| 1 |
include(CMakePrintHelpers) |
| 2 |
|
| 3 |
|
| 4 |
# Find TribitsExProj package(s), load compilers and compiler options, and get |
| 5 |
# CMake lib targets (which have include dirs also) to link against. |
| 6 |
# |
| 7 |
# On return, sets the vars in the current scope: |
| 8 |
# |
| 9 |
# * TribitsExProj_SELECTED_PACKAGE_LIST: List of all of the packages pulled in |
| 10 |
# * from the TribtsExProj. |
| 11 |
# |
| 12 |
# * APP_DEPS_LIB_TARGETS: List of all of the IMPORTED CMake targets that 'app' |
| 13 |
# must link against |
| 14 |
# |
| 15 |
# * CMAKE_<LANG>_COMPILER and CMAKE_<LANG>_FLAGS pulled in from the |
| 16 |
# TribitsExProjConfig.config or a <Package>Config.cmake file |
| 17 |
# |
| 18 |
macro(getTribitsExProjStuffForApp) |
| 19 |
|
| 20 |
set(${PROJECT_NAME}_FIND_INDIVIDUAL_PACKAGES OFF CACHE BOOL |
| 21 |
"Set to TRUE to find individual packages and OFF to find project TribitsExProj") |
| 22 |
|
| 23 |
if (${PROJECT_NAME}_FIND_INDIVIDUAL_PACKAGES) |
| 24 |
getTribitsExProjStuffForAppByPackage() |
| 25 |
else() |
| 26 |
getTribitsExProjStuffForAppByProject() |
| 27 |
endif() |
| 28 |
|
| 29 |
endmacro() |
| 30 |
|
| 31 |
|
| 32 |
# Get TribitsExProj stuff with find_package(<Package>) for each |
| 33 |
# package/component independently. |
| 34 |
# |
| 35 |
macro(getTribitsExProjStuffForAppByPackage) |
| 36 |
|
| 37 |
# Find each package and gather up all the <Package>::all_libs targets |
| 38 |
set(APP_DEPS_LIB_TARGETS "") |
| 39 |
foreach (packageName IN LISTS ${PROJECT_NAME}_USE_COMPONENTS) |
| 40 |
find_package(${packageName} REQUIRED) |
| 41 |
message("Found ${packageName}!") |
| 42 |
list(APPEND APP_DEPS_LIB_TARGETS ${packageName}::all_libs) |
| 43 |
endforeach() |
| 44 |
print_var(APP_DEPS_LIB_TARGETS) |
| 45 |
|
| 46 |
# Set TribitsExProj_SELECTED_PACKAGE_LIST |
| 47 |
set(TribitsExProj_SELECTED_PACKAGE_LIST ${${PROJECT_NAME}_USE_COMPONENTS}) |
| 48 |
# NOTE: We are setting his here since TribitsExProjConfig.cmake is not being |
| 49 |
# read in in this case. |
| 50 |
|
| 51 |
# Get compilers from first package listed |
| 52 |
list(GET ${PROJECT_NAME}_USE_COMPONENTS 0 firstPkg) |
| 53 |
setCompilersForAppFromConfigFileCompilers(${firstPkg}) |
| 54 |
|
| 55 |
endmacro() |
| 56 |
|
| 57 |
|
| 58 |
# Get TribitsExProj stuff from find_package(TribitsExProj) |
| 59 |
# |
| 60 |
macro(getTribitsExProjStuffForAppByProject) |
| 61 |
|
| 62 |
find_package(TribitsExProj REQUIRED COMPONENTS ${${PROJECT_NAME}_USE_COMPONENTS}) |
| 63 |
|
| 64 |
message("\nFound TribitsExProj! Here are the details: ") |
| 65 |
message(" TribitsExProj_DIR = ${TribitsExProj_DIR}") |
| 66 |
message(" TribitsExProj_VERSION = ${TribitsExProj_VERSION}") |
| 67 |
message(" TribitsExProj_PACKAGE_LIST = ${TribitsExProj_PACKAGE_LIST}") |
| 68 |
message(" TribitsExProj_BUILD_SHARED_LIBS = ${TribitsExProj_BUILD_SHARED_LIBS}") |
| 69 |
message("End of TribitsExProj details\n") |
| 70 |
|
| 71 |
# Make sure to use same compilers and flags as TribitsExProj |
| 72 |
setCompilersForAppFromConfigFileCompilers(TribitsExProj) |
| 73 |
|
| 74 |
# Get the libraries for building and linking |
| 75 |
if (${PROJECT_NAME}_USE_COMPONENTS) |
| 76 |
set(APP_DEPS_LIB_TARGETS TribitsExProj::all_selected_libs) |
| 77 |
else() |
| 78 |
set(APP_DEPS_LIB_TARGETS TribitsExProj::all_libs) |
| 79 |
endif() |
| 80 |
|
| 81 |
endmacro() |
| 82 |
|
| 83 |
|
| 84 |
# Get compilers and compiler flags from the imported |
| 85 |
# ``TribitsExProjConfig.cmake`` or ``<Package>Config.cmake`` file. |
| 86 |
# |
| 87 |
# Here ``prefix`` is the prefix for the variables read in from the |
| 88 |
# *Config.cmake file. |
| 89 |
# |
| 90 |
macro(setCompilersForAppFromConfigFileCompilers prefix) |
| 91 |
|
| 92 |
message("-- Setting compilers and flags read in from '${prefix}Config.cmake' file:") |
| 93 |
|
| 94 |
set(CMAKE_CXX_COMPILER ${${prefix}_CXX_COMPILER} ) |
| 95 |
set(CMAKE_C_COMPILER ${${prefix}_C_COMPILER} ) |
| 96 |
set(CMAKE_Fortran_COMPILER ${${prefix}_Fortran_COMPILER} ) |
| 97 |
|
| 98 |
set(CMAKE_CXX_FLAGS "${${prefix}_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}") |
| 99 |
set(CMAKE_C_FLAGS "${${prefix}_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}") |
| 100 |
set(CMAKE_Fortran_FLAGS "${${prefix}_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}") |
| 101 |
|
| 102 |
cmake_print_variables(CMAKE_CXX_COMPILER) |
| 103 |
cmake_print_variables(CMAKE_C_COMPILER) |
| 104 |
cmake_print_variables(CMAKE_Fortran_COMPILER) |
| 105 |
cmake_print_variables(CMAKE_CXX_FLAGS) |
| 106 |
cmake_print_variables(CMAKE_C_FLAGS) |
| 107 |
cmake_print_variables(CMAKE_Fortran_FLAGS) |
| 108 |
|
| 109 |
endmacro() |
| 110 |
|
| 111 |
|
| 112 |
# Add compiler defines to the ``app`` target for optionally supported packages |
| 113 |
# from upstream TribitExProj |
| 114 |
# |
| 115 |
function(addAppDepCompileDefines) |
| 116 |
addAppDepCompileDefine("SimpleCxx") |
| 117 |
addAppDepCompileDefine("MixedLang") |
| 118 |
addAppDepCompileDefine("WithSubpackagesA") |
| 119 |
addAppDepCompileDefine("WithSubpackagesB") |
| 120 |
addAppDepCompileDefine("WithSubpackagesC") |
| 121 |
endfunction() |
| 122 |
|
| 123 |
|
| 124 |
function(addAppDepCompileDefine componentName) |
| 125 |
if (TARGET ${componentName}::all_libs) |
| 126 |
string(TOUPPER "${componentName}" componentNameUpper) |
| 127 |
target_compile_definitions(app PRIVATE TRIBITSEXAPP_HAVE_${componentNameUpper}) |
| 128 |
endif() |
| 129 |
endfunction() |
| 130 |
# NOTE: Above, we look to see if the 'all_libs' target for a package is |
| 131 |
# defined as a way to know if that package is enabled. That will determine if |
| 132 |
# the package is enabled even if it is just implicitly enabled and therefore |
| 133 |
# is not listed in the list of COMPONENTS passed to find_package(). |
| 134 |
|
| 135 |
|
| 136 |
# Return the extended dependency string from the app at runtime given the |
| 137 |
# enabled packages from TribitsExProj. |
| 138 |
# |
| 139 |
function(getExpectedAppDepsStr expectedDepsStrOut) |
| 140 |
|
| 141 |
if (TARGET SimpleTpl::all_libs) |
| 142 |
set(simpleCxxDeps "simpletpl ") |
| 143 |
else() |
| 144 |
set(simpleCxxDeps "") |
| 145 |
endif() |
| 146 |
set(simpleCxxDeps "${simpleCxxDeps}headeronlytpl") |
| 147 |
|
| 148 |
set(withSubpackagesADeps "SimpleCxx ${simpleCxxDeps}") |
| 149 |
set(withSubpackagesBDeps "A ${withSubpackagesADeps} SimpleCxx ${simpleCxxDeps}") |
| 150 |
set(withSubpackagesCDeps "B ${withSubpackagesBDeps} A ${withSubpackagesADeps}") |
| 151 |
|
| 152 |
set(depsStr "") |
| 153 |
appendExpectedAppDepsStr("WithSubpackagesC" |
| 154 |
"WithSubpackagesC:${withSubpackagesCDeps}" |
| 155 |
depsStr) |
| 156 |
appendExpectedAppDepsStr("WithSubpackagesB" |
| 157 |
"WithSubpackagesB:${withSubpackagesBDeps}" |
| 158 |
depsStr) |
| 159 |
appendExpectedAppDepsStr("WithSubpackagesA" |
| 160 |
"WithSubpackagesA:${withSubpackagesADeps}" |
| 161 |
depsStr) |
| 162 |
appendExpectedAppDepsStr("MixedLang" "MixedLang:Mixed Language" depsStr) |
| 163 |
appendExpectedAppDepsStr("SimpleCxx" "SimpleCxx:${simpleCxxDeps}" depsStr) |
| 164 |
|
| 165 |
set(${expectedDepsStrOut} "${depsStr}" PARENT_SCOPE) |
| 166 |
|
| 167 |
endfunction() |
| 168 |
|
| 169 |
|
| 170 |
function(appendExpectedAppDepsStr componentName str depsStrOut) |
| 171 |
set(depsStr "${${depsStrOut}}") # Should be value of var in parent scope! |
| 172 |
#message("-- depsStr (inner) = '${depsStr}'") |
| 173 |
if (TARGET ${componentName}::all_libs) |
| 174 |
if (depsStr) |
| 175 |
set(depsStr "${depsStr}[;] ${str}") |
| 176 |
else() |
| 177 |
set(depsStr "${str}") |
| 178 |
endif() |
| 179 |
endif() |
| 180 |
set(${depsStrOut} "${depsStr}" PARENT_SCOPE) |
| 181 |
endfunction() |
| 182 |
|
| 183 |
|
| 184 |
function(print_var varName) |
| 185 |
message("-- ${varName} = '${${varName}}'") |
| 186 |
endfunction() |