From b8838d28b356ba4dd72de733be4fe0a611aafb28 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Fri, 15 Sep 2017 11:21:59 +0200 Subject: [PATCH] Added sibling search mechanism using ${PROJECT_BINARY_DIR} for opm-common If sibling search is activated and opm-common_DIR is not set, then we try to determine the build directory layout from ${PROJECT_BINARY_DIR}. The following two possibilities are supported: + / + / where is the case sensitive module name (in this case opm-common). This results in the following search precedence: 1. User set opm-common_DIR 2. sibling directories search (if the directories exist) 3. Default (system) CMake search path --- CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00c1e7d0..c1d2bebc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,24 @@ set( OPM_COMMON_ROOT "" CACHE PATH "Root directory containing OPM related cmake option(SIBLING_SEARCH "Search for other modules in sibling directories?" ON) 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()