forked from TriBITSPub/TriBITS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break out clean CMakeLists.[raw|tribits].cmake files (TriBITSPub#582)
This makes it easier to compare the TriBITS build system for a package with a raw CMake build system that is TriBITS-compliant.
- Loading branch information
1 parent
fcd82bb
commit 950e528
Showing
7 changed files
with
88 additions
and
83 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.raw.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) | ||
|
||
if (COMMAND tribits_package) | ||
message("Configuring raw CMake package Package1") | ||
else() | ||
message("Configuring raw CMake project Package1") | ||
endif() | ||
|
||
# Standard project-level stuff | ||
project(Package1 LANGUAGES C CXX) | ||
include(GNUInstallDirs) | ||
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() | ||
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) | ||
|
||
# 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 ) | ||
|
||
# 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}" ) |
5 changes: 5 additions & 0 deletions
5
tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.tribits.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
message("Configuring package Package1 as full TriBITS package") | ||
tribits_package(Package1) | ||
add_subdirectory(src) | ||
tribits_add_test_directories(test) | ||
tribits_package_postprocess() |
76 changes: 7 additions & 69 deletions
76
tribits/examples/TribitsExampleProject2/packages/package1/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR) | ||
|
||
macro(include_raw_cmake_build) | ||
# 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) | ||
include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.raw.cmake" | ||
NO_POLICY_SCOPE) | ||
return() | ||
endif() | ||
endmacro() | ||
|
||
if ((COMMAND tribits_package) AND (NOT Package1_USE_RAW_CMAKE)) | ||
|
||
message("Configuring package Package1 as full TriBITS package") | ||
tribits_package(Package1) | ||
add_subdirectory(src) | ||
tribits_add_test_directories(test) | ||
tribits_package_postprocess() | ||
|
||
else() | ||
|
||
if (COMMAND tribits_package) | ||
message("Configuring raw CMake package Package1") | ||
else() | ||
message("Configuring raw CMake project Package1") | ||
endif() | ||
project(Package1 LANGUAGES C CXX) | ||
include(GNUInstallDirs) | ||
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() | ||
add_subdirectory(test) | ||
include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.tribits.cmake" | ||
NO_POLICY_SCOPE) | ||
endif() | ||
endmacro() | ||
|
||
# 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) | ||
|
||
# Generate Package1Config.cmake file for the build tree | ||
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 ) | ||
|
||
# Generate and install the Package1Config.cmake file for the install tree | ||
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}" ) | ||
|
||
endif() | ||
# Pull in the base CMakeLists.txt file variant | ||
include_cmakelists_file() |
4 changes: 4 additions & 0 deletions
4
tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.tribits.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||
tribits_add_library(package1 HEADERS Package1.hpp SOURCES Package1.cpp) | ||
tribits_add_executable(package1-prg NOEXEPREFIX NOEXESUFFIX | ||
SOURCES Package1_Prg.cpp INSTALLABLE ) |
9 changes: 1 addition & 8 deletions
9
tribits/examples/TribitsExampleProject2/packages/package1/src/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
include_raw_cmake_build() | ||
|
||
tribits_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
tribits_add_library(package1 HEADERS Package1.hpp SOURCES Package1.cpp) | ||
|
||
tribits_add_executable(package1-prg NOEXEPREFIX NOEXESUFFIX | ||
SOURCES Package1_Prg.cpp INSTALLABLE ) | ||
include_cmakelists_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters