diff --git a/CMakeLists.txt b/CMakeLists.txt index e688d7053..6e036bdfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,83 +19,40 @@ project(opm-simulators CXX) cmake_minimum_required (VERSION 2.8) -set( OPM_COMMON_ROOT "" CACHE PATH "Root directory containing OPM related cmake modules") option(SIBLING_SEARCH "Search for other modules in sibling directories?" ON) set( USE_OPENMP_DEFAULT OFF ) # Use of OpenMP is considered experimental -if(OPM_COMMON_ROOT AND opm-common_DIR) - message(WARNING "Both the variables OPM_COMMON_ROOT and opm-common_DIR are set. " - "Will use opm-common_DIR") - set(OPM_COMMON_ROOT "OPM_COMMON_ROOT-NOTFOUND") -endif() - -if(NOT OPM_COMMON_ROOT) - if(SIBLING_SEARCH AND NOT opm-common_DIR) - # guess the sibling dir - get_filename_component(_leaf_dir_name ${PROJECT_BINARY_DIR} NAME) - get_filename_component(_parent_full_dir ${PROJECT_BINARY_DIR} DIRECTORY) - get_filename_component(_parent_dir_name ${_parent_full_dir} NAME) - #Try if / is used - get_filename_component(_modules_dir ${_parent_full_dir} DIRECTORY) - if(IS_DIRECTORY ${_modules_dir}/opm-common/${_leaf_dir_name}) - set(opm-common_DIR ${_modules_dir}/opm-common/${_leaf_dir_name}) - else() - string(REPLACE ${PROJECT_NAME} opm-common _opm_common_leaf ${_leaf_dir_name}) - message("_opm_common_leaf=${_opm_common_leaf}") - if(NOT _leaf_dir_name STREQUAL _opm_common_leaf - AND IS_DIRECTORY ${_parent_full_dir}/${_opm_common_leaf}) - # We are using build directories named - set(opm-common_DIR ${_parent_full_dir}/${_opm_common_leaf}) - elseif(IS_DIRECTORY ${_parent_full_dir}/opm-common) - # All modules are in a common build dir - set(opm-common_DIR "${_parent_full_dir}/opm-common}") - endif() - endif() +if(SIBLING_SEARCH AND NOT opm-common_DIR) + # guess the sibling dir + get_filename_component(_leaf_dir_name ${PROJECT_BINARY_DIR} NAME) + get_filename_component(_parent_full_dir ${PROJECT_BINARY_DIR} DIRECTORY) + get_filename_component(_parent_dir_name ${_parent_full_dir} NAME) + #Try if / is used + get_filename_component(_modules_dir ${_parent_full_dir} DIRECTORY) + if(IS_DIRECTORY ${_modules_dir}/opm-common/${_leaf_dir_name}) + set(opm-common_DIR ${_modules_dir}/opm-common/${_leaf_dir_name}) else() - if(NOT IS_DIRECTORY ${opm-common_DIR}) - message(WARNING "Value ${opm-common_DIR} passed to variable" - " opm-common_DIR is not a directory") + string(REPLACE ${PROJECT_NAME} opm-common _opm_common_leaf ${_leaf_dir_name}) + if(NOT _leaf_dir_name STREQUAL _opm_common_leaf + AND IS_DIRECTORY ${_parent_full_dir}/${_opm_common_leaf}) + # We are using build directories named + set(opm-common_DIR ${_parent_full_dir}/${_opm_common_leaf}) + elseif(IS_DIRECTORY ${_parent_full_dir}/opm-common) + # All modules are in a common build dir + set(opm-common_DIR "${_parent_full_dir}/opm-common}") endif() - endif() - find_package(opm-common REQUIRED) -endif() - -if (opm-common_FOUND) - include(OpmInit) + endif() else() - if(OPM_COMMON_ROOT) - message(WARNING "Setting OPM_COMMON_ROOT is deprecated. Please either " - "set opm-common_DIR instead or rely on sibling build") - endif() - - unset(opm-common_FOUND) - - if (NOT OPM_COMMON_ROOT AND SIBLING_SEARCH) - set(OPM_COMMON_ROOT ${PROJECT_SOURCE_DIR}/../opm-common) - endif() - if (OPM_COMMON_ROOT) - list( APPEND CMAKE_MODULE_PATH "${OPM_COMMON_ROOT}/cmake/Modules") - include (OpmInit OPTIONAL RESULT_VARIABLE OPM_INIT) - set( OPM_MACROS_ROOT ${OPM_COMMON_ROOT} ) - endif() - - if (NOT OPM_INIT) - message( "" ) - message( " /---------------------------------------------------------------------------------\\") - message( " | Could not locate the opm build macros. The opm build macros |") - message( " | are in a separate repository - instructions to proceed: |") - message( " | |") - message( " | 1. Clone the repository: git clone git@github.com:OPM/opm-common.git |") - message( " | |") - message( " | 2. Run cmake in the current project with -DOPM_COMMON_ROOT=/opm-common |") - message( " | |") - message( " \\---------------------------------------------------------------------------------/") - message( "" ) - message( FATAL_ERROR "Could not find OPM Macros") - endif() - + if(NOT IS_DIRECTORY ${opm-common_DIR}) + message(WARNING "Value ${opm-common_DIR} passed to variable" + " opm-common_DIR is not a directory") + endif() endif() +find_package(opm-common REQUIRED) + +include(OpmInit) + # not the same location as most of the other projects? this hook overrides macro (dir_hook)