tools/corrosion/test/ConfigureAndBuild.cmake
branchtransitional_engine
changeset 16021 6a3dc15b78b9
child 16038 d903f8d2395a
equal deleted inserted replaced
16009:7544a7d7c819 16021:6a3dc15b78b9
       
     1 # CMake script to configure and build a test project
       
     2 
       
     3 set(TEST_ARG_LIST)
       
     4 
       
     5 # Expect actual arguments to start at index 3 (cmake -P <script_name>)
       
     6 foreach(ARG_INDEX RANGE 3 ${CMAKE_ARGC})
       
     7     list(APPEND TEST_ARG_LIST "${CMAKE_ARGV${ARG_INDEX}}")
       
     8 endforeach()
       
     9 
       
    10 set(options "USE_INSTALLED_CORROSION")
       
    11 set(oneValueArgs
       
    12     SOURCE_DIR
       
    13     BINARY_DIR
       
    14     GENERATOR
       
    15     GENERATOR_PLATFORM
       
    16     RUST_TOOLCHAIN
       
    17     CARGO_TARGET
       
    18     C_COMPILER
       
    19     CXX_COMPILER
       
    20     SYSTEM_NAME
       
    21     EXTERNAL_CORROSION_GENERATOR
       
    22     CARGO_PROFILE
       
    23 )
       
    24 set(multiValueArgs "PASS_THROUGH_ARGS")
       
    25 cmake_parse_arguments(TEST "${options}" "${oneValueArgs}"
       
    26                       "${multiValueArgs}" ${TEST_ARG_LIST} )
       
    27 
       
    28 if(TEST_CARGO_TARGET)
       
    29     set(TEST_Rust_CARGO_TARGET "-DRust_CARGO_TARGET=${TEST_CARGO_TARGET}")
       
    30 endif()
       
    31 if(TEST_USE_INSTALLED_CORROSION)
       
    32     set(TEST_CORROSION_INSTALL "-DCORROSION_TESTS_FIND_CORROSION=ON")
       
    33 endif()
       
    34 if(TEST_GENERATOR_PLATFORM)
       
    35     set(TEST_GENERATOR_PLATFORM "-A${TEST_GENERATOR_PLATFORM}")
       
    36 endif()
       
    37 if(TEST_C_COMPILER)
       
    38     set(TEST_C_COMPILER "-DCMAKE_C_COMPILER=${TEST_C_COMPILER}")
       
    39 endif()
       
    40 if(TEST_CXX_COMPILER)
       
    41     set(TEST_CXX_COMPILER "-DCMAKE_CXX_COMPILER=${TEST_CXX_COMPILER}")
       
    42 endif()
       
    43 if(TEST_SYSTEM_NAME)
       
    44     set(TEST_SYSTEM_NAME "-DCMAKE_SYSTEM_NAME=${TEST_SYSTEM_NAME}")
       
    45 endif()
       
    46 if(TEST_EXTERNAL_CORROSION_GENERATOR)
       
    47     set(TEST_EXTERNAL_CORROSION_GENERATOR
       
    48         "-DCORROSION_GENERATOR_EXECUTABLE=${TEST_EXTERNAL_CORROSION_GENERATOR}"
       
    49     )
       
    50 endif()
       
    51 if(TEST_CARGO_PROFILE)
       
    52     set(TEST_CARGO_PROFILE "-DCARGO_PROFILE=${TEST_CARGO_PROFILE}")
       
    53 endif()
       
    54 
       
    55 # Remove old binary directory
       
    56 file(REMOVE_RECURSE "${TEST_BINARY_DIR}")
       
    57 
       
    58 file(MAKE_DIRECTORY "${TEST_BINARY_DIR}")
       
    59 
       
    60 message(STATUS "TEST_BINARY_DIRECTORY: ${TEST_BINARY_DIR}")
       
    61 
       
    62 execute_process(
       
    63     COMMAND
       
    64         "${CMAKE_COMMAND}"
       
    65             "-G${TEST_GENERATOR}"
       
    66             "-DRust_TOOLCHAIN=${TEST_RUST_TOOLCHAIN}"
       
    67             --log-level Debug
       
    68             ${TEST_Rust_CARGO_TARGET}
       
    69             ${TEST_CORROSION_INSTALL}
       
    70             ${TEST_GENERATOR_PLATFORM}
       
    71             ${TEST_C_COMPILER}
       
    72             ${TEST_CXX_COMPILER}
       
    73             ${TEST_SYSTEM_NAME}
       
    74             ${TEST_EXTERNAL_CORROSION_GENERATOR}
       
    75             ${TEST_CARGO_PROFILE}
       
    76             ${TEST_PASS_THROUGH_ARGS}
       
    77             -S "${TEST_SOURCE_DIR}"
       
    78             -B "${TEST_BINARY_DIR}"
       
    79         COMMAND_ECHO STDOUT
       
    80         RESULT_VARIABLE EXIT_CODE
       
    81 )
       
    82 
       
    83 if (NOT "${EXIT_CODE}" EQUAL 0)
       
    84     message(FATAL_ERROR "Configure step failed. Exit code: `${EXIT_CODE}`")
       
    85 endif()
       
    86 
       
    87 if ("${TEST_GENERATOR}" STREQUAL "Ninja Multi-Config"
       
    88         OR "${TEST_GENERATOR}" MATCHES "Visual Studio"
       
    89     )
       
    90     foreach(config Debug Release RelWithDebInfo)
       
    91         execute_process(
       
    92                 COMMAND "${CMAKE_COMMAND}"
       
    93                     --build "${TEST_BINARY_DIR}"
       
    94                     --config "${config}"
       
    95                 COMMAND_ECHO STDOUT
       
    96                 RESULT_VARIABLE EXIT_CODE
       
    97         )
       
    98         if (NOT "${EXIT_CODE}" EQUAL 0)
       
    99             message(FATAL_ERROR "Build step failed for config `${config}`. "
       
   100                     "Exit code: `${EXIT_CODE}`")
       
   101         endif()
       
   102     endforeach()
       
   103 else()
       
   104     execute_process(
       
   105             COMMAND "${CMAKE_COMMAND}" --build "${TEST_BINARY_DIR}"
       
   106             COMMAND_ECHO STDOUT
       
   107             RESULT_VARIABLE EXIT_CODE
       
   108     )
       
   109     if (NOT "${EXIT_CODE}" EQUAL 0)
       
   110         message(FATAL_ERROR "Build step failed. Exit code: `${EXIT_CODE}`")
       
   111     endif()
       
   112 endif()
       
   113 
       
   114