Skip to content

Commit

Permalink
Merge branch 'tribits_github_snapshot' into tribits-299-modern-cmake-…
Browse files Browse the repository at this point in the history
…targets-1-again (TriBITSPub/TriBITS#433)

Should address all of the issues with the merge of PR trilinos#9894
listed out in TriBITSPub/TriBITS#433 (which is part of
TriBITSPub/TriBITS#299).  This should resolve the failures reported in
trilinos#9972 and trilinos#9973.
  • Loading branch information
bartlettroscoe committed Dec 15, 2021
2 parents 5113de5 + e9e2860 commit 963854c
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ include(MessageWrapper)
include(DualScopeSet)
include(CMakeParseArguments)


#
# Private helper macros
#
Expand Down Expand Up @@ -314,7 +315,6 @@ macro(tribits_disable_parents_subpackages PARENT_PACKAGE_NAME)
endmacro()


#
# Macro that enables all of the subpackages of a parent package.
#
macro(tribits_enable_parents_subpackages PARENT_PACKAGE_NAME)
Expand Down Expand Up @@ -698,6 +698,8 @@ macro(tribits_postprocess_package_with_subpackages_enables PACKAGE_NAME)
"Setting ${PROJECT_NAME}_ENABLE_${PACKAGE_NAME}=ON"
" because ${PROJECT_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}=ON")
set(${PROJECT_NAME}_ENABLE_${PACKAGE_NAME} ON)
tribits_postprocess_package_with_subpackages_optional_subpackage_enables(
${PACKAGE_NAME})
tribits_postprocess_package_with_subpackages_test_example_enables(
${PACKAGE_NAME} TESTS)
tribits_postprocess_package_with_subpackages_test_example_enables(
Expand All @@ -711,6 +713,27 @@ macro(tribits_postprocess_package_with_subpackages_enables PACKAGE_NAME)
endmacro()


# Set <ParentPackage>_ENABLE_<SubPackage>=ON if not already enabled for all
# subpackages of a parent package.
#
macro(tribits_postprocess_package_with_subpackages_optional_subpackage_enables
PACKAGE_NAME
)
#message("TRIBITS_POSTPROCESS_PACKAGE_WITH_SUBPACKAGES_TEST_EXAMPLE_ENABLES '${PACKAGE_NAME}'")
foreach(TRIBITS_SUBPACKAGE ${${PACKAGE_NAME}_SUBPACKAGES})
set(SUBPACKAGE_FULLNAME ${PACKAGE_NAME}${TRIBITS_SUBPACKAGE})
if (${PROJECT_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}
AND "${${PACKAGE_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}}" STREQUAL ""
)
message("-- "
"Setting ${PACKAGE_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}=ON"
" because ${PROJECT_NAME}_ENABLE_${SUBPACKAGE_FULLNAME}=ON")
set(${PACKAGE_NAME}_ENABLE_${SUBPACKAGE_FULLNAME} ON)
endif()
endforeach()
endmacro()


# Set the parent package tests/examples enables if one subpackage is enabled
# and has its tests/examples
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ endfunction()
#
# Read the ``TPL_<tplName>_LIBRARIES` list variable and produce the string for
# the IMPORTED targets commands and return list of targets and left over
# linker flags..
# linker flags.
#
# Usage::
#
Expand All @@ -243,17 +243,17 @@ endfunction()
#
# The arguments are:
#
# ``<tplName>``: Name of the external package/TPL
# ``<tplName>``: [In] Name of the external package/TPL
#
# ``<libTargetsListOut>``: Name of list variable that will be set with the
# list of IMPORTED library targets generated from this list.
# ``<libTargetsListOut>``: [Out] Name of list variable that will be set with
# the list of IMPORTED library targets generated from this list.
#
# ``<libLinkFlagsListOut>``: Name of list variable that will be set with the
# list of ``-L<dir>`` library directoy paths.
# ``<libLinkFlagsListOut>``: [Out] Name of list variable that will be set
# with the list of ``-L<dir>`` library directoy paths.
#
# ``<configFileFragStrInOut>``: A string variable that will be appended with
# the IMPORTED library commands for the list of targts given in
# ``<libTargetsList>``.
# ``<configFileFragStrInOut>``: [Inout] A string variable that will be
# appended with the IMPORTED library commands for the list of targts given
# in ``<libTargetsList>``.
#
function(tribits_external_package_process_libraries_list tplName)

Expand Down Expand Up @@ -294,6 +294,9 @@ function(tribits_external_package_process_libraries_list tplName)
"ERROR: Can't handle argument '${libentry}' in list TPL_${tplName}_LIBRARIES")
elseif (libEntryType STREQUAL "LIB_DIR_LINK_OPTION")
list(APPEND libLinkFlagsList "${libentry}")
elseif (libEntryType STREQUAL "GENERAL_LINK_OPTION")
message_wrapper("NOTE: Moving the general link argument '${libentry}' in TPL_${tplName}_LIBRARIES forward on the link line which may change the link and break the link!")
list(APPEND libLinkFlagsList "${libentry}")
else()
tribits_external_package_process_libraries_list_library_entry(
${tplName} "${libentry}" ${libEntryType} libTargets lastLib configFileStr )
Expand Down Expand Up @@ -326,25 +329,36 @@ endfunction()
# ``LIB_NAME_LINK_OPTION``: A library name link option of the form
# ``-l<libname>``
#
# ``LIB_NAME``: A library name of the form ``<libname>``
#
# ``LIB_DIR_LINK_OPTION``: A library directory search option of the form
# ``-L<dir>``
#
# ``GENERAL_LINK_OPTION``: Some other general link option that starts with
# ``-`` but is not ``-l`` or ``-L``.
#
# ``UNSUPPORTED_LIB_ENTRY``: An unsupported lib option
#
function(tribits_tpl_libraries_entry_type libentry libEntryTypeOut)
string(SUBSTRING "${libentry}" 0 1 firstCharLibEntry)
string(SUBSTRING "${libentry}" 0 2 firstTwoCharsLibEntry)
if (firstTwoCharsLibEntry STREQUAL "-l")
set(libEntryType LIB_NAME_LINK_OPTION)
elseif (firstTwoCharsLibEntry STREQUAL "-L")
set(libEntryType LIB_DIR_LINK_OPTION)
elseif (firstCharLibEntry STREQUAL "-")
set(libEntryType GENERAL_LINK_OPTION)
elseif (IS_ABSOLUTE "${libentry}")
set(libEntryType FULL_LIB_PATH)
elseif (libentry MATCHES "^[a-zA-Z_][a-zA-Z0-9_-]*$")
set(libEntryType LIB_NAME)
else()
set(libEntryType UNSUPPORTED_LIB_ENTRY)
endif()
set(${libEntryTypeOut} ${libEntryType} PARENT_SCOPE)
endfunction()

