Skip to content

Commit

Permalink
Write out <tplName>ConfigVersion.cmake and disallow finding <tplName>…
Browse files Browse the repository at this point in the history
…Config.cmake (TriBITSPub#299, TriBITSPub#427)

This is one solution to the problem of finding <tplName>Config.cmake files in
the CMAKE_INSTALL_PREFIX directory in the middile of a FindTpl<tplName>.cmake
module.  If you have to write a FindTpl<tplName>.cmake module, you are not
expecting/wanting to find a TriBTIS-written <tplName>Config.cmake file.  See
the comment in TribitsProcessEnabledTpl.cmake for more details.

This should fix the bug reported in TriBITSPub#427 where the find_package(HDF5 ...) call
in FindTPLHDF5.cmake was finding HDF5Config.cmake in the install tree written
by TriBITS in a previous installation.

I am not sure this is the best solution to this problem but it has the
advantage that we keep the <Package>Config.cmake files for external package
and TriBITS package side-by-side.  I suspect that I will implement another
solution but at least this is a start to writing <tplName>ConfigVersion.cmake
files.
  • Loading branch information
bartlettroscoe committed Nov 12, 2021
1 parent fb79c7f commit b4a6628
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ function(tribits_external_package_write_config_file tplName tplConfigFile)
endfunction()


# @FUNCTION: tribits_external_package_write_config_version_file()
#
# Write out a ``<tplName>ConfigVersion.cmake`` file.
#
# Usage::
#
# tribits_write_external_package_config_version_file(
# <tplName> <tplConfigVersionFile> )
#
# ToDo: Add version arguments!
#
# The arguments are:
#
# ``<tplName>``: Name of the external package/TPL
#
# ``<tplConfigVersionFile>``: Full file path for the
# ``<tplName>ConfigVersion.cmake`` file that will be written out.
#
function(tribits_external_package_write_config_version_file tplName tplConfigVersionFile)
set(tplConfigVersionFileStr "")
string(APPEND tplConfigVersionFileStr
"# Package config file for external package/TPL '${tplName}'\n"
"#\n"
"# Generated by CMake, do not edit!\n"
"\n"
"if (TRIBITS_FINDING_RAW_${tplName}_PACKAGE_FIRST)\n"
" set(PACKAGE_VERSION_COMPATIBLE FALSE)\n"
" set(PACKAGE_VERSION_UNSUITABLE TRUE)\n"
"else()\n"
" set(PACKAGE_VERSION_COMPATIBLE TRUE)\n"
"endif()\n"
"\n"
"# Currently there is no version information\n"
"set(PACKAGE_VERSION UNKNOWN)\n"
"set(PACKAGE_VERSION_EXACT FALSE)\n"
)
file(WRITE "${tplConfigVersionFile}" "${tplConfigVersionFileStr}")
endfunction()


# @FUNCTION: tribits_external_package_install_config_file()
#
# Install an already-generated ``<tplName>Config.cmake`` file.
Expand All @@ -93,6 +133,33 @@ function(tribits_external_package_install_config_file tplName tplConfigFile)
endfunction()


# @FUNCTION: tribits_external_package_install_config_version_file()
#
# Install an already-generated ``<tplName>ConfigVersion.cmake`` file.
#
# Usage::
#
# tribits_write_external_package_install_config_version_file(
# <tplName> <tplConfigVersionFile> )
#
# The arguments are:
#
# ``<tplName>``: Name of the external package/TPL
#
# ``<tplConfigVersionFile>``: Full file path for the
# ``<tplName>ConfigVersion.cmake`` file that will be installed into the
# correct location.
#
function(tribits_external_package_install_config_version_file tplName
tplConfigVersionFile
)
install(
FILES "${tplConfigVersionFile}"
DESTINATION "${${PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${tplName}"
)
endfunction()


# @FUNCTION: tribits_external_package_write_config_file_str()
#
# Create the text strig for a ``<tplName>Config.cmake`` file given the list of
Expand Down
11 changes: 11 additions & 0 deletions tribits/core/package_arch/TribitsProcessEnabledTpl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ function(tribits_process_enabled_tpl TPL_NAME)

# Process the FindTPL${TPL_NAME}.cmake module
tribits_trace_file_processing(TPL INCLUDE "${CURRENT_TPL_PATH}")
set(TRIBITS_FINDING_RAW_${TPL_NAME}_PACKAGE_FIRST TRUE)
include("${CURRENT_TPL_PATH}")
unset(TRIBITS_FINDING_RAW_${TPL_NAME}_PACKAGE_FIRST)
# NOTE: Above, setting TRIBITS_FINDING_RAW_${TPL_NAME}_PACKAGE_FIRST=TRUE
# triggers special logic in the TriBITS-created
# ${TPL_NAME}ConfigVersion.cmake file to set
# PACKAGE_VERSION_COMPATIBLE=FALSE and result in find_package(${TPL_NAME})
# that may be called inside of ${TPL_NAME}_FINDMOD to not find a
# TriBITS-generated ${TPL_NAME}Config.cmake file. This allows
# find_package(${TPL_NAME}) to usae a proper non-TriBITS
# Find${TPL_NAME}.cmake module or find a non-TriBITS
# ${TPL_NAME}Config.cmake module.

if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
print_var(TPL_${TPL_NAME}_NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,16 @@ function(tribits_tpl_find_include_dirs_and_libraries TPL_NAME)
"${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_CMAKE_PKGS_DIR}")
set(tplConfigFile
"${buildDirCMakePkgsDir}/${TPL_NAME}/${TPL_NAME}Config.cmake")
set(tplConfigVersionFile
"${buildDirCMakePkgsDir}/${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)
include("${tplConfigFile}")
endif()
tribits_external_package_install_config_file(${TPL_NAME} "${tplConfigFile}")
tribits_external_package_install_config_version_file(${TPL_NAME}
"${tplConfigVersionFile}")

endfunction()

Expand Down

0 comments on commit b4a6628

Please sign in to comment.