Skip to content

Commit

Permalink
Change to pass info through <Package>Config.cmake files (#63)
Browse files Browse the repository at this point in the history
This changes to pass info through the <Package>Config.cmake files between
installed SimpleCxx and the downstream package.

This also changes to process TPLs at the base project level instead of in a
function() scope so that non-cache var info can propogate forward.  This
technically breaks backward compatibility but this is more simalar to how a
raw CMake project would call find_package() to get external packages.

This changed the function tribits_process_enabled_tpl() to a macro so that
local vars are at base project scope.  Also, the macro
tribits_process_enabled_tpl() was refactored into smaller macros and function
to make it easier to follow and understand.
  • Loading branch information
bartlettroscoe committed Jan 25, 2023
1 parent 0d8cc97 commit 98ad21e
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 128 deletions.
176 changes: 105 additions & 71 deletions tribits/core/package_arch/TribitsProcessEnabledTpl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,69 @@ include(AppendStringVar)
include(TribitsStandardizePaths)


# @FUNCTION: tribits_process_enabled_tpl()
# @MACRO: tribits_process_enabled_tpl()
#
# Process an enabled TPL's FindTPL${TPL_NAME}.cmake module.
#
function(tribits_process_enabled_tpl TPL_NAME)
macro(tribits_process_enabled_tpl TPL_NAME)

# Setup the processing string
set(PROCESSING_MSG_STRING "Processing enabled external package/TPL: ${TPL_NAME} (")
if (${TPL_NAME}_ENABLING_PKG)
string(APPEND PROCESSING_MSG_STRING
"enabled by ${${TPL_NAME}_ENABLING_PKG}," )
else()
string(APPEND PROCESSING_MSG_STRING
"enabled explicitly," )
endif()
string(APPEND PROCESSING_MSG_STRING
" disable with -DTPL_ENABLE_${TPL_NAME}=OFF)" )

# Print the processing header
message("${PROCESSING_MSG_STRING}")
tribits_get_enabled_tpl_processing_string(${TPL_NAME} tplProcessingString)
message("${tplProcessingString}")

if (NOT ${PROJECT_NAME}_TRACE_DEPENDENCY_HANDLING_ONLY)

# Locate the FindTPL${TPL_NAME}.cmake module
if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
print_var(${TPL_NAME}_FINDMOD)
endif()

if (${TPL_NAME}_FINDMOD STREQUAL "TRIBITS_PKG")
message("Calling find_package(${TPL_NAME}) for TriBITS-compatible package ...")
set(TPL_${TPL_NAME}_PARTS_ALREADY_SET FALSE) # ToDo: Take out?
if (NOT TPL_${TPL_NAME}_PARTS_ALREADY_SET)
find_package(${TPL_NAME} CONFIG REQUIRED)
global_set(TPL_${TPL_NAME}_PARTS_ALREADY_SET TRUE)
endif()
return()
elseif (IS_ABSOLUTE ${${TPL_NAME}_FINDMOD})
tribits_process_enabled_tribits_compatible_tpl(${TPL_NAME})
else()
tribits_process_enabled_tribits_find_tpl_mod_file(${TPL_NAME})
tribits_address_failed_tpl_find(${TPL_NAME})
tribits_generate_tpl_version_file_and_add_package_config_install_targets(
${TPL_NAME})
endif()

endif()

endmacro()


# Get external package/TPL processing string
#
function(tribits_get_enabled_tpl_processing_string TPL_NAME tplProcessingStringOut)
set(tplProcessingString "Processing enabled external package/TPL: ${TPL_NAME} (")
if (${TPL_NAME}_ENABLING_PKG)
string(APPEND tplProcessingString "enabled by ${${TPL_NAME}_ENABLING_PKG}," )
else()
string(APPEND tplProcessingString "enabled explicitly," )
endif()
string(APPEND tplProcessingString " disable with -DTPL_ENABLE_${TPL_NAME}=OFF)" )
set(${tplProcessingStringOut} "${tplProcessingString}" PARENT_SCOPE)
endfunction()


# Process an enabled TPL defined using a fully TriBITS-compatible
# <tplName>Config.cmake file
#
macro(tribits_process_enabled_tribits_compatible_tpl TPL_NAME)
message("-- "
"Calling find_package(${TPL_NAME}) for TriBITS-compatible package ...")
set(TPL_${TPL_NAME}_PARTS_ALREADY_SET FALSE) # ToDo: Take out?
if (NOT TPL_${TPL_NAME}_PARTS_ALREADY_SET)
find_package(${TPL_NAME} CONFIG REQUIRED)
set(TPL_${TPL_NAME}_PARTS_ALREADY_SET TRUE)
endif()
endmacro()


# Process an enabled TPL defined using a FindTPL<tplName>.cmake module
#
macro(tribits_process_enabled_tribits_find_tpl_mod_file TPL_NAME)

if (IS_ABSOLUTE ${${TPL_NAME}_FINDMOD})
#message("${${TPL_NAME}_FINDMOD} is absolute!")
set(CURRENT_TPL_PATH "${${TPL_NAME}_FINDMOD}")
else()
Expand Down Expand Up @@ -112,56 +139,63 @@ function(tribits_process_enabled_tpl TPL_NAME)
print_var(TPL_${TPL_NAME}_NOT_FOUND)
endif()

# Address failed find of the TPL
if (TPL_${TPL_NAME}_NOT_FOUND AND NOT TPL_TENTATIVE_ENABLE_${TPL_NAME})
endmacro()


function(tribits_address_failed_tpl_find TPL_NAME)
# Address failed find of the TPL
if (TPL_${TPL_NAME}_NOT_FOUND AND NOT TPL_TENTATIVE_ENABLE_${TPL_NAME})
message(
"-- NOTE: The find module file for this failed TPL '${TPL_NAME}' is:\n"
" ${CURRENT_TPL_PATH}\n"
" which is pointed to in the file:\n"
" ${${TPL_NAME}_TPLS_LIST_FILE}\n"
)
if (${TPL_NAME}_ENABLING_PKG)
message(
"-- NOTE: The find module file for this failed TPL '${TPL_NAME}' is:\n"
" ${CURRENT_TPL_PATH}\n"
" which is pointed to in the file:\n"
" ${${TPL_NAME}_TPLS_LIST_FILE}\n"
"TIP: One way to get past the configure failure for the\n"
"TPL '${TPL_NAME}' is to simply disable it with:\n"
" -DTPL_ENABLE_${TPL_NAME}=OFF\n"
"which will disable it and will recursively disable all of the\n"
"downstream packages that have required dependencies on it, including\n"
"the package '${${TPL_NAME}_ENABLING_PKG}' which triggered its enable.\n"
"When you reconfigure, just grep the cmake stdout for '${TPL_NAME}'\n"
"and then follow the disables that occur as a result to see what impact\n"
"this TPL disable has on the configuration of ${PROJECT_NAME}.\n"
)
else()
message(
"TIP: Even though the TPL '${TPL_NAME}' was explicitly enabled in input,\n"
"it can be disabled with:\n"
" -DTPL_ENABLE_${TPL_NAME}=OFF\n"
"which will disable it and will recursively disable all of the\n"
"downstream packages that have required dependencies on it.\n"
"When you reconfigure, just grep the cmake stdout for '${TPL_NAME}'\n"
"and then follow the disables that occur as a result to see what impact\n"
"this TPL disable has on the configuration of ${PROJECT_NAME}.\n"
)
if (${TPL_NAME}_ENABLING_PKG)
message(
"TIP: One way to get past the configure failure for the\n"
"TPL '${TPL_NAME}' is to simply disable it with:\n"
" -DTPL_ENABLE_${TPL_NAME}=OFF\n"
"which will disable it and will recursively disable all of the\n"
"downstream packages that have required dependencies on it, including\n"
"the package '${${TPL_NAME}_ENABLING_PKG}' which triggered its enable.\n"
"When you reconfigure, just grep the cmake stdout for '${TPL_NAME}'\n"
"and then follow the disables that occur as a result to see what impact\n"
"this TPL disable has on the configuration of ${PROJECT_NAME}.\n"
)
else()
message(
"TIP: Even though the TPL '${TPL_NAME}' was explicitly enabled in input,\n"
"it can be disabled with:\n"
" -DTPL_ENABLE_${TPL_NAME}=OFF\n"
"which will disable it and will recursively disable all of the\n"
"downstream packages that have required dependencies on it.\n"
"When you reconfigure, just grep the cmake stdout for '${TPL_NAME}'\n"
"and then follow the disables that occur as a result to see what impact\n"
"this TPL disable has on the configuration of ${PROJECT_NAME}.\n"
)
endif()
message(FATAL_ERROR
"ERROR: TPL_${TPL_NAME}_NOT_FOUND=${TPL_${TPL_NAME}_NOT_FOUND}, aborting!")
endif()

# Generate the <tplName>ConfigVersion.cmake file if it has not been
# created yet and add install targets for <tplName>Config[Version].cmake
set(buildDirExternalPkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}")
set(tplConfigFile
"${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}Config.cmake")
set(tplConfigVersionFile
"${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}ConfigVersion.cmake")
tribits_extpkg_write_config_version_file(${TPL_NAME}
"${tplConfigVersionFile}")
tribits_extpkg_install_config_file(${TPL_NAME} "${tplConfigFile}")
tribits_extpkg_install_config_version_file(${TPL_NAME}
"${tplConfigVersionFile}")

message(FATAL_ERROR
"ERROR: TPL_${TPL_NAME}_NOT_FOUND=${TPL_${TPL_NAME}_NOT_FOUND}, aborting!")
endif()
endfunction()


# Generate the <tplName>ConfigVersion.cmake file for a TriBITS TPL and install
# the already generated <tplName>Config.cmake file
#
function(tribits_generate_tpl_version_file_and_add_package_config_install_targets
TPL_NAME
)
set(buildDirExternalPkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}")
set(tplConfigFile
"${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}Config.cmake")
set(tplConfigVersionFile
"${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}ConfigVersion.cmake")
tribits_extpkg_write_config_version_file(${TPL_NAME}
"${tplConfigVersionFile}")
tribits_extpkg_install_config_file(${TPL_NAME} "${tplConfigFile}")
tribits_extpkg_install_config_version_file(${TPL_NAME}
"${tplConfigVersionFile}")
endfunction()
2 changes: 1 addition & 1 deletion tribits/doc/guides/TribitsMacroFunctionDocTemplate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@MACRO: tribits_package_define_dependencies() +
@MACRO: tribits_package_postprocess() +
@MACRO: tribits_process_subpackages() +
@FUNCTION: tribits_process_enabled_tpl() +
@MACRO: tribits_process_enabled_tpl() +
@MACRO: tribits_project() +
@MACRO: tribits_project_define_extra_repositories() +
@MACRO: tribits_project_enable_all() +
Expand Down
3 changes: 0 additions & 3 deletions tribits/examples/TribitsExampleProject/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@ set(HeaderOnlyTpl_INCLUDE_DIRS
"${${PROJECT_NAME}_TRIBITS_DIR}/examples/tpls/HeaderOnlyTpl"
CACHE PATH "Default set by TriBITS/CMakeLists.txt" )

# This does not get set by TriBITS when this is the TriBITS project :-(
set(TribitsExampleProject_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

# Do all of the processing for this Tribits project
tribits_project()

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ tribits_add_show_deprecated_warnings_option()
add_subdirectory(src)
tribits_add_test_directories(test)

include("${TribitsExampleProject_SOURCE_DIR}/cmake/ExpectedDepsStrings.cmake")
# Set a variable that will be used in downstream packages

if (SimpleCxx_ENABLE_SimpleTpl)
set(simpletplText "simpletpl ")
else()
set(simpletplText)
endif()

global_set(EXPECTED_SIMPLECXX_AND_DEPS
"SimpleCxx ${simpletplText}headeronlytpl")
tribits_pkg_export_cache_var(EXPECTED_SIMPLECXX_AND_DEPS)

#
# E) Do standard post processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@ tribits_subpackage(B)

add_subdirectory(src)

include("${TribitsExampleProject_SOURCE_DIR}/cmake/ExpectedDepsStrings.cmake")
# Set variables that will be used in this package and downstream packages

if (${PROJECT_NAME}_ENABLE_InsertedPkg)
global_set(EXPECTED_INSERTEDPKG_AND_DEPS "InsertedPkg ${EXPECTED_SIMPLECXX_AND_DEPS}")
global_set(EXPECTED_INSERTEDPKG_AND_DEPS_STR "${EXPECTED_INSERTEDPKG_AND_DEPS} ")
else()
global_set(EXPECTED_INSERTEDPKG_DEPS "")
global_set(EXPECTED_INSERTEDPKG_DEPS_STR "")
endif()

if (${PROJECT_NAME}_ENABLE_WithSubpackagesA)
global_set(EXPECTED_A_AND_DEPS "A ${EXPECTED_SIMPLECXX_AND_DEPS}")
global_set(EXPECTED_A_AND_DEPS_STR "${EXPECTED_A_AND_DEPS} ")
else()
global_set(EXPECTED_A_AND_DEPS "")
global_set(EXPECTED_A_AND_DEPS_STR "")
endif()

global_set(EXPECTED_B_DEPS
"${EXPECTED_A_AND_DEPS_STR}${EXPECTED_INSERTEDPKG_AND_DEPS_STR}${EXPECTED_SIMPLECXX_AND_DEPS}")
tribits_pkg_export_cache_var(EXPECTED_B_DEPS)

tribits_add_test_directories(tests)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ tribits_add_library(pws_c
${TAL_EXTRALIB_ARGS} # Used to show warnings and errors
)

include("${TribitsExampleProject_SOURCE_DIR}/cmake/ExpectedDepsStrings.cmake")

tribits_add_test_directories(tests)

tribits_subpackage_postprocess()

0 comments on commit 98ad21e

Please sign in to comment.