# NOTE: Above, if libentry is only 1 char long, then firstTwoCharsLibEntry is
# also 1 char long and the above logic still works.

# Function to process a library inside of loop over TPL_<tplName>_LIBRARIES
# in the function tribits_external_package_process_libraries_list()
Expand Down Expand Up @@ -395,6 +409,9 @@ function(tribits_external_package_get_libname_and_path_from_libentry
elseif (libEntryType STREQUAL "LIB_NAME_LINK_OPTION")
tribits_external_package_get_libname_from_lib_name_link_option("${libentry}" libname)
set(libpath "")
elseif (libEntryType STREQUAL "LIB_NAME")
set(libname "${libentry}")
set(libpath "")
else()
message(FATAL_ERROR "Error libEntryType='${libEntryType}' not supported here!")
endif()
Expand All @@ -414,7 +431,10 @@ function(tribits_external_package_append_add_library_str
"set_target_properties(${prefixed_libname} PROPERTIES\n"
" IMPORTED_LOCATION \"${libpath}\")\n"
)
elseif (libEntryType STREQUAL "LIB_NAME_LINK_OPTION")
elseif (
(libEntryType STREQUAL "LIB_NAME_LINK_OPTION")
OR (libEntryType STREQUAL "LIB_NAME")
)
string(APPEND configFileStr
"add_library(${prefixed_libname} IMPORTED INTERFACE GLOBAL)\n"
"set_target_properties(${prefixed_libname} PROPERTIES\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,22 @@ function(tribits_append_dependent_package_config_file_includes packageName)
# 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 "${pkgConfigFileBaseDir}/${depPkg}")
string(APPEND configFileStr
"include(\"${cmakePkgDir}/${depPkg}Config.cmake\")\n")
foreach(depPkg IN LISTS ${packageName}_LIB_REQUIRED_DEP_PACKAGES)
if (${PROJECT_NAME}_ENABLE_${depPkg})
set(cmakeTplDir "${pkgConfigFileBaseDir}/${depPkg}")
string(APPEND configFileStr
"include(\"${cmakeTplDir}/${depPkg}Config.cmake\")\n")
endif()
# NOTE: Above, a required dependent package may not actaully be enabled if
# it is a required subpackage of a parent package and the parent package
# itself is not actaully enabled (very tricky).
endforeach()
foreach(depPkg IN LISTS ${packageName}_LIB_OPTIONAL_DEP_PACKAGES)
if (${packageName}_ENABLE_${depPkg} AND ${PROJECT_NAME}_ENABLE_${depPkg})
set(cmakeTplDir "${pkgConfigFileBaseDir}/${depPkg}")
string(APPEND configFileStr
"include(\"${cmakeTplDir}/${depPkg}Config.cmake\")\n")
endif()
endforeach()

# Include configurations of dependent external packages/TPLs
Expand Down
2 changes: 1 addition & 1 deletion cmake/tribits/examples/InsertedPkg/InsertedPkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "SimpleCxx_HelloWorld.hpp"

std::string InsertedPkg::deps() {
return SimpleCxx::deps();
return (std::string("SimpleCxx ") + SimpleCxx::deps());
}
2 changes: 1 addition & 1 deletion cmake/tribits/examples/InsertedPkg/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ tribits_add_executable_and_test( test
SOURCES InsertedPkg_test.cpp
NUM_MPI_PROCS 1
PASS_REGULAR_EXPRESSION
"InsertedPkg deps are: headeronlytpl"
"InsertedPkg deps are: ${EXPECTED_SIMPLECXX_AND_DEPS}"
)
26 changes: 21 additions & 5 deletions cmake/tribits/examples/TribitsExampleApp/AppHelperFuncs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,22 @@ endmacro()
function(addAppDepCompileDefines)
addAppDepCompileDefine("SimpleCxx")
addAppDepCompileDefine("MixedLang")
addAppDepCompileDefine("WithSubpackages")
addAppDepCompileDefine("WithSubpackagesA")
addAppDepCompileDefine("WithSubpackagesB")
addAppDepCompileDefine("WithSubpackagesC")
endfunction()


function(addAppDepCompileDefine componentName)
if (${componentName} IN_LIST TribitsExProj_SELECTED_PACKAGE_LIST)
if (TARGET ${componentName}::all_libs)
string(TOUPPER "${componentName}" componentNameUpper)
target_compile_definitions(app PRIVATE TRIBITSEXAPP_HAVE_${componentNameUpper})
endif()
endfunction()
# NOTE: Above, we look to see if the 'all_libs' target for a package is
# defined as a way to know if that package is enabled. That will determine if
# the package is enabled even if it is just implicitly enabled and therefore
# is not listed in the list of COMPONENTS passed to find_package().


# Return the extended dependency string from the app at runtime given the
Expand All @@ -140,9 +146,19 @@ function(getExpectedAppDepsStr expectedDepsStrOut)
endif()
set(simpleCxxDeps "${simpleCxxDeps}headeronlytpl")

set(withSubpackagesADeps "SimpleCxx ${simpleCxxDeps}")
set(withSubpackagesBDeps "A ${withSubpackagesADeps} SimpleCxx ${simpleCxxDeps}")
set(withSubpackagesCDeps "B ${withSubpackagesBDeps} A ${withSubpackagesADeps}")

set(depsStr "")
appendExpectedAppDepsStr("WithSubpackages"
"WithSubpackages:B A ${simpleCxxDeps} ${simpleCxxDeps}"
appendExpectedAppDepsStr("WithSubpackagesC"
"WithSubpackagesC:${withSubpackagesCDeps}"
depsStr)
appendExpectedAppDepsStr("WithSubpackagesB"
"WithSubpackagesB:${withSubpackagesBDeps}"
depsStr)
appendExpectedAppDepsStr("WithSubpackagesA"
"WithSubpackagesA:${withSubpackagesADeps}"
depsStr)
appendExpectedAppDepsStr("MixedLang" "MixedLang:Mixed Language" depsStr)
appendExpectedAppDepsStr("SimpleCxx" "SimpleCxx:${simpleCxxDeps}" depsStr)
Expand All @@ -155,7 +171,7 @@ endfunction()
function(appendExpectedAppDepsStr componentName str depsStrOut)
set(depsStr "${${depsStrOut}}") # Should be value of var in parent scope!
#message("-- depsStr (inner) = '${depsStr}'")
if (${componentName} IN_LIST TribitsExProj_SELECTED_PACKAGE_LIST)
if (TARGET ${componentName}::all_libs)
if (depsStr)
set(depsStr "${depsStr}[;] ${str}")
else()
Expand Down
20 changes: 16 additions & 4 deletions cmake/tribits/examples/TribitsExampleApp/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
#ifdef TRIBITSEXAPP_HAVE_MIXEDLANG
# include "MixedLang.hpp"
#endif
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGES
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGESA
# include "A.hpp"
#endif
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGESB
# include "B.hpp"
#endif
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGESC
# include "wsp_c/C.hpp"
#endif

Expand All @@ -27,11 +33,17 @@ void appendDepsStr(std::string &depsStr, const std::string &str)
int main(int argc, char *argv[]) {
// Get deps down the deps graph
std::string depsStr;
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGES
appendDepsStr(depsStr, "WithSubpackages:"+WithSubpackages::depsC());
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGESC
appendDepsStr(depsStr, "WithSubpackagesC:"+WithSubpackages::depsC());
#endif
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGESB
appendDepsStr(depsStr, "WithSubpackagesB:"+WithSubpackages::depsB());
#endif
#ifdef TRIBITSEXAPP_HAVE_WITHSUBPACKAGESA
appendDepsStr(depsStr, "WithSubpackagesA:"+WithSubpackages::depsA());
#endif
#ifdef TRIBITSEXAPP_HAVE_MIXEDLANG
appendDepsStr(depsStr, "MixedLang:"+tribits_mixed::mixedLang());
appendDepsStr(depsStr, "MixedLang:"+tribits_mixed::mixedLang()); // Just print something
#endif
#ifdef TRIBITSEXAPP_HAVE_SIMPLECXX
appendDepsStr(depsStr, "SimpleCxx:"+SimpleCxx::deps());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ tribits_add_show_deprecated_warnings_option()
#
add_subdirectory(src)
tribits_add_test_directories(test)
#tribits_add_example_directories(example)

# 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")

#
# E) Do standard post processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ std::string WithSubpackages::getA() {
}

std::string WithSubpackages::depsA() {
return SimpleCxx::deps();
return "SimpleCxx "+SimpleCxx::deps();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ tribits_add_advanced_test( test_of_a
TEST_0 EXEC a_test
PASS_REGULAR_EXPRESSION_ALL
"A label is: A"
"A deps are: headeronlytpl"
"A deps are: ${EXPECTED_SIMPLECXX_AND_DEPS}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ tribits_subpackage(B)

add_subdirectory(src)

# 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_add_test_directories(tests)

install( DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/stuff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ std::string WithSubpackages::depsB() {
#ifdef HAVE_WITHSUBPACKAGESB_INSERTEDPKG
B_deps += (std::string("InsertedPkg ") + InsertedPkg::deps() + std::string(" "));
#endif
B_deps += SimpleCxx::deps();
B_deps += (std::string("SimpleCxx ") + SimpleCxx::deps());
return B_deps;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,12 @@ add_subdirectory(testlib)
# Test b_test
#

set(EXPECTED_B_DEPS)
assert_defined(${PACKAGE_NAME}_ENABLE_WithSubpackagesA)
if(${PACKAGE_NAME}_ENABLE_WithSubpackagesA)
set(EXPECTED_B_DEPS "${EXPECTED_B_DEPS} A headeronlytpl")
endif()
if(${PACKAGE_NAME}_ENABLE_InsertedPkg)
set(EXPECTED_B_DEPS "${EXPECTED_B_DEPS} InsertedPkg headeronlytpl")
endif()
set(EXPECTED_B_DEPS "${EXPECTED_B_DEPS} headeronlytpl")

tribits_add_advanced_test( test_of_b
OVERALL_NUM_MPI_PROCS 1
TEST_0 EXEC b_test
PASS_REGULAR_EXPRESSION_ALL
"B label is: B"
"B deps are:${EXPECTED_B_DEPS}"
"B deps are: ${EXPECTED_B_DEPS}"
ADDED_TEST_NAME_OUT test_of_b_TEST_NAME
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ std::string WithSubpackages::getC()

std::string WithSubpackages::depsC()
{
return std::string("B ") + depsB();
return std::string("B ") + depsB() + std::string(" A ") + depsA();
}
Loading

0 comments on commit 963854c

Please sign in to comment.