From: Matthias Maier Date: Mon, 3 Jul 2023 15:23:32 +0000 (-0500) Subject: CMake: simplify Target.config generation X-Git-Tag: relicensing~773^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bb794c7a0f979cf1f211a260504924ca056e7b2;p=dealii.git CMake: simplify Target.config generation Let us call the export(TARGETS ...) function at one central place. This simplifies the configuration logic significantly and avoids accidentally recreating the file. --- diff --git a/cmake/macros/macro_define_interface_target.cmake b/cmake/macros/macro_define_interface_target.cmake index c9f74ad566..54d1b29585 100644 --- a/cmake/macros/macro_define_interface_target.cmake +++ b/cmake/macros/macro_define_interface_target.cmake @@ -146,17 +146,6 @@ function(define_interface_target _feature) copy_target_properties(${_interface_target} ${${_feature}_TARGETS} ${${_feature}_TARGETS_${_build}}) endif() - export(TARGETS ${_interface_target} - NAMESPACE "${DEAL_II_TARGET_NAME}::" - FILE ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake - APPEND - ) - - install(TARGETS ${_interface_target} - COMPONENT library - EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets - ) - if(${_feature}_SPLIT_CONFIGURATION) # Future FIXME: change to block(PARENT_SCOPE)/endblock() (CMake 3.25) list(APPEND DEAL_II_TARGETS_${_build} ${_interface_target}) diff --git a/cmake/setup_finalize.cmake b/cmake/setup_finalize.cmake index 4fbfd19c0c..f39c09c420 100644 --- a/cmake/setup_finalize.cmake +++ b/cmake/setup_finalize.cmake @@ -50,16 +50,6 @@ foreach(_flag ${DEAL_II_REMOVED_FLAGS}) endif() endforeach() - -# -# Clean up deal.IITargets.cmake in the build directory: -# - -file(REMOVE - ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake - ) - - ######################################################################## # # # Query for git repository information: # diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index eda829e970..f99c27fb0f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -191,40 +191,34 @@ foreach(build ${DEAL_II_BUILD_TYPES}) ) endif() - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}) - export(TARGETS ${DEAL_II_TARGET_NAME}_${build_lowercase} - NAMESPACE "${DEAL_II_TARGET_NAME}::" - FILE ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake - APPEND - ) - - install(TARGETS ${DEAL_II_TARGET_NAME}_${build_lowercase} - COMPONENT library - EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets - RUNTIME DESTINATION ${DEAL_II_EXECUTABLE_RELDIR} - LIBRARY DESTINATION ${DEAL_II_LIBRARY_RELDIR} - ARCHIVE DESTINATION ${DEAL_II_LIBRARY_RELDIR} - ) - target_link_libraries(${DEAL_II_TARGET_NAME} INTERFACE "$<$:${DEAL_II_TARGET_NAME}::${DEAL_II_TARGET_NAME}_${build_lowercase}>" ) endforeach() +# +# And install all targets: +# + +set(_targets ${DEAL_II_TARGET_NAME}) +foreach(build ${DEAL_II_BUILD_TYPES}) + string(TOLOWER ${build} build_lowercase) + list(APPEND _targets ${DEAL_II_TARGET_NAME}_${build_lowercase}) +endforeach() + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}) -export(TARGETS ${DEAL_II_TARGET_NAME} +export(TARGETS ${_targets} ${DEAL_II_TARGETS} ${DEAL_II_TARGETS_DEBUG} ${DEAL_II_TARGETS_RELEASE} NAMESPACE "${DEAL_II_TARGET_NAME}::" FILE ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake - APPEND ) -install(TARGETS ${DEAL_II_TARGET_NAME} +install(TARGETS ${_targets} ${DEAL_II_TARGETS} ${DEAL_II_TARGETS_DEBUG} ${DEAL_II_TARGETS_RELEASE} COMPONENT library EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets RUNTIME DESTINATION ${DEAL_II_EXECUTABLE_RELDIR} LIBRARY DESTINATION ${DEAL_II_LIBRARY_RELDIR} ARCHIVE DESTINATION ${DEAL_II_LIBRARY_RELDIR} -) + ) install(EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets NAMESPACE "${DEAL_II_TARGET_NAME}::"