Skip to content

Commit

Permalink
Finish basic implentation for building against external packages (#63)
Browse files Browse the repository at this point in the history
This demonstates the basic use case building and installing an internal
package and then building the reaming packages against it as an external
package.

This adds a first test to get TribitsExampleProject to build against external
SimpleCxx.

Just a few things had to be tweaked to get this to work:

* Set <Package>_FINDMOD to "TRIBITS_PKG": There was existing, no-tested logic
  in TriBITS added a long time ago to treat pre-installed TriBITS packages as
  TPLs. Therefore, I just needed to set <Package>_FINDMOD to "TRIBITS_PKG" for
  internal packages being treated as external packages and that was it!

* Cleaned up the existing code to call find_package(${TPL_NAME}).  (This code
  will be refactored to clean it up some.)

* Aggregated logic for expected output from TribitsExampeProject tests into a
  single file ExpectedDepsStrings.cmake so that it works even when a package's
  CMakeLists.txt file is not processed (because it is being treated as
  external).
  • Loading branch information
bartlettroscoe committed Jan 24, 2023
1 parent 5403385 commit 7ad12ad
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 33 deletions.
103 changes: 103 additions & 0 deletions test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3209,3 +3209,106 @@ if (TribitsExampleProject_extra_link_flags_NAME)
set_tests_properties(${TribitsExampleProject_extra_link_flags_NAME}
PROPERTIES DEPENDS ${SimpleTpl_install_STATIC_NAME} )
endif()


###################################################################################




tribits_add_advanced_test( TribitsExampleProject_SimpleCxx_External
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1

TEST_0
MESSAGE "Copy TribitsExampleProject so we can change it"
CMND cp
ARGS -r ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .
# CMND ln
# ARGS -s ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .

TEST_1
MESSAGE "Configure to just build and install just SimpleCxx"
CMND ${CMAKE_COMMAND}
WORKING_DIRECTORY Build_SimpleCxx
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj_ENABLE_SimpleCxx=ON
-DCMAKE_INSTALL_PREFIX=../install/simple_cxx
# ToDo: Add option to stop install of TribitsExProjConfig.cmake ...
-DTPL_ENABLE_MPI=OFF
-DTPL_ENABLE_SimpleTpl=ON
-DSimpleTpl_INCLUDE_DIRS=${SimpleTpl_install_STATIC_DIR}/install/include
-DSimpleTpl_LIBRARY_DIRS=${SimpleTpl_install_STATIC_DIR}/install/lib
../TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Configuring done"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_2
MESSAGE "Build just SimpleCxx"
CMND make ARGS ${CTEST_BUILD_FLAGS}
WORKING_DIRECTORY Build_SimpleCxx
SKIP_CLEAN_WORKING_DIRECTORY

TEST_3
MESSAGE "Install just SimpleCxx"
CMND make ARGS ${CTEST_BUILD_FLAGS} install
WORKING_DIRECTORY Build_SimpleCxx
SKIP_CLEAN_WORKING_DIRECTORY

# ToDo: Remove build dir Build_SimpleCxx

# ToDo: Remove the source tree for simple_cxx so it can't be built!

TEST_4
MESSAGE "Configure rest of TribitsExampleProject against pre-installed SimpleCxx"
CMND ${CMAKE_COMMAND}
WORKING_DIRECTORY Build
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj_ENABLE_ALL_PACKAGES=ON
-DTribitsExProj_ENABLE_TESTS=ON
#-DTribitsExProj_ENABLE_INSTALL_CMAKE_CONFIG_FILES=OFF # Allow WrapExternal enable
-DTPL_ENABLE_SimpleCxx=ON
-DCMAKE_PREFIX_PATH=../install/simple_cxx
-DTPL_ENABLE_MPI=OFF
-DTPL_ENABLE_SimpleTpl=ON
-DSimpleTpl_INCLUDE_DIRS=${SimpleTpl_install_STATIC_DIR}/install/include
-DSimpleTpl_LIBRARY_DIRS=${SimpleTpl_install_STATIC_DIR}/install/lib
# ToDo: Remove how to find SimpleTpl because SimpleCxx should already
# have that found and we should just use what it found!
../TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Configuring done"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_5
MESSAGE "Build TribitsExampleProject"
CMND make ARGS ${CTEST_BUILD_FLAGS}
WORKING_DIRECTORY Build
SKIP_CLEAN_WORKING_DIRECTORY

TEST_6
MESSAGE "Run all the tests with ctest"
WORKING_DIRECTORY Build
SKIP_CLEAN_WORKING_DIRECTORY
CMND ${CMAKE_CTEST_COMMAND}
PASS_REGULAR_EXPRESSION_ALL
"100% tests passed, 0 tests failed out of 7"
ALWAYS_FAIL_ON_NONZERO_RETURN

ADDED_TEST_NAME_OUT TribitsExampleProject_SimpleCxx_External_NAME
)


if (TribitsExampleProject_SimpleCxx_External_NAME)
set_tests_properties(${TribitsExampleProject_SimpleCxx_External_NAME}
PROPERTIES DEPENDS ${SimpleTpl_install_STATIC_NAME} )
endif()


3 changes: 2 additions & 1 deletion tribits/core/package_arch/TribitsAdjustPackageEnables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,8 @@ macro(tribits_set_internal_package_to_external packageName)
"Treating internal package ${packageName} as EXTERNAL because"
" " ${ARGN})
endif()
set(${packageName}_PACKAGE_BUILD_STATUS EXTERNAL)
set(${packageName}_PACKAGE_BUILD_STATUS EXTERNAL)
set(${packageName}_FINDMOD TRIBITS_PKG)
endmacro()


