Skip to content

Commit

Permalink
Merge pull request #520 from bartlettroscoe/516-export-pkg-info-vars
Browse files Browse the repository at this point in the history
Add support for exporting package info vars into <Package>Config.cmake files (#516)
  • Loading branch information
bartlettroscoe authored Aug 23, 2022
2 parents 3559a18 + 903b9a1 commit c85490f
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 77 deletions.
2 changes: 1 addition & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ tribits_add_advanced_test( TribitsWriteClientExportFiles_UnitTests
-DCMAKE_CURRENT_LIST_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/TribitsWriteClientExportFiles_UnitTests.cmake"
PASS_REGULAR_EXPRESSION_ALL
"Final UnitTests Result: num_run = 30"
"Final UnitTests Result: num_run = 33"
"Final UnitTests Result: PASSED"
)

Expand Down
17 changes: 9 additions & 8 deletions test/core/ExamplesUnitTests/TribitsExampleApp_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ function(TribitsExampleApp_NoFortran fullOrComponents sharedOrStatic)
MESSAGE "Copy source for TribitsExampleProject"
CMND ${CMAKE_COMMAND}
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .
WORKING_DIRECTORY TribitsExampleProject
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
TribitsExampleProject

TEST_1
MESSAGE "Do the configure of TribitsExampleProject"
Expand Down Expand Up @@ -344,6 +344,7 @@ function(TribitsExampleApp_NoFortran fullOrComponents sharedOrStatic)
${tribitsExProjUseComponentsArg}
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleApp
PASS_REGULAR_EXPRESSION_ALL
"WithSubpackagesA_SPECIAL_VALUE = '3'"
"-- Configuring done"
"-- Generating done"
"-- Build files have been written to: .*/${testName}/app_build"
Expand Down Expand Up @@ -428,8 +429,8 @@ function(TribitsExampleApp_EnableSingleSubpackage fullOrComponents sharedOrStati
MESSAGE "Copy source for TribitsExampleProject"
CMND ${CMAKE_COMMAND}
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .
WORKING_DIRECTORY TribitsExampleProject
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
TribitsExampleProject

TEST_1
MESSAGE "Make Withsubpackages OPTIONAL subpackages REQUIRED"
Expand Down Expand Up @@ -567,8 +568,8 @@ function(TribitsExampleApp_ALL_ST byProjectOrPackage sharedOrStatic serialOrM
MESSAGE "Copy source for TribitsExampleProject"
CMND ${CMAKE_COMMAND}
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .
WORKING_DIRECTORY TribitsExampleProject
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
TribitsExampleProject

TEST_1
MESSAGE "Do the configure of TribitsExampleProject"
Expand Down Expand Up @@ -963,8 +964,8 @@ function(TribitsExampleApp_ALL_ST_tpl_link_options byProjectOrPackage sharedOrSt
MESSAGE "Copy source for TribitsExampleProject"
CMND ${CMAKE_COMMAND}
ARGS -E copy_directory
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .
WORKING_DIRECTORY TribitsExampleProject
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
TribitsExampleProject

TEST_1
MESSAGE "Write configuration fragment file to deal with semi-colon problem"
Expand Down
26 changes: 19 additions & 7 deletions test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
-DTribitsExProj_DUMP_CPACK_SOURCE_IGNORE_FILES=ON
-DTribitsExProj_DUMP_PACKAGE_DEPENDENCIES=ON
-DTribitsExProj_ENABLE_INSTALL_CMAKE_CONFIG_FILES=ON
-DWithSubpackagesA_SPECIAL_VALUE=5
-DCMAKE_CXX_FLAGS=-DSIMPLECXX_SHOW_DEPRECATED_WARNINGS=1
-DCMAKE_INSTALL_PREFIX=install
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject
Expand Down Expand Up @@ -310,6 +311,17 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_5
MESSAGE "Grep the contents of the WithSubpackagesAConfig.cmake file in build dir"
CMND cat ARGS cmake_packages/WithSubpackagesA/WithSubpackagesAConfig.cmake
PASS_REGULAR_EXPRESSION_ALL
"# Enables/Disables for upstream package dependencies"
"set[(]WithSubpackagesA_ENABLE_SimpleCxx ON[)]"
"# Exported cache variables"
"set[(]WithSubpackages_ENABLE_DEBUG .OFF.[)]"
"set[(]HAVE_WITHSUBPACKAGES_DEBUG .OFF.[)]"
"set[(]WithSubpackagesA_SPECIAL_VALUE .5.[)]"

TEST_6
MESSAGE "Build 'install' target using raw 'make'"
CMND make ARGS install ${CTEST_BUILD_FLAGS}
PASS_REGULAR_EXPRESSION_ALL
Expand Down Expand Up @@ -343,7 +355,7 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
"Installing: .+/install/lib/cmake/WithSubpackagesC/WithSubpackagesCTargets-release.cmake"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_6
TEST_7
MESSAGE "Create and configure a dummy project that calls"
" find_package(WithSubpackages) from the install tree"
CMND ${CMAKE_COMMAND}
Expand Down Expand Up @@ -390,7 +402,7 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
"WithSubpackages::all_libs INTERFACE_LINK_LIBRARIES: 'WithSubpackagesA::pws_a[;]WithSubpackagesB::pws_b[;]WithSubpackagesC::pws_c'"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_7
TEST_8
MESSAGE "Create and configure a dummy project that calls"
" find_package(TribitsExProj) with no components"
CMND ${CMAKE_COMMAND}
Expand Down Expand Up @@ -448,7 +460,7 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
"-- Generating done"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_8
TEST_9
MESSAGE "Create and configure a dummy project that calls find_package(TribitsExProj)"
" with required and optional components"
CMND ${CMAKE_COMMAND}
Expand Down Expand Up @@ -478,7 +490,7 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
"-- Generating done"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_9
TEST_10
MESSAGE "Run find_package() from two different subdirs with related packages"
WORKING_DIRECTORY find_package_two_dirs
CMND ${CMAKE_COMMAND}
Expand All @@ -492,7 +504,7 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
"-- Generating done"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_10
TEST_11
MESSAGE "Create the tarball"
CMND make ARGS package_source
PASS_REGULAR_EXPRESSION_ALL
Expand All @@ -509,12 +521,12 @@ function(TribitsExampleProject_ALL_ST_NoFortran sharedOrStatic serialOrMpi)
"CPack: - package: .*/ExamplesUnitTests/${testName}/tribitsexproj-1.1-Source.tar.bz2 generated."
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_11
TEST_12
MESSAGE "Untar the tarball"
CMND tar ARGS -xzf tribitsexproj-1.1-Source.tar.gz
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_12
TEST_13
MESSAGE "Make sure right directories are excluded"
CMND diff
ARGS -qr
Expand Down
45 changes: 43 additions & 2 deletions test/core/TribitsWriteClientExportFiles_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,46 @@ endmacro()


#
# A) Test basic package processing and reading dependencies
# A) Misc unit tests
#

function(unittest_tribits_assert_cache_and_local_vars_same_value)

message("\n***")
message("*** tribits_assert_cache_and_local_vars_same_value()")
message("***\n")

set(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

message("\nOnly cache var exists")
global_set(MESSAGE_WRAPPER_INPUT)
set(cacheVar1 "1st value" CACHE STRING "")
tribits_assert_cache_and_local_vars_same_value(cacheVar1)
unittest_compare_const(MESSAGE_WRAPPER_INPUT "")
unset(cacheVar1 CACHE)

message("\nCache var and local var with same values exist")
global_set(MESSAGE_WRAPPER_INPUT)
set(cacheVar2 "2nd value" CACHE STRING "")
set(cacheVar2 "2nd value")
tribits_assert_cache_and_local_vars_same_value(cacheVar2)
unittest_compare_const(MESSAGE_WRAPPER_INPUT "")
unset(cacheVar2 CACHE)

message("\nCache var and local var with different values exist")
global_set(MESSAGE_WRAPPER_INPUT)
set(cacheVar3 "3rd value" CACHE STRING "")
set(cacheVar3 "3rd value diff")
tribits_assert_cache_and_local_vars_same_value(cacheVar3)
unittest_compare_const(MESSAGE_WRAPPER_INPUT
"SEND_ERROR;ERROR: The cache variable cacheVar3 with the; cache var value '3rd value' is not the same value as the local; variable cacheVar3 with value '3rd value diff'!")
unset(cacheVar3 CACHE)

endfunction()


#
# B) Test basic package processing and reading dependencies
#


Expand Down Expand Up @@ -255,8 +294,10 @@ unittest_initialize_vars()
# Run the unit tests
#

unittest_tribits_assert_cache_and_local_vars_same_value()

unittest_write_specialized_package_export_makefile_rtop_before_libs()
unittest_write_specialized_package_export_makefile_rtop_after_libs()

# Pass in the number of expected tests that must pass!
unittest_final_result(30)
unittest_final_result(33)
6 changes: 6 additions & 0 deletions tribits/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
ChangeLog for TriBITS
----------------------------------------

## 2022-08-22:

* **Added:** Added support for exporting cache variables for packages in their
`<Package>Config.cmake` files using the new function
`tribits_pkg_export_cache_var()`.

## 2022-08-18:

* **Changed:** Made setting parent package tests/examples enable/disable
Expand Down
7 changes: 7 additions & 0 deletions tribits/core/package_arch/TribitsAddOptionAndDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ include(GlobalSet)
#
# #cmakedefine <macroDefineName>
#
# NOTE: This also calls `tribits_pkg_export_cache_var()`_ to export the
# variables ``<userOptionName>`` and ``<macroDefineName>``.
#
macro(tribits_add_option_and_define USER_OPTION_NAME MACRO_DEFINE_NAME
DOCSTRING DEFAULT_VALUE
)
Expand All @@ -70,6 +73,10 @@ macro(tribits_add_option_and_define USER_OPTION_NAME MACRO_DEFINE_NAME
global_set(${MACRO_DEFINE_NAME} OFF)
endif()
endif()
if (COMMAND tribits_pkg_export_cache_var)
tribits_pkg_export_cache_var(${USER_OPTION_NAME})
tribits_pkg_export_cache_var(${MACRO_DEFINE_NAME})
endif()
endmacro()

# 2008/10/05: rabartl: ToDo: Add an option to automatically add the macro
Expand Down
24 changes: 24 additions & 0 deletions tribits/core/package_arch/TribitsGeneralMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,27 @@ function(tribits_trace_file_processing TYPE_IN PROCESSING_TYPE_IN FILE_PATH)
endif()

endfunction()


# @MACRO: tribits_assert_cache_and_local_vars_same_value()
#
# Asset that a cache variable and a possible local variable (if it exists)
# have the same value.
#
# Usage::
#
# tribits_assert_cache_and_local_vars_same_value(<cacheVarName>)
#
# If the local var ``<cacheVarName>`` and the cache var ``<cacheVarName>``
# both exist but have different values, then ``message(SEND_ERROR ...)`` is
# called with an informative error message.
#
macro(tribits_assert_cache_and_local_vars_same_value cacheVarName)
set(cacheVarValue "$CACHE{${cacheVarName}}")
set(localValue "${${cacheVarName}}")
if (NOT localValue STREQUAL cacheVarValue)
message_wrapper(SEND_ERROR "ERROR: The cache variable ${cacheVarName} with the"
" cache var value '${cacheVarValue}' is not the same value as the local"
" variable ${cacheVarName} with value '${localValue}'!")
endif()
endmacro()
Loading

0 comments on commit c85490f

Please sign in to comment.