From afe12e377605b60edb18ace4f4912bdae4f1f45b Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sat, 14 Oct 2023 12:48:23 +0200 Subject: [PATCH] tests: pass through more options Using a list makes passing multiple named args slightly nicer. Could investigate using a macro here too, to reduce some code duplication. Pass more options like the toolchain file, so that the tests get the necessary options for cross-compiling. --- test/CMakeLists.txt | 27 ++++++++++++------- test/ConfigureAndBuild.cmake | 39 ++++++++++++++++++---------- test/output directory/CMakeLists.txt | 23 +++++++++++----- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cd782c73..37d50585 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -87,18 +87,30 @@ function(corrosion_tests_add_test test_name bin_names) set(test_dir "${test_name}") endif() - + set(configure_cmake_args) if(CMAKE_C_COMPILER) - set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") + list(APPEND configure_cmake_args "C_COMPILER" "${CMAKE_C_COMPILER}") endif() if(CMAKE_CXX_COMPILER) - set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") + list(APPEND configure_cmake_args "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") + endif() + if(CMAKE_C_COMPILER_TARGET) + list(APPEND configure_cmake_args "C_COMPILER_TARGET" "${CMAKE_C_COMPILER_TARGET}") + endif() + if(CMAKE_CXX_COMPILER_TARGET) + list(APPEND configure_cmake_args "CXX_COMPILER_TARGET" "${CMAKE_CXX_COMPILER_TARGET}") endif() if(CMAKE_GENERATOR_PLATFORM) - set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") + list(APPEND configure_cmake_args "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") endif() if(CMAKE_CROSSCOMPILING) - set(TEST_SYSTEM_NAME SYSTEM_NAME "${CMAKE_SYSTEM_NAME}") + list(APPEND configure_cmake_args SYSTEM_NAME "${CMAKE_SYSTEM_NAME}") + endif() + if(CMAKE_OSX_ARCHITECTURES) + list(APPEND configure_cmake_args OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + endif() + if(CMAKE_TOOLCHAIN_FILE) + list(APPEND configure_cmake_args TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}") endif() add_test(NAME "${test_name}_build" @@ -110,10 +122,7 @@ function(corrosion_tests_add_test test_name bin_names) GENERATOR "${CMAKE_GENERATOR}" RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" CARGO_TARGET "${Rust_CARGO_TARGET}" - "${TEST_SYSTEM_NAME}" - "${TEST_C_COMPILER}" - "${TEST_CXX_COMPILER}" - "${TEST_GENERATOR_PLATFORM}" + ${configure_cmake_args} ${pass_through_arguments} COMMAND_EXPAND_LISTS diff --git a/test/ConfigureAndBuild.cmake b/test/ConfigureAndBuild.cmake index fbf40cb1..c3017074 100644 --- a/test/ConfigureAndBuild.cmake +++ b/test/ConfigureAndBuild.cmake @@ -17,33 +17,50 @@ set(oneValueArgs CARGO_TARGET C_COMPILER CXX_COMPILER + C_COMPILER_TARGET + CXX_COMPILER_TARGET SYSTEM_NAME CARGO_PROFILE + OSX_ARCHITECTURES + TOOLCHAIN_FILE ) set(multiValueArgs "PASS_THROUGH_ARGS") cmake_parse_arguments(TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${TEST_ARG_LIST} ) +set(configure_args "") if(TEST_CARGO_TARGET) - set(TEST_Rust_CARGO_TARGET "-DRust_CARGO_TARGET=${TEST_CARGO_TARGET}") + list(APPEND configure_args "-DRust_CARGO_TARGET=${TEST_CARGO_TARGET}") endif() if(TEST_USE_INSTALLED_CORROSION) - set(TEST_CORROSION_INSTALL "-DCORROSION_TESTS_FIND_CORROSION=ON") + list(APPEND configure_args "-DCORROSION_TESTS_FIND_CORROSION=ON") endif() if(TEST_GENERATOR_PLATFORM) - set(TEST_GENERATOR_PLATFORM "-A${TEST_GENERATOR_PLATFORM}") + list(APPEND configure_args "-A${TEST_GENERATOR_PLATFORM}") endif() if(TEST_C_COMPILER) - set(TEST_C_COMPILER "-DCMAKE_C_COMPILER=${TEST_C_COMPILER}") + list(APPEND configure_args "-DCMAKE_C_COMPILER=${TEST_C_COMPILER}") endif() if(TEST_CXX_COMPILER) - set(TEST_CXX_COMPILER "-DCMAKE_CXX_COMPILER=${TEST_CXX_COMPILER}") + list(APPEND configure_args "-DCMAKE_CXX_COMPILER=${TEST_CXX_COMPILER}") +endif() +if(TEST_C_COMPILER_TARGET) + list(APPEND configure_args "-DCMAKE_C_COMPILER_TARGET=${TEST_C_COMPILER_TARGET}") +endif() +if(TEST_CXX_COMPILER_TARGET) + list(APPEND configure_args "-DCMAKE_CXX_COMPILER_TARGET=${TEST_CXX_COMPILER_TARGET}") endif() if(TEST_SYSTEM_NAME) - set(TEST_SYSTEM_NAME "-DCMAKE_SYSTEM_NAME=${TEST_SYSTEM_NAME}") + list(APPEND configure_args "-DCMAKE_SYSTEM_NAME=${TEST_SYSTEM_NAME}") +endif() +if(TEST_OSX_ARCHITECTURES) + list(APPEND configure_args "-DCMAKE_OSX_ARCHITECTURES=${TEST_OSX_ARCHITECTURES}") +endif() +if(TEST_TOOLCHAIN_FILE) + list(APPEND configure_args "-DCMAKE_TOOLCHAIN_FILE=${TEST_TOOLCHAIN_FILE}") endif() if(TEST_CARGO_PROFILE) - set(TEST_CARGO_PROFILE "-DCARGO_PROFILE=${TEST_CARGO_PROFILE}") + list(APPEND configure_args "-DCARGO_PROFILE=${TEST_CARGO_PROFILE}") endif() # Remove old binary directory @@ -59,13 +76,7 @@ execute_process( "-G${TEST_GENERATOR}" "-DRust_TOOLCHAIN=${TEST_RUST_TOOLCHAIN}" --log-level Debug - ${TEST_Rust_CARGO_TARGET} - ${TEST_CORROSION_INSTALL} - ${TEST_GENERATOR_PLATFORM} - ${TEST_C_COMPILER} - ${TEST_CXX_COMPILER} - ${TEST_SYSTEM_NAME} - ${TEST_CARGO_PROFILE} + ${configure_args} ${TEST_PASS_THROUGH_ARGS} -S "${TEST_SOURCE_DIR}" -B "${TEST_BINARY_DIR}" diff --git a/test/output directory/CMakeLists.txt b/test/output directory/CMakeLists.txt index 357a4dd9..b3961118 100644 --- a/test/output directory/CMakeLists.txt +++ b/test/output directory/CMakeLists.txt @@ -1,11 +1,24 @@ +set(configure_cmake_args) if(CMAKE_C_COMPILER) - set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") + list(APPEND configure_cmake_args "C_COMPILER" "${CMAKE_C_COMPILER}") endif() if(CMAKE_CXX_COMPILER) - set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") + list(APPEND configure_cmake_args "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") +endif() +if(CMAKE_C_COMPILER_TARGET) + list(APPEND configure_cmake_args "C_COMPILER_TARGET" "${CMAKE_C_COMPILER_TARGET}") +endif() +if(CMAKE_CXX_COMPILER_TARGET) + list(APPEND configure_cmake_args "CXX_COMPILER_TARGET" "${CMAKE_CXX_COMPILER_TARGET}") endif() if(CMAKE_GENERATOR_PLATFORM) - set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") + list(APPEND configure_cmake_args "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") +endif() +if(CMAKE_OSX_ARCHITECTURES) + list(APPEND configure_cmake_args OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") +endif() +if(CMAKE_TOOLCHAIN_FILE) + list(APPEND configure_cmake_args TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}") endif() add_test(NAME "output_directory_build" @@ -18,9 +31,7 @@ add_test(NAME "output_directory_build" RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" CARGO_TARGET "${Rust_CARGO_TARGET}" SYSTEM_NAME "${CMAKE_SYSTEM_NAME}" - "${TEST_C_COMPILER}" - "${TEST_CXX_COMPILER}" - "${TEST_GENERATOR_PLATFORM}" + ${configure_cmake_args} COMMAND_EXPAND_LISTS )