Expand Down
3 changes: 1 addition & 2 deletions tribits/core/package_arch/TribitsProcessEnabledTpl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ function(tribits_process_enabled_tpl TPL_NAME)
print_var(${TPL_NAME}_FINDMOD)
endif()
if (${TPL_NAME}_FINDMOD STREQUAL "TRIBITS_PKG")
message("Calling find_package(${TPL_NAME}) for TriBITS-compatible package ...")
set(TPL_${TPL_NAME}_PARTS_ALREADY_SET FALSE) # ToDo: Take out?
if (NOT TPL_${TPL_NAME}_PARTS_ALREADY_SET)
find_package(${TPL_NAME} CONFIG REQUIRED)
global_set(TPL_${TPL_NAME}_LIBRARIES
"${${TPL_NAME}_LIBRARIES}" "${${TPL_NAME}_TPL_LIBRARIES}")
global_set(TPL_${TPL_NAME}_PARTS_ALREADY_SET TRUE)
endif()
return()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file contains logic for the expected dependencies for each package and
# TPLs used in TribitsExampleProject. This logic is contained here instead of
# in the packages's CMakeLists.txt files in case some of these are pulled in
# as external packages and that package's CMakeLists.txt files are not
# actually processed.

tribits_get_package_enable_status(SimpleCxx SimpleCxx_enabled "")
print_var(SimpleCxx_enabled)
print_var(SimpleCxx_ENABLE_SimpleTpl)
if (SimpleCxx_enabled)
if (SimpleCxx_ENABLE_SimpleTpl)
set(simpletplText "simpletpl ")
else()
set(simpletplText)
endif()
set(EXPECTED_SIMPLECXX_AND_DEPS
"SimpleCxx ${simpletplText}headeronlytpl")
endif()
print_var(EXPECTED_SIMPLECXX_AND_DEPS)

tribits_get_package_enable_status(InsertedPkg InsertedPkg_enabled "")
if (InsertedPkg_enabled)
set(EXPECTED_INSERTEDPKG_AND_DEPS "InsertedPkg ${EXPECTED_SIMPLECXX_AND_DEPS}")
set(EXPECTED_INSERTEDPKG_AND_DEPS_STR "${EXPECTED_INSERTEDPKG_AND_DEPS} ")
else()
set(EXPECTED_INSERTEDPKG_DEPS "")
set(EXPECTED_INSERTEDPKG_DEPS_STR "")
endif()
print_var(EXPECTED_INSERTEDPKG_DEPS)
print_var(EXPECTED_INSERTEDPKG_DEPS_STR)

tribits_get_package_enable_status(WithSubpackagesA WithSubpackagesA_enabled "")
if (WithSubpackagesA_enabled)
set(EXPECTED_A_AND_DEPS "A ${EXPECTED_SIMPLECXX_AND_DEPS}")
set(EXPECTED_A_AND_DEPS_STR "${EXPECTED_A_AND_DEPS} ")
else()
set(EXPECTED_A_AND_DEPS "")
set(EXPECTED_A_AND_DEPS_STR "")
endif()
print_var(EXPECTED_A_AND_DEPS)
print_var(EXPECTED_A_AND_DEPS_STR)

tribits_get_package_enable_status(WithSubpackagesB WithSubpackagesB_enabled "")
if (WithSubpackagesB_enabled)
set(EXPECTED_B_DEPS
"${EXPECTED_A_AND_DEPS_STR}${EXPECTED_INSERTEDPKG_AND_DEPS_STR}${EXPECTED_SIMPLECXX_AND_DEPS}")
endif()
print_var(EXPECTED_B_DEPS)
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ tribits_add_show_deprecated_warnings_option()
add_subdirectory(src)
tribits_add_test_directories(test)

# 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")
include("${PROJECT_SOURCE_DIR}/cmake/ExpectedDepsStrings.cmake")

#
# E) Do standard post processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,7 @@ 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}")
include("${PROJECT_SOURCE_DIR}/cmake/ExpectedDepsStrings.cmake")

tribits_add_test_directories(tests)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ tribits_add_library(pws_c
${TAL_EXTRALIB_ARGS} # Used to show warnings and errors
)

include("${PROJECT_SOURCE_DIR}/cmake/ExpectedDepsStrings.cmake")

tribits_add_test_directories(tests)

tribits_subpackage_postprocess()

0 comments on commit 7ad12ad

Please sign in to comment.