Skip to content

Commit

Permalink
tests: pass through more options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jschwe committed Oct 14, 2023
1 parent 697150f commit afe12e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
27 changes: 18 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
39 changes: 25 additions & 14 deletions test/ConfigureAndBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand Down
23 changes: 17 additions & 6 deletions test/output directory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
)
Expand Down

0 comments on commit afe12e3

Please sign in to comment.