Skip to content

Commit

Permalink
Move <tplName>Config[Version].cmake files to external_packages/ dir (T…
Browse files Browse the repository at this point in the history
…riBITSPub#299, TriBITSPub#427)

This has two benefits:

* It makes a distinction between <Package>Config.cmake files that are unique
  and created by the CMake project (and are put in <buildDir>/cmake_packages/
  on installed under <installDir>/lib/cmake/) and those <tplName>Config.cmake
  files that are created by TriBITS to create standard targets needed to be
  used by downstream TriBITS projects.

* It avoids find_package() from accidentally finding these TriBITS-generated
  <tplName>Config.cmake files in all contexts when <buildDir>/cmake_packages
  and <installDir> are added to CMAKE_PREFIX_PATH.  This way, for example,
  downstream customer raw CMake projects will not accidentally find the
  TriBITS-generated HDF5Config.cmake when the Trilinos install dir is added to
  CMAKE_PREFIX_PATH.

NOTE: This change is not needed to make the test
TribitsExampleProject2_install_config_again pass due to commit:

  Write out <tplName>ConfigVersion.cmake and disallow finding <tplName>Config.cmake (TriBITSPub#299, TriBITSPub#427)

but this makes it even more robust to not find these <tplName>Config.cmake
files by accident.
  • Loading branch information
bartlettroscoe committed Nov 10, 2021
1 parent 8779829 commit 1507920
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
3 changes: 3 additions & 0 deletions test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ tribits_add_advanced_test( TribitsExampleProject_ALL_ST_NoFortran
MESSAGE "Build 'install' target using raw 'make'"
CMND make ARGS install ${CTEST_BUILD_FLAGS}
PASS_REGULAR_EXPRESSION_ALL
"Install configuration: .RELEASE."
"Installing: .*/install/lib/external_packages/HeaderOnlyTpl/HeaderOnlyTplConfig.cmake"
"Installing: .*/install/lib/external_packages/HeaderOnlyTpl/HeaderOnlyTplConfigVersion.cmake"
"Installing: .+/install/include/TribitsExProj_version.h"
"Installing: .+/install/lib/cmake/TribitsExProj/TribitsExProjConfig.cmake"
"Installing: .+/install/lib/cmake/TribitsExProj/TribitsExProjConfigVersion.cmake"
Expand Down
2 changes: 2 additions & 0 deletions tribits/core/package_arch/TribitsConstants.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ set(${PROJECT_NAME}_PACKAGE_DEPS_TABLE_HTML_FILE_NAME ${PROJECT_NAME}PackageDepe

set(${PROJECT_NAME}_PACKAGE_DEPS_FILES_DIR "cmake/dependencies")

set(${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR "external_packages")

set(${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR "cmake_packages")

# Other stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ endfunction()
function(tribits_external_package_install_config_file tplName tplConfigFile)
install(
FILES "${tplConfigFile}"
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${tplName}"
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/external_packages/${tplName}"
)
endfunction()

Expand All @@ -155,7 +155,7 @@ function(tribits_external_package_install_config_version_file tplName
)
install(
FILES "${tplConfigVersionFile}"
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${tplName}"
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/external_packages/${tplName}"
)
endfunction()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,12 @@ function(tribits_tpl_find_include_dirs_and_libraries TPL_NAME)
global_set(TPL_${TPL_NAME}_NOT_FOUND FALSE)
endif()

set(buildDirCMakePkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR}")
set(buildDirExternalPkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}")
set(tplConfigFile
"${buildDirCMakePkgsDir}/${TPL_NAME}/${TPL_NAME}Config.cmake")
"${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}Config.cmake")
set(tplConfigVersionFile
"${buildDirCMakePkgsDir}/${TPL_NAME}/${TPL_NAME}ConfigVersion.cmake")
"${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}ConfigVersion.cmake")
tribits_external_package_write_config_file(${TPL_NAME} "${tplConfigFile}")
tribits_external_package_write_config_version_file(${TPL_NAME} "${tplConfigVersionFile}")
if (NOT ${PROJECT_NAME}_ENABLE_INSTALLATION_TESTING)
Expand Down
34 changes: 21 additions & 13 deletions tribits/core/package_arch/TribitsWriteClientExportFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ endfunction()
#
function(tribits_generate_package_config_file_for_build_tree packageName)

set(BUILD_DIR_CMAKE_PKGS_DIR
set(buildDirExtPkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}")
set(buildDirCMakePkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR}")

if (PARSE_PACKAGE_CONFIG_FOR_BUILD_BASE_DIR
Expand All @@ -382,7 +384,8 @@ function(tribits_generate_package_config_file_for_build_tree packageName)
set(PACKAGE_CONFIG_CODE "")

tribits_append_dependent_package_config_file_includes(${packageName}
CONFIG_FILE_BASE_DIR "${BUILD_DIR_CMAKE_PKGS_DIR}"
EXT_PKG_CONFIG_FILE_BASE_DIR "${buildDirExtPkgsDir}"
PKG_CONFIG_FILE_BASE_DIR "${buildDirCMakePkgsDir}"
CONFIG_FILE_STR_INOUT PACKAGE_CONFIG_CODE )

# Import build tree targets into applications.
Expand Down Expand Up @@ -469,7 +472,9 @@ function(tribits_generate_package_config_file_for_install_tree packageName)
set(PACKAGE_CONFIG_CODE "")

tribits_append_dependent_package_config_file_includes(${packageName}
CONFIG_FILE_BASE_DIR "\${CMAKE_CURRENT_LIST_DIR}/.."
EXT_PKG_CONFIG_FILE_BASE_DIR
"\${CMAKE_CURRENT_LIST_DIR}/../../${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}"
PKG_CONFIG_FILE_BASE_DIR "\${CMAKE_CURRENT_LIST_DIR}/.."
CONFIG_FILE_STR_INOUT PACKAGE_CONFIG_CODE )

# Import install targets
Expand Down Expand Up @@ -499,14 +504,15 @@ endfunction()

# @FUNCTION: tribits_append_dependent_package_config_file_includes()
#
# Append the includes for upstream internal packages and external packages
# (TPLs) to a `<Package>Config.cmake` file string.
# Append the includes for upstream external packages (TPLs) and internal
# packages to a `<Package>Config.cmake` file string.
#
# Usage::
#
# tribits_append_dependent_package_config_file_includes(
# <packageName>
# CONFIG_FILE_BASE_DIR <configFileBaseDir>
# EXT_PKG_CONFIG_FILE_BASE_DIR <extPkgconfigFileBaseDir>
# PKG_CONFIG_FILE_BASE_DIR <pkgConfigFileBaseDir>
# CONFIG_FILE_STR_INOUT <configFileStrInOut>
# )
#
Expand All @@ -517,20 +523,22 @@ function(tribits_append_dependent_package_config_file_includes packageName)
cmake_parse_arguments(
PARSE #prefix
"" #options
"CONFIG_FILE_BASE_DIR;CONFIG_FILE_STR_INOUT" #one_value_keywords
#one_value_keywords
"EXT_PKG_CONFIG_FILE_BASE_DIR;PKG_CONFIG_FILE_BASE_DIR;CONFIG_FILE_STR_INOUT"
"" #multi_value_keywords
${ARGN}
)
tribits_check_for_unparsed_arguments()

set(configFileBaseDir "${PARSE_CONFIG_FILE_BASE_DIR}")
set(extPkgConfigFileBaseDir "${PARSE_EXT_PKG_CONFIG_FILE_BASE_DIR}")
set(pkgConfigFileBaseDir "${PARSE_PKG_CONFIG_FILE_BASE_DIR}")
set(configFileStr "${${PARSE_CONFIG_FILE_STR_INOUT}}")

# Include configurations of dependent packages
string(APPEND configFileStr
"# Include configuration of dependent packages\n")
foreach(depPkg IN LISTS ${packageName}_FULL_ENABLED_DEP_PACKAGES)
set(cmakePkgDir "${configFileBaseDir}/${depPkg}")
set(cmakePkgDir "${pkgConfigFileBaseDir}/${depPkg}")
string(APPEND configFileStr
"include(\"${cmakePkgDir}/${depPkg}Config.cmake\")\n")
endforeach()
Expand All @@ -540,14 +548,14 @@ function(tribits_append_dependent_package_config_file_includes packageName)
"\n# Include configuration of dependent external packages/TPls\n")
foreach(depTpl IN LISTS ${packageName}_LIB_REQUIRED_DEP_TPLS)
if (TARGET ${depTpl}::all_libs)
set(cmakeTplDir "${configFileBaseDir}/${depTpl}")
set(cmakeTplDir "${extPkgConfigFileBaseDir}/${depTpl}")
string(APPEND configFileStr
"include(\"${cmakeTplDir}/${depTpl}Config.cmake\")\n")
endif()
endforeach()
foreach(depTpl IN LISTS ${packageName}_LIB_OPTIONAL_DEP_TPLS)
if (${packageName}_ENABLE_${depTpl} AND TARGET ${depTpl}::all_libs)
set(cmakeTplDir "${configFileBaseDir}/${depTpl}")
set(cmakeTplDir "${extPkgConfigFileBaseDir}/${depTpl}")
string(APPEND configFileStr
"include(\"${cmakeTplDir}/${depTpl}Config.cmake\")\n")
endif()
Expand Down Expand Up @@ -645,7 +653,7 @@ function(tribits_write_package_client_export_files PACKAGE_NAME)
message("\nTRIBITS_WRITE_PACKAGE_CLIENT_EXPORT_FILES: ${PACKAGE_NAME}")
endif()

set(BUILD_DIR_CMAKE_PKGS_DIR
set(buildDirCMakePkgsDir
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR}")

set(EXPORT_FILES_ARGS PACKAGE_NAME ${PACKAGE_NAME})
Expand All @@ -655,7 +663,7 @@ function(tribits_write_package_client_export_files PACKAGE_NAME)
message("For package ${PACKAGE_NAME} creating ${PACKAGE_NAME}Config.cmake")
endif()
set(PACKAGE_CONFIG_FOR_BUILD_BASE_DIR
"${BUILD_DIR_CMAKE_PKGS_DIR}/${PACKAGE_NAME}" )
"${buildDirCMakePkgsDir}/${PACKAGE_NAME}" )
set(PACKAGE_CONFIG_FOR_INSTALL_BASE_DIR
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles" )
append_set(EXPORT_FILES_ARGS
Expand Down

0 comments on commit 1507920

Please sign in to comment.