Skip to content

Commit

Permalink
WIP: Make TriBITS package with raw CMake work (TriBITSPub#582)
Browse files Browse the repository at this point in the history
Allow TriBITS package TribitsExampleProject/Package1 to use 100% raw CMake and
update TriBITS to allow that.

This raw CMake build mode for Package1 uses no TriBITS macros, functions, or
other functionality at all.

The only changes to TriBITS-proper needed to allow this were:

* Skip check for not calling tribits_package_postprocess() if the
  `<Package>::all_libs` target is already defined.

* Build up the list of package libraries target for the `<Project>_libs`
  target from `<Package>::all_libs` instead of `<Package>_libs` (since the
  latter does not exist for a raw CMake package).

This seems to pass all of the TriBITS tests.

NOTE: This commit does **not** yet contain the changes to TriBITS to allow
calling project() in the package's CMakeLists.txt files and still use TriBITS
macros in the package's CMakeLists.txt files.  Those changes will come later
as we add an example that calls some TriBITS functions.
  • Loading branch information
bartlettroscoe committed Jul 26, 2023
1 parent 3ce4dcb commit 7930a20
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
9 changes: 6 additions & 3 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2072,17 +2072,20 @@ macro(tribits_configure_enabled_packages)
tribits_trace_file_processing(PACKAGE ADD_SUBDIR
"${TRIBITS_PACKAGE_CMAKELIST_FILE}")
if (NOT ${TRIBITS_PACKAGE}_SOURCE_DIR STREQUAL ${PROJECT_NAME}_SOURCE_DIR)
add_subdirectory(${${TRIBITS_PACKAGE}_SOURCE_DIR} ${${TRIBITS_PACKAGE}_BINARY_DIR})
add_subdirectory(${${TRIBITS_PACKAGE}_SOURCE_DIR}
${${TRIBITS_PACKAGE}_BINARY_DIR})
else()
include("${TRIBITS_PACKAGE_CMAKELIST_FILE}")
endif()
if (NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS)
if ((NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS) AND
(NOT TARGET ${PACKAGE_NAME}::all_libs)
)
tribits_report_invalid_tribits_usage(
"ERROR: Forgot to call tribits_package_postprocess() in"
" ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
endif()

list(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}_libs)
list(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}::all_libs)
list(APPEND ${PROJECT_NAME}_LIBRARIES ${${TRIBITS_PACKAGE}_LIBRARIES})

tribits_package_config_code_stop_timer(PROCESS_THIS_PACKAGE_TIME_START_SECONDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,29 @@ else()
add_subdirectory(test)
endif()

# Generate the all_libs target
# 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
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
# Generate and install the Package1Config.cmake file for the install tree
install(EXPORT ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ target_link_libraries(Package1_package1
set_target_properties(Package1_package1 PROPERTIES
EXPORT_NAME package1)
add_library(Package1::package1 ALIAS Package1_package1)
install(
TARGETS Package1_package1
install(TARGETS Package1_package1
EXPORT ${PROJECT_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
install(
Expand Down

0 comments on commit 7930a20

Please sign in to comment.