Skip to content

Commit

Permalink
Have Kokkos TriBITS build properly export options to package config f…
Browse files Browse the repository at this point in the history
…iles (trilinos#11545)

Just need to move where tribits_package_decl() is called before Kokkos defines
its options and then call tribits_pkg_export_cache_var() inside of
kokkos_option().

NOTE: We don't export the variables Kokkos_ENABLE_TESTS or
Kokkos_ENABLE_EXAMPLES because those are special varaibles defined by TriBITS
where the project-level variable value may be different than the cache
variable value (which is on purpose) and also we don't want to export these
variables because downstream packages should not need to know this info.

ToDo: Kokkos really should differentiate what options values it exports and
which it does not to provide a better defined API (and downstream customers
don't need to grep the installed Kokkos_config.h file to figure out this
info).
  • Loading branch information
bartlettroscoe authored and jwillenbring committed Jun 12, 2023
1 parent 510cfeb commit 16e73ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/kokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ if( "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}" )
message( FATAL_ERROR "FATAL: In-source builds are not allowed. You should create a separate directory for build files and delete CMakeCache.txt." )
endif()

if (COMMAND TRIBITS_PACKAGE_DECL)
TRIBITS_PACKAGE_DECL(Kokkos)
endif()

# We want to determine if options are given with the wrong case
# In order to detect which arguments are given to compare against
# the list of valid arguments, at the beginning here we need to
# form a list of all the given variables. If it begins with any
# case of KoKkOS, we add it to the list.


GET_CMAKE_PROPERTY(_variableNames VARIABLES)
SET(KOKKOS_GIVEN_VARIABLES)
FOREACH (var ${_variableNames})
Expand Down Expand Up @@ -288,8 +291,9 @@ IF (KOKKOS_HAS_TRILINOS)
$<$<COMPILE_LANGUAGE:CXX>:${KOKKOS_ALL_COMPILE_OPTIONS}>)
ENDIF()

KOKKOS_PACKAGE_DECL()

if (NOT COMMAND TRIBITS_PACKAGE_DECL)
KOKKOS_PACKAGE_DECL()
endif()

#------------------------------------------------------------------------------
#
Expand Down
9 changes: 9 additions & 0 deletions packages/kokkos/cmake/kokkos_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Validate options are given with correct case and define an internal
# upper-case version for use within

set(Kokkos_OPTIONS_NOT_TO_EXPORT
Kokkos_ENABLE_TESTS Kokkos_ENABLE_EXAMPLES)

#
#
# @FUNCTION: kokkos_deprecated_list
Expand Down Expand Up @@ -57,6 +60,12 @@ FUNCTION(kokkos_option CAMEL_SUFFIX DEFAULT TYPE DOCSTRING)
# Make sure this appears in the cache with the appropriate DOCSTRING
SET(${CAMEL_NAME} ${DEFAULT} CACHE ${TYPE} ${DOCSTRING})

IF (KOKKOS_HAS_TRILINOS)
IF (NOT CAMEL_NAME IN_LIST Kokkos_OPTIONS_NOT_TO_EXPORT)
TRIBITS_PKG_EXPORT_CACHE_VAR(${CAMEL_NAME})
ENDIF()
ENDIF()

#I don't love doing it this way because it's N^2 in number options, but c'est la vie
FOREACH(opt ${KOKKOS_GIVEN_VARIABLES})
STRING(TOUPPER ${opt} OPT_UC)
Expand Down

0 comments on commit 16e73ee

Please sign in to comment.