From 6715ed6d48ad8b388d634ec6d33e1cc4eb5a28c3 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Fri, 13 Oct 2017 21:35:24 +0200 Subject: [PATCH] Allow multiple find_package calls in config mode --- cmake/Templates/opm-project-config.cmake.in | 86 +++++++++++---------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/cmake/Templates/opm-project-config.cmake.in b/cmake/Templates/opm-project-config.cmake.in index 3ef2c2bf3..e26c4c900 100644 --- a/cmake/Templates/opm-project-config.cmake.in +++ b/cmake/Templates/opm-project-config.cmake.in @@ -19,51 +19,55 @@ # -# propagate these properties from one build system to the other -set (@opm-project_NAME@_VERSION "@opm-project_VERSION@") -set (@opm-project_NAME@_DEFINITIONS "@opm-project_DEFINITIONS@") -set (@opm-project_NAME@_INCLUDE_DIRS "@opm-project_INCLUDE_DIRS@") -set (@opm-project_NAME@_LIBRARY_DIRS "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") -set (@opm-project_NAME@_LINKER_FLAGS "@opm-project_LINKER_FLAGS@") -set (@opm-project_NAME@_CONFIG_VARS "@opm-project_CONFIG_VARS@") +# Prevent multiple inclusions +if(NOT @opm-project_NAME@_FOUND) -# libraries come from the build tree where this file was generated -set (@opm-project_NAME@_LIBRARY "@opm-project_LIBRARY@") -set (@opm-project_NAME@_LIBRARIES ${@opm-project_NAME@_LIBRARY} "@opm-project_LIBRARIES@") -mark_as_advanced (@opm-project_NAME@_LIBRARY) + # propagate these properties from one build system to the other + set (@opm-project_NAME@_VERSION "@opm-project_VERSION@") + set (@opm-project_NAME@_DEFINITIONS "@opm-project_DEFINITIONS@") + set (@opm-project_NAME@_INCLUDE_DIRS "@opm-project_INCLUDE_DIRS@") + set (@opm-project_NAME@_LIBRARY_DIRS "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@") + set (@opm-project_NAME@_LINKER_FLAGS "@opm-project_LINKER_FLAGS@") + set (@opm-project_NAME@_CONFIG_VARS "@opm-project_CONFIG_VARS@") -# not all projects have targets; conditionally add this part -if (NOT "@opm-project_TARGET@" STREQUAL "") - # add the library as a target, so that other things in the project including - # this file may depend on it and get rebuild if this library changes. - add_library (@opm-project_TARGET@ UNKNOWN IMPORTED) - set_property (TARGET @opm-project_TARGET@ PROPERTY IMPORTED_LOCATION "${@opm-project_NAME@_LIBRARY}") -endif (NOT "@opm-project_TARGET@" STREQUAL "") + # libraries come from the build tree where this file was generated + set (@opm-project_NAME@_LIBRARY "@opm-project_LIBRARY@") + set (@opm-project_NAME@_LIBRARIES ${@opm-project_NAME@_LIBRARY} "@opm-project_LIBRARIES@") + mark_as_advanced (@opm-project_NAME@_LIBRARY) -# ensure that we build with support for C++11 to preserve ABI -string (REPLACE "@CXX_STD0X_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string (REPLACE "@CXX_STDLIB_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string (STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS) -set (CMAKE_CXX_FLAGS "@CXX_STD0X_FLAGS@@CXX_SPACE@@CXX_STDLIB_FLAGS@ ${CMAKE_CXX_FLAGS}") + # not all projects have targets; conditionally add this part + if (NOT "@opm-project_TARGET@" STREQUAL "") + # add the library as a target, so that other things in the project including + # this file may depend on it and get rebuild if this library changes. + add_library (@opm-project_TARGET@ UNKNOWN IMPORTED) + set_property (TARGET @opm-project_TARGET@ PROPERTY IMPORTED_LOCATION "${@opm-project_NAME@_LIBRARY}") + endif (NOT "@opm-project_TARGET@" STREQUAL "") -# same as above, but for C99 -string (REPLACE "@C_STD99_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS) -set (CMAKE_C_FLAG "@C_STD99_FLAGS@ ${CMAKE_C_FLAGS}") - -# build with OpenMP if that was found -if (NOT "@OpenMP_C_FLAGS@" STREQUAL "") - string (REPLACE "@OpenMP_C_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS) - set (CMAKE_C_FLAG "@OpenMP_C_FLAGS@ ${CMAKE_C_FLAGS}") -endif (NOT "@OpenMP_C_FLAGS@" STREQUAL "") -if (NOT "@OpenMP_CXX_FLAGS@" STREQUAL "") - string (REPLACE "@OpenMP_CXX_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + # ensure that we build with support for C++11 to preserve ABI + string (REPLACE "@CXX_STD0X_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string (REPLACE "@CXX_STDLIB_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string (STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS) - set (CMAKE_C_FLAG "@OpenMP_CXX_FLAGS@ ${CMAKE_CXX_FLAGS}") -endif (NOT "@OpenMP_CXX_FLAGS@" STREQUAL "") + set (CMAKE_CXX_FLAGS "@CXX_STD0X_FLAGS@@CXX_SPACE@@CXX_STDLIB_FLAGS@ ${CMAKE_CXX_FLAGS}") -# this is the contents of config.h as far as our probes can tell: + # same as above, but for C99 + string (REPLACE "@C_STD99_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS) + set (CMAKE_C_FLAG "@C_STD99_FLAGS@ ${CMAKE_C_FLAGS}") -# extra code -@OPM_PROJECT_EXTRA_CODE@ + # build with OpenMP if that was found + if (NOT "@OpenMP_C_FLAGS@" STREQUAL "") + string (REPLACE "@OpenMP_C_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS) + set (CMAKE_C_FLAG "@OpenMP_C_FLAGS@ ${CMAKE_C_FLAGS}") + endif (NOT "@OpenMP_C_FLAGS@" STREQUAL "") + if (NOT "@OpenMP_CXX_FLAGS@" STREQUAL "") + string (REPLACE "@OpenMP_CXX_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string (STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS) + set (CMAKE_C_FLAG "@OpenMP_CXX_FLAGS@ ${CMAKE_CXX_FLAGS}") + endif (NOT "@OpenMP_CXX_FLAGS@" STREQUAL "") + + # this is the contents of config.h as far as our probes can tell: + + # extra code + @OPM_PROJECT_EXTRA_CODE@ +endif()