Skip to content

Commit

Permalink
Make WrapExernal work with external TribitsExProj packages (#63)
Browse files Browse the repository at this point in the history
So for there is just one test for this.

To make this work, I had to grab the include directories off of the upstream
targets, which are returned as generator expressions.  And with that, I had to
switch the generation of the makefile for external_func to build time with a
custom command so it would evaluate the generator expressions.  (There is no
way to run a general command at generation time.)
  • Loading branch information
bartlettroscoe committed Jan 25, 2023
1 parent 98ad21e commit 7e85ccc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
4 changes: 2 additions & 2 deletions test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3274,7 +3274,7 @@ tribits_add_advanced_test( TribitsExampleProject_SimpleCxx_External
-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
-DTribitsExProj_ENABLE_INSTALL_CMAKE_CONFIG_FILES=OFF # Allow WrapExternal enable
-DTPL_ENABLE_SimpleCxx=ON
-DCMAKE_PREFIX_PATH=../install/simple_cxx
-DTPL_ENABLE_MPI=OFF
Expand All @@ -3300,7 +3300,7 @@ tribits_add_advanced_test( TribitsExampleProject_SimpleCxx_External
SKIP_CLEAN_WORKING_DIRECTORY
CMND ${CMAKE_CTEST_COMMAND}
PASS_REGULAR_EXPRESSION_ALL
"100% tests passed, 0 tests failed out of 7"
"100% tests passed, 0 tests failed out of 8"
ALWAYS_FAIL_ON_NONZERO_RETURN

ADDED_TEST_NAME_OUT TribitsExampleProject_SimpleCxx_External_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
# provides libraries that need to be cast as TriBITS CMake libraries. To
# make this even more interesting, the external software has dependencies on
# upstream TriBITS packages.
#
# An overview of the basic tasks required are:
#
# a) Enumerate the upstream packages and TPLs needed (this is done in the
# cmake/Dependencies.cmake file).
#
# b) Generate an export makefile for the upstream packages and TPLs
#
# c) Call the configure script for the external package passing the compilers,
# compiler flags, and a pointer to the export makefile (which is just used to
# lift the include dirs and libs).
#
# d) Define library targets for the external project and define a build rule
# for generating those libraries given the list of header and source files in
# the external project.

tribits_package(WrapExternal)

Expand Down Expand Up @@ -66,41 +51,51 @@ endif()

string(TOUPPER "${CMAKE_BUILD_TYPE}" upperBuildType)

set(includeDirsList
-I ${WithSubpackagesA_SOURCE_DIR}
-I ${SimpleCxx_SOURCE_DIR}/src
-I ${SimpleCxx_BINARY_DIR}/src
)
get_target_property(simpleCxx_IncludeDirs
SimpleCxx::simplecxx INTERFACE_INCLUDE_DIRECTORIES)

get_target_property(withSubpackagesA_IncludeDirs
WithSubpackagesA::pws_a INTERFACE_INCLUDE_DIRECTORIES)

set(includeDirsList ${withSubpackagesA_IncludeDirs} ${simpleCxx_IncludeDirs})

if (${PACKAGE_NAME}_ENABLE_MixedLang)
list(PREPEND includeDirsList
-I ${MixedLang_SOURCE_DIR}/src
-I ${MixedLang_BINARY_DIR}/src
)
get_target_property(mixedLang_IncludeDirs
MixedLang::mixedlang INTERFACE_INCLUDE_DIRECTORIES)
list(PREPEND includeDirsList ${mixedLang_IncludeDirs})
endif()
list(JOIN includeDirsList " " includeDirs)
# NOTE: TriBITS export Makefile support used to handle the above stuff
# automatically but that is what you give up when moving to modern CMake.
list(JOIN includeDirsList " -I" includeDirsCompileOptions)
set(includeDirsCompileOptions "-I${includeDirsCompileOptions}")

#
# C) Do configuration of the external project
# C) Do configuration of the external project as a build target
#

set(EXTERNAL_FUNC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_func)
set(EXTERNAL_FUNC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external_func)
set(EXTERNAL_FUNC_LIB_FILE ${EXTERNAL_FUNC_BINARY_DIR}/libexternal_func.a)
set(EXTERNAL_FUNC_MAKEFILE ${EXTERNAL_FUNC_BINARY_DIR}/Makefile)

file(MAKE_DIRECTORY ${EXTERNAL_FUNC_BINARY_DIR})

execute_process(
add_custom_command(
OUTPUT ${EXTERNAL_FUNC_MAKEFILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${EXTERNAL_FUNC_SOURCE_DIR}/configure.py
COMMAND ${PYTHON_EXECUTABLE} ${EXTERNAL_FUNC_SOURCE_DIR}/configure.py
"--cxx=${CMAKE_CXX_COMPILER}"
"--cxx-flags=${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${upperBuildType}}"
"--ar=${CMAKE_AR}"
"--include-dirs=${includeDirs}"
"--include-dirs=${includeDirsCompileOptions}"
"--src-dir=${EXTERNAL_FUNC_SOURCE_DIR}"
"--build-dir=${EXTERNAL_FUNC_BINARY_DIR}"
)

# NOTE: Above, we have to run the configure.py script at build time after
# generation because ${includeDirsCompileOptions} contains generation
# expressions that are evaluated at generation time by the
# add_custom_command() call.

#
# D) Define a custom build rule and target to create external_func library
#
Expand All @@ -109,6 +104,7 @@ add_custom_command(
OUTPUT ${EXTERNAL_FUNC_LIB_FILE}
DEPENDS ${EXTERNAL_FUNC_SOURCE_DIR}/external_func.hpp
${EXTERNAL_FUNC_SOURCE_DIR}/external_func.cpp
${EXTERNAL_FUNC_MAKEFILE}
COMMAND make ${CTEST_BUILD_FLAGS}
WORKING_DIRECTORY ${EXTERNAL_FUNC_BINARY_DIR}
)
Expand Down

0 comments on commit 7e85ccc

Please sign in to comment.