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.
This commit is contained in:
Brad King
2022-02-23 18:41:34 -05:00
parent b0ac0fbe0e
commit 802b76140d
4 changed files with 61 additions and 0 deletions
@@ -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 <stdio.h>
#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 <stdio.h>
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()
@@ -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:
@@ -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'
@@ -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'