From 802b76140d782d1482ddbff676fee6108b1224b5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 23 Feb 2022 18:41:34 -0500 Subject: Tests: Extend RunCMake.SymlinkTrees to verify paths passed to compiler Verify that the paths to source files and include directories are passed to the compiler with the symlinks preserved. --- Tests/RunCMake/SymlinkTrees/CMakeLists.txt | 43 ++++++++++++++++++++++ Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake | 10 +++++ .../common-separate-exe-build-stdout.txt | 4 ++ .../SymlinkTrees/generic-exe-build-stdout.txt | 4 ++ 4 files changed, 61 insertions(+) create mode 100644 Tests/RunCMake/SymlinkTrees/common-separate-exe-build-stdout.txt create mode 100644 Tests/RunCMake/SymlinkTrees/generic-exe-build-stdout.txt diff --git a/Tests/RunCMake/SymlinkTrees/CMakeLists.txt b/Tests/RunCMake/SymlinkTrees/CMakeLists.txt index d090fea..e16faea 100644 --- a/Tests/RunCMake/SymlinkTrees/CMakeLists.txt +++ b/Tests/RunCMake/SymlinkTrees/CMakeLists.txt @@ -7,3 +7,46 @@ get_filename_component(real_source "${CMAKE_SOURCE_DIR}" REALPATH) get_filename_component(real_binary "${CMAKE_BINARY_DIR}" REALPATH) message(STATUS "real source: '${real_source}'") message(STATUS "real binary: '${real_binary}'") + +if(RunCMake_TEST MATCHES "-exe") + enable_language(C) + file(WRITE "${CMAKE_SOURCE_DIR}/source.c" [[ + #include + #include "source.h" + #include "binary.h" + extern void print_binary_c(void); + extern void print_binary_c(void); + void print_source_c(void) { + printf("source.c: '%s'\n", __FILE__); + } + int main(void) { + print_source_c(); + print_source_h(); + print_binary_c(); + print_binary_h(); + return 0; + } + ]]) + file(WRITE "${CMAKE_BINARY_DIR}/binary.c" [[ + #include + void print_binary_c(void) { + printf("binary.c: '%s'\n", __FILE__); + } + ]]) + file(WRITE "${CMAKE_SOURCE_DIR}/include/source.h" [[ + void print_source_h(void) { + printf("source.h: '%s'\n", __FILE__); + } + ]]) + file(WRITE "${CMAKE_BINARY_DIR}/include/binary.h" [[ + void print_binary_h(void) { + printf("binary.h: '%s'\n", __FILE__); + } + ]]) + add_executable(exe source.c ${CMAKE_BINARY_DIR}/binary.c) + target_include_directories(exe PRIVATE + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/include + ) + add_custom_target(print ALL COMMAND exe) +endif() diff --git a/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake b/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake index 02989ab..72676d2 100644 --- a/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake +++ b/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake @@ -74,6 +74,16 @@ function (run_symlink_test case src bin src_from_bin bin_from_src) # Pass relative paths to the source and binary trees. set(RunCMake_TEST_VARIANT_DESCRIPTION " -S ../${name}/${src} -B ../${name}/${bin}") run_symlink_test_case("${case}" -S "../${name}/${src}" -B "../${name}/${bin}") + + # Verify paths passed to compiler. + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + run_symlink_test_case("${case}-exe" -S "${src}" -B "${bin}") + if (RunCMake_GENERATOR MATCHES "Xcode") + # The native build system may pass the real paths. + set(RunCMake-stdout-file "generic-exe-build-stdout.txt") + endif() + set(RunCMake_TEST_OUTPUT_MERGE 1) + run_cmake_command("${case}-exe-build" ${CMAKE_COMMAND} --build "${bin}") endfunction () # Create the following structure: diff --git a/Tests/RunCMake/SymlinkTrees/common-separate-exe-build-stdout.txt b/Tests/RunCMake/SymlinkTrees/common-separate-exe-build-stdout.txt new file mode 100644 index 0000000..7f73af2 --- /dev/null +++ b/Tests/RunCMake/SymlinkTrees/common-separate-exe-build-stdout.txt @@ -0,0 +1,4 @@ +source.c: '[^']*/Tests/RunCMake/SymlinkTrees/common/source/source.c' +source.h: '[^']*/Tests/RunCMake/SymlinkTrees/common/source/include/source.h' +binary.c: '[^']*/Tests/RunCMake/SymlinkTrees/common/binary/binary.c' +binary.h: '[^']*/Tests/RunCMake/SymlinkTrees/common/binary/include/binary.h' diff --git a/Tests/RunCMake/SymlinkTrees/generic-exe-build-stdout.txt b/Tests/RunCMake/SymlinkTrees/generic-exe-build-stdout.txt new file mode 100644 index 0000000..db2173c --- /dev/null +++ b/Tests/RunCMake/SymlinkTrees/generic-exe-build-stdout.txt @@ -0,0 +1,4 @@ +source.c: '[^']*/Tests/RunCMake/SymlinkTrees/[^']*/source.c' +source.h: '[^']*/Tests/RunCMake/SymlinkTrees/[^']*/include/source.h' +binary.c: '[^']*/Tests/RunCMake/SymlinkTrees/[^']*/binary.c' +binary.h: '[^']*/Tests/RunCMake/SymlinkTrees/[^']*/include/binary.h' -- cgit v0.12