Skip to content

Instantly share code, notes, and snippets.

@petrhosek
Created July 14, 2023 06:26
Show Gist options
  • Save petrhosek/6c8efc0c3d8b5b07187564725fba6169 to your computer and use it in GitHub Desktop.
Save petrhosek/6c8efc0c3d8b5b07187564725fba6169 to your computer and use it in GitHub Desktop.
Using Multi-Config for Multilibs
$ cmake -G "Ninja Multi-Config" -DCMAKE_TOOLCHAIN_FILE=${HOME}/fuchsia/scripts/clang/ToolChain.cmake -C ../Cache.cmake -DCMAKE_CONFIGURATION_TYPES=rv32i\;rv32iac\;rv32im\;rv32imafc -DCMAKE_CROSS_CONFIGS=all -DCMAKE_DEFAULT_CONFIGS=all ..
set(CMAKE_C_COMPILER_TARGET "riscv32-unknown-elf" CACHE STRING "")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
set(CMAKE_C_FLAGS "--target=riscv32-unknown-elf" CACHE STRING "")
set(CMAKE_C_FLAGS_RV32I "-march=rv32i -mabi=ilp32" CACHE STRING "")
set(CMAKE_C_FLAGS_RV32IAC "-march=rv32iac -mabi=ilp32" CACHE STRING "")
set(CMAKE_C_FLAGS_RV32IM "-march=rv32im -mabi=ilp32" CACHE STRING "")
set(CMAKE_C_FLAGS_RV32IMAFC "-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
set(OUTPUT_DIRECTORIES
$<$<CONFIG:rv32i>:${CMAKE_BINARY_DIR}/lib/rv32i/ilp32>
$<$<CONFIG:rv32iac>:${CMAKE_BINARY_DIR}/lib/rv32iac/ilp32>
$<$<CONFIG:rv32im>:${CMAKE_BINARY_DIR}/lib/rv32im/ilp32>
$<$<CONFIG:rv32imafc>:${CMAKE_BINARY_DIR}/lib/rv32imafc/ilp32f>
)
string(REPLACE ";" "" OUTPUT_DIRECTORIES "${OUTPUT_DIRECTORIES}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORIES}" CACHE STRING "")
cmake_minimum_required(VERSION 3.16)
project(Foo C)
add_library(foo STATIC foo.c)
int foo() {
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment