From: Matthias Maier Date: Thu, 24 Nov 2022 13:42:42 +0000 (-0600) Subject: CMake: Introduce a dealii:: namespace for targets and harmonize naming X-Git-Tag: v9.5.0-rc1~806^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94a028cac4fcad39baf2341c163e2206af8edda6;p=dealii.git CMake: Introduce a dealii:: namespace for targets and harmonize naming The top-level targets are now named dealii_debug and dealii_release (and their exported counterparts dealii::dealii_debug and dealii::dealii_release). --- diff --git a/cmake/config/CMakeLists.txt b/cmake/config/CMakeLists.txt index db465e340b..c7be0c2ee1 100644 --- a/cmake/config/CMakeLists.txt +++ b/cmake/config/CMakeLists.txt @@ -84,6 +84,7 @@ strip_flag(DEAL_II_CXX_FLAGS "-Wsuggest-override") # foreach(_build ${DEAL_II_BUILD_TYPES}) + string(TOLOWER ${_build} _build_lowercase) if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DebugRelease") set(_keyword "general") @@ -113,7 +114,7 @@ foreach(_build ${DEAL_II_BUILD_TYPES}) ) list(APPEND CONFIG_LIBRARIES ${_keyword} \${DEAL_II_LIBRARIES_${_build}}) - set(CONFIG_TARGET_${_build} ${DEAL_II_BASE_NAME}${DEAL_II_${_build}_SUFFIX}) + set(CONFIG_TARGET_${_build} ${DEAL_II_NAMESPACE}::${DEAL_II_NAMESPACE}_${_build_lowercase}) list(APPEND CONFIG_TARGET ${_keyword} \${DEAL_II_TARGET_${_build}}) endforeach() diff --git a/cmake/macros/macro_deal_ii_insource_setup_target.cmake b/cmake/macros/macro_deal_ii_insource_setup_target.cmake index 4009669a45..9febffccda 100644 --- a/cmake/macros/macro_deal_ii_insource_setup_target.cmake +++ b/cmake/macros/macro_deal_ii_insource_setup_target.cmake @@ -25,6 +25,7 @@ # macro(DEAL_II_INSOURCE_SETUP_TARGET _target _build) + string(TOLOWER ${_build} _build_lowercase) set_target_properties(${_target} PROPERTIES LINK_FLAGS "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}" @@ -64,9 +65,7 @@ macro(DEAL_II_INSOURCE_SETUP_TARGET _target _build) get_property(_type TARGET ${_target} PROPERTY TYPE) if(NOT "${_type}" STREQUAL "OBJECT_LIBRARY") - target_link_libraries(${_target} - ${DEAL_II_BASE_NAME}${DEAL_II_${_build}_SUFFIX} - ) + target_link_libraries(${_target} ${DEAL_II_NAMESPACE}_${_build_lowercase}) endif() endmacro() diff --git a/cmake/setup_deal_ii.cmake b/cmake/setup_deal_ii.cmake index 670efd87f7..58d32fb756 100644 --- a/cmake/setup_deal_ii.cmake +++ b/cmake/setup_deal_ii.cmake @@ -36,6 +36,8 @@ # DEAL_II_VERSION # # Information about paths, install locations and names: + +# DEAL_II_NAMESPACE *) # # DEAL_II_PROJECT_CONFIG_NAME *) # DEAL_II_BASE_NAME *) @@ -100,7 +102,11 @@ set(DEAL_II_VERSION ${DEAL_II_VERSION_MAJOR}.${DEAL_II_VERSION_MINOR}.${DEAL_II_ # # ######################################################################## -set(DEAL_II_PROJECT_CONFIG_NAME "${DEAL_II_PACKAGE_NAME}") +string(REPLACE "." "" _namespace "${DEAL_II_PACKAGE_NAME}") +string(TOLOWER "${_namespace}" _namespace) +set_if_empty(DEAL_II_NAMESPACE "${_namespace}") + +set_if_empty(DEAL_II_PROJECT_CONFIG_NAME "${DEAL_II_PACKAGE_NAME}") string(REPLACE "." "_" _base_name "${DEAL_II_PACKAGE_NAME}") set_if_empty(DEAL_II_BASE_NAME "${_base_name}") diff --git a/contrib/python-bindings/source/CMakeLists.txt b/contrib/python-bindings/source/CMakeLists.txt index 43f6a75356..1f04fdbaff 100644 --- a/contrib/python-bindings/source/CMakeLists.txt +++ b/contrib/python-bindings/source/CMakeLists.txt @@ -71,7 +71,7 @@ foreach(_build ${DEAL_II_BUILD_TYPES}) endif() target_link_libraries(PyDealII_${_build_lowercase} - ${DEAL_II_BASE_NAME}${DEAL_II_${_build}_SUFFIX} + ${DEAL_II_NAMESPACE}_${_build_lowercase} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ) diff --git a/doc/developers/cmake-internals.html b/doc/developers/cmake-internals.html index 07825d90b6..e7b65e9f47 100644 --- a/doc/developers/cmake-internals.html +++ b/doc/developers/cmake-internals.html @@ -96,7 +96,7 @@ LIST(APPEND CONFIG_LIBRARIES ${CONFIG_LIBRARIES_${_build}} ) -SET_TARGET_PROPERTIES(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} +SET_TARGET_PROPERTIES(${DEAL_II_NAMESPACE}_${build_lowercase} PROPERTIES VERSION ${VERSION} SOVERSION ${VERSION} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 5302be899e..83a53336b6 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -84,13 +84,13 @@ foreach(build ${DEAL_II_BUILD_TYPES}) get_property(_objects GLOBAL PROPERTY DEAL_II_OBJECTS_${build}) - add_library(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + add_library(${DEAL_II_NAMESPACE}_${build_lowercase} dummy.cc # Workaround for a bug in the Xcode generator ${_objects} ) - add_dependencies(library ${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX}) + add_dependencies(library ${DEAL_II_NAMESPACE}_${build_lowercase}) - set_target_properties(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + set_target_properties(${DEAL_II_NAMESPACE}_${build_lowercase} PROPERTIES VERSION "${DEAL_II_PACKAGE_VERSION}" # @@ -103,13 +103,16 @@ foreach(build ${DEAL_II_BUILD_TYPES}) LINKER_LANGUAGE "CXX" COMPILE_DEFINITIONS "${DEAL_II_DEFINITIONS};${DEAL_II_DEFINITIONS_${build}}" COMPILE_FLAGS "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${build}}" + ARCHIVE_OUTPUT_NAME "${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX}" + LIBRARY_OUTPUT_NAME "${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX}" + RUNTIME_OUTPUT_NAME "${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DEAL_II_LIBRARY_RELDIR}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DEAL_II_LIBRARY_RELDIR}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DEAL_II_EXECUTABLE_RELDIR}" ) if(CMAKE_SYSTEM_NAME MATCHES "Darwin") - set_target_properties(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + set_target_properties(${DEAL_II_NAMESPACE}_${build_lowercase} PROPERTIES MACOSX_RPATH OFF BUILD_WITH_INSTALL_RPATH OFF @@ -126,7 +129,7 @@ foreach(build ${DEAL_II_BUILD_TYPES}) # lib locations for _DEBUG (no support for dynamic linking, _RELEASE will be # ignored), but we do it anyhow. if (DEAL_II_MSVC) - set_target_properties(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + set_target_properties(${DEAL_II_NAMESPACE}_${build_lowercase} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${DEAL_II_LIBRARY_RELDIR}" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/${DEAL_II_LIBRARY_RELDIR}" @@ -138,7 +141,7 @@ foreach(build ${DEAL_II_BUILD_TYPES}) endif() - target_link_libraries(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + target_link_libraries(${DEAL_II_NAMESPACE}_${build_lowercase} ${DEAL_II_LIBRARIES_${build}} ${DEAL_II_LIBRARIES} ) @@ -146,12 +149,13 @@ foreach(build ${DEAL_II_BUILD_TYPES}) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR} ) - export(TARGETS ${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + export(TARGETS ${DEAL_II_NAMESPACE}_${build_lowercase} + NAMESPACE "${DEAL_II_NAMESPACE}::" FILE ${CMAKE_BINARY_DIR}/${DEAL_II_PROJECT_CONFIG_RELDIR}/${DEAL_II_PROJECT_CONFIG_NAME}Targets.cmake APPEND ) - install(TARGETS ${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX} + install(TARGETS ${DEAL_II_NAMESPACE}_${build_lowercase} COMPONENT library EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets RUNTIME DESTINATION ${DEAL_II_EXECUTABLE_RELDIR} @@ -161,6 +165,7 @@ foreach(build ${DEAL_II_BUILD_TYPES}) endforeach() install(EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets + NAMESPACE "${DEAL_II_NAMESPACE}::" DESTINATION ${DEAL_II_PROJECT_CONFIG_RELDIR} COMPONENT library )