diff options
| author | Martin Hořeňovský | 2021-02-20 10:29:01 +0100 |
|---|---|---|
| committer | GitHub | 2021-02-20 10:29:01 +0100 |
| commit | 1ee09404271265be46851e2fd4b8d4917293a722 (patch) | |
| tree | dd9c629650bd6934dd5a00eaa1f8e3b257ee61d7 /tests | |
| parent | c12170ff69ddc9a0a25ec2025783b815354c6d26 (diff) | |
| parent | 29050daec0fc1a1b092ac2dc711bfc40648b8976 (diff) | |
| download | catch3-1ee09404271265be46851e2fd4b8d4917293a722.tar.gz | |
Merge pull request #2177 from catchorg/devel-generating-surrogates
Add surrogate TUs option to CMake
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f8bdb3b4..1a490398 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,66 @@ include(MiscFunctions) +if (CATCH_BUILD_SURROGATES) + message(STATUS "Configuring targets for surrogate TUs") + + # If the folder does not exist before we ask for output redirect to + # a file, it won't work. + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/surrogates) + + # Creates target to generate the surrogate TU for provided header. + # Returns the path to the generated file. + function(createSurrogateFileTarget sourceHeader pathToFile) + set(pathPrefix ${PROJECT_SOURCE_DIR}/src) + + file(RELATIVE_PATH includePath ${pathPrefix} ${sourceHeader}) + + get_filename_component(basicFileName "${sourceHeader}" NAME_WE) + + set(surrogateFilePath ${CMAKE_CURRENT_BINARY_DIR}/surrogates/surrogate_${basicFileName}.cpp) + + add_custom_command( + OUTPUT ${surrogateFilePath} + COMMAND cmake -E echo "\#include <${includePath}>" > "${surrogateFilePath}" + VERBATIM + ) + + set(${pathToFile} ${surrogateFilePath} PARENT_SCOPE) + endfunction() + + # Extracts all non-helper (e.g. catch_all.hpp) headers from the + # Catch2 target, and returns them through the argument. + function(ExtractCatch2Headers OutArg) + get_target_property(targetSources Catch2 SOURCES) + foreach(Source ${targetSources}) + string(REGEX MATCH "^.*\\.hpp$" isHeader ${Source}) + string(REGEX MATCH "_all.hpp" isAllHeader ${Source}) + if(isHeader AND NOT isAllHeader) + list(APPEND AllHeaders ${Source}) + endif() + endforeach() + set(${OutArg} ${AllHeaders} PARENT_SCOPE) + endfunction() + + + ExtractCatch2Headers(mainHeaders) + + if (NOT mainHeaders) + message(FATAL_ERROR "No headers in the main target were detected. Something is broken.") + endif() + + foreach(header ${mainHeaders}) + createSurrogateFileTarget(${header} pathToGeneratedFile) + list(APPEND surrogateFiles ${pathToGeneratedFile}) + endforeach() + + + add_executable(Catch2SurrogateTarget + ${surrogateFiles} + ) + target_link_libraries(Catch2SurrogateTarget PRIVATE Catch2WithMain) + +endif(CATCH_BUILD_SURROGATES) + #### # Temporary workaround for VS toolset changes in 2017 # We need to disable <UseFullPaths> property, but CMake doesn't support it |