tools/corrosion/generator/CMakeLists.txt
branchtransitional_engine
changeset 16071 14b83df1832b
parent 16070 fc5258d7ecb2
parent 16067 d903f8d2395a
equal deleted inserted replaced
16070:fc5258d7ecb2 16071:14b83df1832b
     1 message(STATUS "Building CMake Generator for Corrosion - This may take a while")
       
     2 
       
     3 set(generator_src "${CMAKE_CURRENT_BINARY_DIR}/legacy_generator_src")
       
     4 set(generator_destination "${CMAKE_CURRENT_BINARY_DIR}/legacy_generator")
       
     5 set(generator_build_quiet "")
       
     6 
       
     7 file(MAKE_DIRECTORY "${generator_src}")
       
     8 file(COPY src DESTINATION "${generator_src}")
       
     9 if(Rust_VERSION VERSION_LESS "1.56")
       
    10     message(STATUS "Corrosion Generator: Using Compatibility lock file, due to rust version less than 1.56")
       
    11     file(COPY Compat.Cargo.lock Compat.Cargo.toml DESTINATION "${generator_src}")
       
    12     file(RENAME "${generator_src}/Compat.Cargo.lock" "${generator_src}/Cargo.lock")
       
    13     file(RENAME "${generator_src}/Compat.Cargo.toml" "${generator_src}/Cargo.toml")
       
    14 else()
       
    15     file(COPY Cargo.lock Cargo.toml DESTINATION "${generator_src}")
       
    16 endif()
       
    17 
       
    18 # Using cargo install has the advantage of caching the build in the user .cargo directory,
       
    19 # so likely the rebuild will be very cheap even after deleting the build directory.
       
    20 execute_process(
       
    21         COMMAND ${CMAKE_COMMAND}
       
    22         -E env
       
    23         # If the Generator is built at configure of a project (instead of being pre-installed)
       
    24         # We don't want environment variables like `RUSTFLAGS` affecting the Generator build.
       
    25         --unset=RUSTFLAGS
       
    26         "CARGO_BUILD_RUSTC=${RUSTC_EXECUTABLE}"
       
    27         "${CARGO_EXECUTABLE}" install
       
    28         --path "."
       
    29         --root "${generator_destination}"
       
    30         --locked
       
    31         ${_CORROSION_QUIET_OUTPUT_FLAG}
       
    32         WORKING_DIRECTORY "${generator_src}"
       
    33         RESULT_VARIABLE generator_build_failed
       
    34 )
       
    35 if(generator_build_failed)
       
    36     message(FATAL_ERROR "Building CMake Generator for Corrosion - failed")
       
    37 else()
       
    38     message(STATUS "Building CMake Generator for Corrosion - done")
       
    39 endif()
       
    40 set(host_executable_suffix "")
       
    41 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
       
    42     set(host_executable_suffix ".exe")
       
    43 endif()
       
    44 
       
    45 set(_CORROSION_GENERATOR_EXE
       
    46         "${generator_destination}/bin/corrosion-generator${host_executable_suffix}"
       
    47 )
       
    48 
       
    49 add_executable(Corrosion::Generator IMPORTED GLOBAL)
       
    50 set_property(
       
    51         TARGET Corrosion::Generator
       
    52         PROPERTY IMPORTED_LOCATION "${_CORROSION_GENERATOR_EXE}")
       
    53 
       
    54 if (CORROSION_DEV_MODE)
       
    55     # If you're developing Corrosion, you want to make sure to re-configure whenever the
       
    56     # generator changes.
       
    57     file(GLOB_RECURSE _RUST_FILES CONFIGURE_DEPENDS generator/src/*.rs)
       
    58     file(GLOB _CARGO_FILES CONFIGURE_DEPENDS generator/Cargo.*)
       
    59     set_property(
       
    60             DIRECTORY APPEND
       
    61             PROPERTY CMAKE_CONFIGURE_DEPENDS
       
    62             ${_RUST_FILES} ${_CARGO_FILES})
       
    63 endif()
       
    64