]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: update populate_target_properties
authorMatthias Maier <tamiko@43-1.org>
Fri, 2 Dec 2022 20:16:32 +0000 (14:16 -0600)
committerMatthias Maier <tamiko@43-1.org>
Fri, 17 Mar 2023 12:44:53 +0000 (07:44 -0500)
cmake/checks/check_01_cxx_features.cmake
cmake/macros/macro_define_object_target.cmake
cmake/macros/macro_populate_target_properties.cmake

index b6b9a0b28a0300f17f03d803dac250b2c6635b55..8d1e960271f0563775f488f4f9717a9b7812c7f5 100644 (file)
@@ -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()
 
 
index f0eba3bc012c44afb60fea60195a8d8a6e9b2f17..7290ab3b0744dc585bc51b8d8bbe3c3611b4a650 100644 (file)
@@ -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}"
index 4f52799e440c5f90e4850731f846f73292e3b9ad..83b0f6688c819ec644df0829ef93d3171ef58020 100644 (file)
 
 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
-    $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
-    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
-    "$<INSTALL_INTERFACE:\${DEAL_II_INCLUDE_RELDIR}>"
-    )
-  foreach(_include ${DEAL_II_BUNDLED_INCLUDE_DIRS})
-    list(APPEND _includes $<BUILD_INTERFACE:${_include}>)
-  endforeach()
-  if(NOT "${DEAL_II_BUNDLED_INCLUDE_DIRS}" STREQUAL "")
-    list(APPEND _includes "$<INSTALL_INTERFACE:\${DEAL_II_INCLUDE_RELDIR}/deal.II/bundled>")
+  if("${_visibility}" STREQUAL "PUBLIC")
+    set(_includes
+      $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
+      $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
+      "$<INSTALL_INTERFACE:\${DEAL_II_INCLUDE_RELDIR}>"
+      )
+    foreach(_include ${DEAL_II_BUNDLED_INCLUDE_DIRS})
+      list(APPEND _includes $<BUILD_INTERFACE:${_include}>)
+    endforeach()
+    if(NOT "${DEAL_II_BUNDLED_INCLUDE_DIRS}" STREQUAL "")
+      list(APPEND _includes "$<INSTALL_INTERFACE:\${DEAL_II_INCLUDE_RELDIR}/deal.II/bundled>")
+    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_LANGUAGE:CXX>:${_compile_options}>
+  target_compile_options(${_target} PRIVATE
+    $<$<COMPILE_LANGUAGE:CXX>:${_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()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.