Skip to content

Commit

Permalink
Factor longer parts out of base CMakeLists.raw.cmake to streamline (T…
Browse files Browse the repository at this point in the history
…riBITSPub#582)

This will allow me to exclude parts that I don't want to show in the
developers guide.

NOTE: The only reas the test file TribitsExampleProject2_Tests.cmake is
updated is because I took 'a' out of 'in a raw'.
  • Loading branch information
bartlettroscoe committed Sep 13, 2023
1 parent 32f8247 commit 56059fa
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,12 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR
"-D Package1_TRACE_ADD_TEST=TRUE" )
string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" )
list(APPEND package1ConfiRegex
"Using TriBITS Test Functions in a raw CMake Package1 build"
"Using TriBITS Test Functions in raw CMake Package1 build"
"Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]"
"Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" )
elseif (package1UseTribitsTestFunctions STREQUAL "")
list(APPEND package1ConfiRegex
"Using Raw CMake add_test[(][)] in a raw CMake Package1 build" )
"Using Raw CMake add_test[(][)] in raw CMake Package1 build" )
else()
message(FATAL_ERROR
"Error, package1UseTribitsTestFunctions='${package1UseTribitsTestFunctions}' is invalid!")
Expand Down Expand Up @@ -1225,13 +1225,13 @@ function(TribitsExampleProject2_External_RawPackage1_PBP
"-D Package1_TRACE_ADD_TEST=TRUE" )
string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" )
set(package1ConfiRegex
"Using TriBITS Test Functions in a raw CMake Package1 build"
"Using TriBITS Test Functions in raw CMake Package1 build"
"Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]"
"Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" )
elseif (package1UseTribitsTestFunctions STREQUAL "")
set(package1UseTribitsTestFunctionsArgs "")
set(package1ConfiRegex
"Using Raw CMake add_test[(][)] in a raw CMake Package1 build" )
"Using Raw CMake add_test[(][)] in raw CMake Package1 build" )
else()
message(FATAL_ERROR
"Error, package1UseTribitsTestFunctions='${package1UseTribitsTestFunctions}' is invalid!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,12 @@ find_package(Tpl1 CONFIG REQUIRED)
add_subdirectory(src)
if (Package1_ENABLE_TESTS)
include(CTest)
if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR)
set(Package1_ENABLE_TESTS ON)
include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake")
include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/EnableTribitsTestSupport.cmake")
add_subdirectory(test)
endif()

# Generate the all_libs target(s)
add_library(Package1_all_libs INTERFACE)
set_target_properties(Package1_all_libs PROPERTIES
EXPORT_NAME all_libs)
target_link_libraries(Package1_all_libs INTERFACE Package1_package1)
install(TARGETS Package1_all_libs
EXPORT ${PROJECT_NAME}
COMPONENT ${PROJECT_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
add_library(Package1::all_libs ALIAS Package1_all_libs)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/DefineAllLibsTarget.cmake")

if (COMMAND tribits_package)
# Generate Package1Config.cmake file for the build tree (for internal
# TriBITS-compliant package)
set(packageBuildDirCMakePackagesDir
"${${CMAKE_PROJECT_NAME}_BINARY_DIR}/cmake_packages/${PROJECT_NAME}")
export(EXPORT ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}ConfigTargets.cmake" )
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in"
"${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake"
@ONLY )
endif()
include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/GeneratePackageConfigFileForBuildDir.cmake")

# Generate and install the Package1Config.cmake file for the install tree
# (needed for both internal and external TriBITS package)
set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(EXPORT ${PROJECT_NAME}
DESTINATION "${pkgConfigInstallDir}"
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}ConfigTargets.cmake )
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake"
@ONLY )
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake"
RENAME "Package1Config.cmake"
DESTINATION "${pkgConfigInstallDir}" )
include("${CMAKE_CURRENT_LIST_DIR}/cmake/raw/GeneratePackageConfigFileForInstallDir.cmake")
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR)

set(Package1_USE_RAW_CMAKE OFF CACHE BOOL
"Use raw CMake for package build, even if TriBITS could be used.")

# Macro to select the TriBITS or the raw CMake build system
macro(include_cmakelists_file)
if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generate the all_libs target(s)
add_library(Package1_all_libs INTERFACE)
set_target_properties(Package1_all_libs
PROPERTIES EXPORT_NAME all_libs)
target_link_libraries(Package1_all_libs
INTERFACE Package1_package1)
install(TARGETS Package1_all_libs
EXPORT ${PROJECT_NAME}
COMPONENT ${PROJECT_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
add_library(Package1::all_libs ALIAS Package1_all_libs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(Package1_USE_TRIBITS_TEST_FUNCTIONS OFF CACHE BOOL
"Use TriBITS testing functions")
set(Package1_TRIBITS_DIR "" CACHE PATH
"Path to TriBITS implementation base dir (e.g. TriBITS/tribits)")
if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR)
# Pull in and turn on TriBITS testing support
include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake")
include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddAdvancedTest.cmake")
set(Package1_ENABLE_TESTS ON)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (COMMAND tribits_package)
# Generate Package1Config.cmake file for the build tree (for internal
# TriBITS-compliant package)
set(packageBuildDirCMakePackagesDir
"${${CMAKE_PROJECT_NAME}_BINARY_DIR}/cmake_packages/${PROJECT_NAME}")
export(EXPORT ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}ConfigTargets.cmake" )
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/Package1Config.cmake.in"
"${packageBuildDirCMakePackagesDir}/${PROJECT_NAME}/Package1Config.cmake"
@ONLY )
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generate and install the Package1Config.cmake file for the install tree
# (needed for both internal and external TriBITS package)
set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(EXPORT ${PROJECT_NAME}
DESTINATION "${pkgConfigInstallDir}"
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}ConfigTargets.cmake )
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/raw/Package1Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake"
@ONLY )
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Package1Config.install.cmake"
RENAME "Package1Config.cmake"
DESTINATION "${pkgConfigInstallDir}" )
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE)
if (Package1_USE_TRIBITS_TEST_FUNCTIONS)
message("-- Using TriBITS Test Functions in a raw CMake Package1 build!")
if ((NOT COMMAND tribits_project) OR Package1_USE_RAW_CMAKE)
if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND (COMMAND tribits_add_test))
message("-- Using TriBITS Test Functions in raw CMake Package1 build!")
include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.tribits.cmake")
else()
message("-- Using Raw CMake add_test() in a raw CMake Package1 build!")
message("-- Using Raw CMake add_test() in raw CMake Package1 build!")
include("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.raw.cmake")
endif()
else()
Expand Down

0 comments on commit 56059fa

Please sign in to comment.