From: Matthias Maier Date: Fri, 2 Dec 2022 20:16:32 +0000 (-0600) Subject: CMake: update populate_target_properties X-Git-Tag: v9.5.0-rc1~446^2~22 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba8a4166cbac6be7d1756fc05411183a40b82be4;p=dealii.git CMake: update populate_target_properties --- diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake index b6b9a0b28a..8d1e960271 100644 --- a/cmake/checks/check_01_cxx_features.cmake +++ b/cmake/checks/check_01_cxx_features.cmake @@ -47,8 +47,9 @@ macro(_set_up_cmake_required) reset_cmake_required() set(CMAKE_REQUIRED_FLAGS "") - add_flags(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS_SAVED}") + add_flags(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_WARNING_FLAGS}") add_flags(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS}") + add_flags(CMAKE_REQUIRED_FLAGS "${DEAL_II_CXX_FLAGS_SAVED}") endmacro() diff --git a/cmake/macros/macro_define_object_target.cmake b/cmake/macros/macro_define_object_target.cmake index f0eba3bc01..7290ab3b07 100644 --- a/cmake/macros/macro_define_object_target.cmake +++ b/cmake/macros/macro_define_object_target.cmake @@ -32,7 +32,7 @@ function(define_object_library _library) - if(NOT "${_library}" MATCHES "^object_" AND NOT "${_library}" MATCHES "^bundled_") + if(NOT "${_library}" MATCHES "^(object|bundled)_") message(FATAL_ERROR "Internal error: The specified target name must begin with object_ " "or bundled_. Encountered: ${_library}" diff --git a/cmake/macros/macro_populate_target_properties.cmake b/cmake/macros/macro_populate_target_properties.cmake index 4f52799e44..83b0f6688c 100644 --- a/cmake/macros/macro_populate_target_properties.cmake +++ b/cmake/macros/macro_populate_target_properties.cmake @@ -37,11 +37,23 @@ function(populate_target_properties _target _build) + if(NOT "${_target}" MATCHES "^(object|bundled|${DEAL_II_NAMESPACE})_") + message(FATAL_ERROR + "Internal error: The specified target name must begin with object_, " + "bundled_, or ${DEAL_II_NAMESPACE}. Encountered: ${_target}" + ) + endif() + + set(_visibility PRIVATE) + if("${_target}" MATCHES "^${DEAL_II_NAMESPACE}") + set(_visibility PUBLIC) + endif() + set_target_properties(${_target} PROPERTIES LINKER_LANGUAGE "CXX") - target_link_libraries(${_target} - PUBLIC ${DEAL_II_LIBRARIES} ${DEAL_II_LIBRARIES_${_build}} - ${DEAL_II_TARGETS} ${DEAL_II_TARGETS_${_build}} + target_link_libraries(${_target} ${_visibility} + ${DEAL_II_LIBRARIES} ${DEAL_II_LIBRARIES_${_build}} + ${DEAL_II_TARGETS} ${DEAL_II_TARGETS_${_build}} ) # @@ -49,9 +61,9 @@ function(populate_target_properties _target _build) # and add the contents of ${DEAL_II_INCLUDE_DIRS} as a public interface. # target_include_directories(${_target} BEFORE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - target_include_directories(${_target} SYSTEM PUBLIC ${DEAL_II_INCLUDE_DIRS}) + target_include_directories(${_target} SYSTEM ${_visibility} ${DEAL_II_INCLUDE_DIRS}) - # Build directory specific includes: + # Build-directory specific includes: target_include_directories(${_target} PRIVATE ${CMAKE_BINARY_DIR}/include @@ -61,34 +73,39 @@ function(populate_target_properties _target _build) # Interface includes: - set(_includes - $ - $ - "$" - ) - foreach(_include ${DEAL_II_BUNDLED_INCLUDE_DIRS}) - list(APPEND _includes $) - endforeach() - if(NOT "${DEAL_II_BUNDLED_INCLUDE_DIRS}" STREQUAL "") - list(APPEND _includes "$") + if("${_visibility}" STREQUAL "PUBLIC") + set(_includes + $ + $ + "$" + ) + foreach(_include ${DEAL_II_BUNDLED_INCLUDE_DIRS}) + list(APPEND _includes $) + endforeach() + if(NOT "${DEAL_II_BUNDLED_INCLUDE_DIRS}" STREQUAL "") + list(APPEND _includes "$") + endif() + target_include_directories(${_target} INTERFACE ${_includes}) endif() - target_include_directories(${_target} INTERFACE ${_includes}) - - target_compile_definitions(${_target} - PUBLIC ${DEAL_II_DEFINITIONS} ${DEAL_II_DEFINITIONS_${_build}} + target_compile_definitions(${_target} ${_visibility} + ${DEAL_II_DEFINITIONS} ${DEAL_II_DEFINITIONS_${_build}} ) + # + # Add copmile and link options with private scope + # + separate_arguments(_compile_options UNIX_COMMAND "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" ) - target_compile_options(${_target} - PUBLIC $<$:${_compile_options}> + target_compile_options(${_target} PRIVATE + $<$:${_compile_options}> ) separate_arguments(_link_options UNIX_COMMAND "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}" ) - target_link_options(${_target} INTERFACE ${_link_options}) + target_link_options(${_target} PRIVATE ${_link_options}) endfunction()