# SPDX-FileCopyrightText: Matteo Settenvini # SPDX-License-Identifier: EUPL-1.2 include_guard(GLOBAL) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message( FATAL_ERROR " In-tree build is not supported. Please use a dedicated build directory. Note: Some dirty files might be in your repo. Remove them before you commit! " ) else() # auto-exclude build folder from commits file(WRITE "${CMAKE_BINARY_DIR}/.gitignore" "*") endif() function(get_project_version OUTPUT_VAR MANIFEST_DIR) find_program(CARGO NAMES cargo REQUIRED) execute_process(COMMAND ${CARGO} metadata --no-deps --format-version 1 OUTPUT_VARIABLE cargo_manifest WORKING_DIRECTORY ${MANIFEST_DIR}) string(JSON version GET "${cargo_manifest}" packages 0 version) set(${OUTPUT_VAR} "${version}" PARENT_SCOPE) endfunction(get_project_version) function(setup_crates DIR) if(CMAKE_BUILD_TYPE MATCHES "^(Release|RelWithDebInfo)$") set(cargo_profile "release") elseif(CMAKE_BUILD_TYPE MATCHES "^(Debug)$") set(cargo_profile "dev") else() message(WARNING "Proper support for ${CMAKE_BUILD_TYPE} not implemented yet.") endif() corrosion_import_crate(MANIFEST_PATH ${DIR}/Cargo.toml PROFILE ${cargo_profile} LOCKED) endfunction(setup_crates) function(ensure_rust_utils) foreach(util IN LISTS ARGV) ensure_rust_util(${util}) endforeach() endfunction(ensure_rust_utils) function(ensure_rust_util UTIL) find_program(${UTIL} NAMES ${UTIL}) if(NOT ${UTIL}) set(out_dir ${CMAKE_BINARY_DIR}/CMakeFiles) message(STATUS "Utility ${UTIL} not found, will be compiled to ${out_dir}") add_custom_command(OUTPUT ${out_dir}/bin/${UTIL} COMMAND cargo install --root ${out_dir} --locked ${UTIL} COMMENT "Installing build utility '${UTIL}' from the cargo registry" VERBATIM) set(${UTIL} ${out_dir}/bin/${UTIL} CACHE INTERNAL "location of the ${UTIL} binary (compiled at build time)") endif() endfunction(ensure_rust_util) function(print_summary) message(STATUS " =========================================================== Finished configuring: ${PROJECT_NAME}, ${PROJECT_VERSION} CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR} CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR} CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} CMAKE_GENERATOR: ${CMAKE_GENERATOR} CMAKE_CROSSCOMPILING: ${CMAKE_CROSSCOMPILING} CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE} CMAKE_SYSROOT: ${CMAKE_SYSROOT} CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH} Rust_VERSION: ${Rust_VERSION} Options: - BUILD_DOCUMENTATION: ${BUILD_DOCUMENTATION} - BUILD_TESTING: ${BUILD_TESTING} =========================================================== ") endfunction(print_summary)