diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a70f6f8e..6d3c2240d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,24 @@ option(SIBLING_SEARCH "Search for other modules in sibling directories?" ON) set( USE_OPENMP_DEFAULT OFF ) # Use of OpenMP is considered experimental 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) + if(_parent_dir_name STREQUAL CMAKE_PROJECT_NAME) + #looks like / 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}) + endif() + elseif(_leaf_dir_name STREQUAL CMAKE_PROJECT_NAME) + # we assume / + if(IS_DIRECTORY ${_parent_full_dir}/opm-common) + set(opm-common_DIR "${_parent_full_dir}/opm-common}") + endif() + endif() + endif() find_package(opm-common QUIET) endif()