tools/corrosion/test/ConfigureAndBuild.cmake
author unC0Rr
Wed, 20 Nov 2024 21:37:47 +0100
branchtransitional_engine
changeset 16067 d903f8d2395a
parent 16050 6a3dc15b78b9
permissions -rw-r--r--
- Update corrosion - Implement installation of targets imported with corrosion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     1
# CMake script to configure and build a test project
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     2
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     3
set(TEST_ARG_LIST)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     4
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     5
# Expect actual arguments to start at index 3 (cmake -P <script_name>)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     6
foreach(ARG_INDEX RANGE 3 ${CMAKE_ARGC})
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     7
    list(APPEND TEST_ARG_LIST "${CMAKE_ARGV${ARG_INDEX}}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     8
endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
     9
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    10
set(options "USE_INSTALLED_CORROSION")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    11
set(oneValueArgs
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    12
    SOURCE_DIR
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    13
    BINARY_DIR
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    14
    GENERATOR
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    15
    GENERATOR_PLATFORM
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    16
    RUST_TOOLCHAIN
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    17
    CARGO_TARGET
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    18
    C_COMPILER
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    19
    CXX_COMPILER
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    20
    C_COMPILER_TARGET
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    21
    CXX_COMPILER_TARGET
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    22
    SYSTEM_NAME
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    23
    CARGO_PROFILE
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    24
    OSX_ARCHITECTURES
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    25
    TOOLCHAIN_FILE
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    26
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    27
set(multiValueArgs "PASS_THROUGH_ARGS")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    28
cmake_parse_arguments(TEST "${options}" "${oneValueArgs}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    29
                      "${multiValueArgs}" ${TEST_ARG_LIST} )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    30
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    31
set(configure_args "")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    32
if(TEST_CARGO_TARGET)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    33
    list(APPEND configure_args "-DRust_CARGO_TARGET=${TEST_CARGO_TARGET}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    34
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    35
if(TEST_USE_INSTALLED_CORROSION)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    36
    list(APPEND configure_args "-DCORROSION_TESTS_FIND_CORROSION=ON")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    37
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    38
if(TEST_GENERATOR_PLATFORM)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    39
    list(APPEND configure_args "-A${TEST_GENERATOR_PLATFORM}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    40
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    41
if(TEST_C_COMPILER)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    42
    list(APPEND configure_args "-DCMAKE_C_COMPILER=${TEST_C_COMPILER}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    43
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    44
if(TEST_CXX_COMPILER)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    45
    list(APPEND configure_args "-DCMAKE_CXX_COMPILER=${TEST_CXX_COMPILER}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    46
endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    47
if(TEST_C_COMPILER_TARGET)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    48
    list(APPEND configure_args "-DCMAKE_C_COMPILER_TARGET=${TEST_C_COMPILER_TARGET}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    49
endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    50
if(TEST_CXX_COMPILER_TARGET)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    51
    list(APPEND configure_args "-DCMAKE_CXX_COMPILER_TARGET=${TEST_CXX_COMPILER_TARGET}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    52
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    53
if(TEST_SYSTEM_NAME)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    54
    list(APPEND configure_args "-DCMAKE_SYSTEM_NAME=${TEST_SYSTEM_NAME}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    55
endif()
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    56
if(TEST_OSX_ARCHITECTURES)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    57
    list(APPEND configure_args "-DCMAKE_OSX_ARCHITECTURES=${TEST_OSX_ARCHITECTURES}")
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    58
endif()
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    59
if(TEST_TOOLCHAIN_FILE)
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    60
    list(APPEND configure_args "-DCMAKE_TOOLCHAIN_FILE=${TEST_TOOLCHAIN_FILE}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    61
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    62
if(TEST_CARGO_PROFILE)
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    63
    list(APPEND configure_args "-DCARGO_PROFILE=${TEST_CARGO_PROFILE}")
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    64
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    65
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    66
# Remove old binary directory
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    67
file(REMOVE_RECURSE "${TEST_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    68
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    69
file(MAKE_DIRECTORY "${TEST_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    70
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    71
message(STATUS "TEST_BINARY_DIRECTORY: ${TEST_BINARY_DIR}")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    72
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    73
execute_process(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    74
    COMMAND
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    75
        "${CMAKE_COMMAND}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    76
            "-G${TEST_GENERATOR}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    77
            "-DRust_TOOLCHAIN=${TEST_RUST_TOOLCHAIN}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    78
            --log-level Debug
16067
d903f8d2395a - Update corrosion
unC0Rr
parents: 16050
diff changeset
    79
            ${configure_args}
16050
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    80
            ${TEST_PASS_THROUGH_ARGS}
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    81
            -S "${TEST_SOURCE_DIR}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    82
            -B "${TEST_BINARY_DIR}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    83
        COMMAND_ECHO STDOUT
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    84
        RESULT_VARIABLE EXIT_CODE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    85
)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    86
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    87
if (NOT "${EXIT_CODE}" EQUAL 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    88
    message(FATAL_ERROR "Configure step failed. Exit code: `${EXIT_CODE}`")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    89
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    90
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    91
if ("${TEST_GENERATOR}" STREQUAL "Ninja Multi-Config"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    92
        OR "${TEST_GENERATOR}" MATCHES "Visual Studio"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    93
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    94
    foreach(config Debug Release RelWithDebInfo)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    95
        execute_process(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    96
                COMMAND "${CMAKE_COMMAND}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    97
                    --build "${TEST_BINARY_DIR}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    98
                    --config "${config}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
    99
                COMMAND_ECHO STDOUT
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   100
                RESULT_VARIABLE EXIT_CODE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   101
        )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   102
        if (NOT "${EXIT_CODE}" EQUAL 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   103
            message(FATAL_ERROR "Build step failed for config `${config}`. "
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   104
                    "Exit code: `${EXIT_CODE}`")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   105
        endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   106
    endforeach()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   107
else()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   108
    execute_process(
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   109
            COMMAND "${CMAKE_COMMAND}" --build "${TEST_BINARY_DIR}"
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   110
            COMMAND_ECHO STDOUT
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   111
            RESULT_VARIABLE EXIT_CODE
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   112
    )
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   113
    if (NOT "${EXIT_CODE}" EQUAL 0)
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   114
        message(FATAL_ERROR "Build step failed. Exit code: `${EXIT_CODE}`")
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   115
    endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   116
endif()
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   117
6a3dc15b78b9 Add corrosion as a subdirectory, CMake fixes
unC0Rr
parents:
diff changeset
   118