Skip to content

Commit

Permalink
Have Kokkos TriBITS build set compiler options as target properties (t…
Browse files Browse the repository at this point in the history
…rilinos#11545)

With the TriBITS modernization refactoring (TriBITSPub/TriBITS#299) and the
generalizated handling of intenral and external packages
(TriBITSPub/TriBITS#63), we need packages like Kokkos to set critical compiler
options as target properties so that they will be exported in the generated
IMPORTED targets of the Kokkos<Subpkg>Targets.cmake file.

This is needed, for example, to pass some critical compiler flags from the
pre-installed Kokkos to downstream CMake configures of KokkosKernels and the
rest of Trilinos (see trilinos#11545).
  • Loading branch information
bartlettroscoe authored and jwillenbring committed Jun 12, 2023
1 parent eeef5fa commit 3af0c34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 2 additions & 0 deletions packages/kokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ IF(NOT KOKKOS_HAS_TRILINOS)
FORCE)
ENDIF()
ENDIF()
ELSE()
SET(KOKKOS_COMPILE_LANGUAGE CXX)
ENDIF()

IF (NOT CMAKE_SIZEOF_VOID_P)
Expand Down
50 changes: 24 additions & 26 deletions packages/kokkos/cmake/kokkos_tribits.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ MACRO(KOKKOS_INSTALL_ADDITIONAL_FILES)
DESTINATION ${KOKKOS_HEADER_DIR})
ENDMACRO()


FUNCTION(KOKKOS_SET_LIBRARY_PROPERTIES LIBRARY_NAME)
CMAKE_PARSE_ARGUMENTS(PARSE
"PLAIN_STYLE"
Expand Down Expand Up @@ -441,6 +442,7 @@ FUNCTION(KOKKOS_SET_LIBRARY_PROPERTIES LIBRARY_NAME)
ENDIF()
ENDFUNCTION()


FUNCTION(KOKKOS_INTERNAL_ADD_LIBRARY LIBRARY_NAME)
CMAKE_PARSE_ARGUMENTS(PARSE
"STATIC;SHARED"
Expand Down Expand Up @@ -503,19 +505,11 @@ FUNCTION(KOKKOS_ADD_LIBRARY LIBRARY_NAME)
# preserving the directory structure, e.g. impl
# If headers got installed in both locations, it breaks some
# downstream packages
TRIBITS_ADD_LIBRARY(${LIBRARY_NAME} ${PARSE_UNPARSED_ARGUMENTS})
#Stolen from Tribits - it can add prefixes
SET(TRIBITS_LIBRARY_NAME_PREFIX "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}")
SET(TRIBITS_LIBRARY_NAME ${TRIBITS_LIBRARY_NAME_PREFIX}${LIBRARY_NAME})
#Tribits has way too much techinical debt and baggage to even
#allow PUBLIC target_compile_options to be used. It forces C++ flags on projects
#as a giant blob of space-separated strings. We end up with duplicated
#flags between the flags implicitly forced on Kokkos-dependent and those Kokkos
#has in its public INTERFACE_COMPILE_OPTIONS.
#These do NOT get de-deduplicated because Tribits
#creates flags as a giant monolithic space-separated string
#Do not set any transitive properties and keep everything working as before
#KOKKOS_SET_LIBRARY_PROPERTIES(${TRIBITS_LIBRARY_NAME} PLAIN_STYLE)
TRIBITS_ADD_LIBRARY(${LIBRARY_NAME} ${PARSE_UNPARSED_ARGUMENTS}
ADDED_LIB_TARGET_NAME_OUT ${LIBRARY_NAME}_TARGET_NAME )
IF (PARSE_ADD_BUILD_OPTIONS)
KOKKOS_SET_LIBRARY_PROPERTIES(${${LIBRARY_NAME}_TARGET_NAME})
ENDIF()
ELSE()
# Forward the headers, we want to know about all headers
# to make sure they appear correctly in IDEs
Expand All @@ -527,15 +521,24 @@ FUNCTION(KOKKOS_ADD_LIBRARY LIBRARY_NAME)
ENDIF()
ENDFUNCTION()


FUNCTION(KOKKOS_ADD_INTERFACE_LIBRARY NAME)
IF (KOKKOS_HAS_TRILINOS)
TRIBITS_ADD_LIBRARY(${NAME} ${ARGN})
ELSE()
ADD_LIBRARY(${NAME} INTERFACE)
KOKKOS_INTERNAL_ADD_LIBRARY_INSTALL(${NAME})
ENDIF()
IF (KOKKOS_HAS_TRILINOS)
TRIBITS_ADD_LIBRARY(${NAME} ${ARGN})
ELSE()
CMAKE_PARSE_ARGUMENTS(PARSE
""
""
"HEADERS;SOURCES"
${ARGN}
)

ADD_LIBRARY(${NAME} INTERFACE)
KOKKOS_INTERNAL_ADD_LIBRARY_INSTALL(${NAME})
ENDIF()
ENDFUNCTION()


FUNCTION(KOKKOS_LIB_INCLUDE_DIRECTORIES TARGET)
IF(KOKKOS_HAS_TRILINOS)
#ignore the target, tribits doesn't do anything directly with targets
Expand All @@ -549,13 +552,8 @@ FUNCTION(KOKKOS_LIB_INCLUDE_DIRECTORIES TARGET)
ENDFUNCTION()

FUNCTION(KOKKOS_LIB_COMPILE_OPTIONS TARGET)
IF(KOKKOS_HAS_TRILINOS)
#don't trust tribits to do this correctly
KOKKOS_TARGET_COMPILE_OPTIONS(${TARGET} ${ARGN})
ELSE()
KOKKOS_LIB_TYPE(${TARGET} INCTYPE)
KOKKOS_TARGET_COMPILE_OPTIONS(${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${TARGET} ${INCTYPE} ${ARGN})
ENDIF()
KOKKOS_LIB_TYPE(${TARGET} INCTYPE)
KOKKOS_TARGET_COMPILE_OPTIONS(${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${TARGET} ${INCTYPE} ${ARGN})
ENDFUNCTION()

MACRO(KOKKOS_ADD_TEST_DIRECTORIES)
Expand Down

0 comments on commit 3af0c34

Please sign in to comment.