From aeb746cc4499d9364807cb1b40fc366429bad06c Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 26 Aug 2021 06:40:10 -0600 Subject: [PATCH] Change internal TriBITS target_link_libraries() to PUBLIC (#299) This should fix the propagation of Kokkos compiler flags added on Kokkos library targets using the INTERFACE_COMPILE_OPTIONS target property. Because Kokkos uses target_compile_options( ... PUBLIC ... ) and target_link_libraries( ... PUBLIC ... ) and TriBITS was using old-style target_link_libraries() with no PUBLIC/PRIVATE/INTERFACE, it was likely defaulting to PRIVATE so the INTERFACE_COMPILE_OPTIONS target property would not get propagated along. This behavior does not seem to be documented in official CMake documentation but it is documented in the book "Professional CMake 5th Edition" which says: > In particular, if a project defines a chain of library dependencies with a > mix of both old and new forms of the command, the old-style form will > generally be treated as PRIVATE. I have not tested this yet but I strongly suspect this will fix the problem of Trilinos customers linking to imported Trilinos CMake targets and not getting the Kokkos compiler options directly from the targets. --- tribits/core/package_arch/TribitsAddExecutable.cmake | 6 +++--- tribits/core/package_arch/TribitsLibraryMacros.cmake | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tribits/core/package_arch/TribitsAddExecutable.cmake b/tribits/core/package_arch/TribitsAddExecutable.cmake index 5e3ba3e98..1c9294e98 100644 --- a/tribits/core/package_arch/TribitsAddExecutable.cmake +++ b/tribits/core/package_arch/TribitsAddExecutable.cmake @@ -175,7 +175,7 @@ include(CMakeParseArguments) # ``TESTONLYLIBS ...`` # # Specifies extra test-only libraries defined in this CMake project that -# will be linked to the executable using ``target_link_library()``. Note +# will be linked to the executable using ``target_link_libraries()``. Note # that regular libraries (i.e. not ``TESTONLY``) defined in the current SE # package or any upstream SE packages can *NOT* be listed! TriBITS # automatically links non ``TESTONLY`` libraries in this package and @@ -197,7 +197,7 @@ include(CMakeParseArguments) # ``IMPORTEDLIBS ...`` # # Specifies extra external libraries that will be linked to the executable -# using ``target_link_library()``. This can only be used for libraries +# using ``target_link_libraries()``. This can only be used for libraries # that are built external from this CMake project and are not provided # through a proper `TriBITS TPL`_. The latter usage of passing in # external libraries is not recommended. External libraries should be @@ -646,7 +646,7 @@ function(tribits_add_executable EXE_NAME) message("-- ${EXE_NAME}:LINK_LIBS='${LINK_LIBS}'") endif() - target_link_libraries(${EXE_BINARY_NAME} ${LINK_LIBS}) + target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${LINK_LIBS}) assert_defined(${PROJECT_NAME}_LINK_SEARCH_START_STATIC) if (${PROJECT_NAME}_LINK_SEARCH_START_STATIC) diff --git a/tribits/core/package_arch/TribitsLibraryMacros.cmake b/tribits/core/package_arch/TribitsLibraryMacros.cmake index 600bdbbbb..cc97f07b5 100644 --- a/tribits/core/package_arch/TribitsLibraryMacros.cmake +++ b/tribits/core/package_arch/TribitsLibraryMacros.cmake @@ -861,7 +861,7 @@ function(tribits_add_library LIBRARY_NAME_IN) message("-- ${LIBRARY_NAME_IN}:LINK_LIBS='${LINK_LIBS}'") endif() - target_link_libraries(${LIBRARY_NAME} ${LINK_LIBS}) + target_link_libraries(${LIBRARY_NAME} PUBLIC ${LINK_LIBS}) if (${PROJECT_NAME}_CXX_STANDARD_FEATURE) target_compile_features(${LIBRARY_NAME} PUBLIC "${${PROJECT_NAME}_CXX_STANDARD_FEATURE}")