cosmocc toolchain
cmake/cosmocc.cmake
set(CMAKE_SYSTEM_NAME Generic)
unset(CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_ASM_COMPILER "cosmocc")
set(CMAKE_C_COMPILER "cosmocc")
set(CMAKE_CXX_COMPILER "cosmoc++")
find_program(CMAKE_AR "cosmoar" REQUIRED)
find_program(CMAKE_RANLIB "cosmoranlib" REQUIRED)
set(CMAKE_USER_MAKE_RULES_OVERRIDE
"${CMAKE_CURRENT_LIST_DIR}/cosmocc-override.cmake")
cmake/cosmocc-override.cmake
set(CMAKE_ASM_OUTPUT_EXTENSION ".o")
set(CMAKE_C_OUTPUT_EXTENSION ".o")
set(CMAKE_CXX_OUTPUT_EXTENSION ".o")
main.c
#include <stdio.h>
// cosmocc adds a cosmo.h header.
#include <cosmo.h>
int main() {
printf("IsLinux()=%d\n", IsLinux());
printf("IsMetal()=%d\n", IsMetal());
printf("IsWindows()=%d\n", IsWindows());
printf("IsBsd()=%d\n", IsBsd());
printf("IsXnu()=%d\n", IsXnu());
printf("IsFreebsd()=%d\n", IsFreebsd());
printf("IsOpenbsd()=%d\n", IsOpenbsd());
printf("IsNetbsd()=%d\n", IsNetbsd());
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.30)
project(cosmocc-toolchain)
add_executable(cosmocc-toolchain main.c)
cmake --toolchain ./cmake/cosmocc.cmake -B ./build/
CMake Error at cmake/cosmocc.cmake:12 (find_program):
Could not find CMAKE_RANLIB using the following names: cosmoranlib
Call Stack (most recent call first):
/usr/local/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:146 (include)
CMakeLists.txt:3 (project)
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
cmake --build ./build/
no such file or directory
CMake Error: Generator: execution of make clean failed.
./build/cosmocc-toolchain
sh: 1: ./build/cosmocc-toolchain: not found