|
| 1 | +cmake_minimum_required(VERSION 3.22) |
| 2 | +project(cesium VERSION 0.1.0 LANGUAGES C CXX) |
| 3 | + |
| 4 | +# Set C standard to C17 |
| 5 | +set(CMAKE_C_STANDARD 17) |
| 6 | +set(CMAKE_C_STANDARD_REQUIRED ON) |
| 7 | + |
| 8 | +# Set C++ standard to latest fully supported by Clang++ (C++20) |
| 9 | +set(CMAKE_CXX_STANDARD 20) |
| 10 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 11 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 12 | + |
| 13 | +# Set default build type to Release if not specified |
| 14 | +if(NOT CMAKE_BUILD_TYPE) |
| 15 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) |
| 16 | + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
| 17 | +endif() |
| 18 | + |
| 19 | +# include(FetchContent) |
| 20 | +# set(FETCHCONTENT_QUIET FALSE CACHE BOOL "Suppress output from FetchContent" FORCE) |
| 21 | + |
| 22 | +# Define the executable with modular source files |
| 23 | +add_executable(cesium src/main.cpp) |
| 24 | + |
| 25 | +# Compiler warnings (all platforms) |
| 26 | +target_compile_options(cesium PRIVATE -Wall -Wextra -Wpedantic) |
| 27 | + |
| 28 | +# Platform-specific settings |
| 29 | +if(WIN32) |
| 30 | + target_compile_definitions(cesium PRIVATE |
| 31 | + _WIN32_WINNT=0x0601 |
| 32 | + WIN32_LEAN_AND_MEAN |
| 33 | + ) |
| 34 | + # no gui |
| 35 | + set_target_properties(cesium PROPERTIES WIN32_EXECUTABLE FALSE) |
| 36 | + # Force console subsystem for MSVC or MinGW, but not for Clang/lld-link |
| 37 | + if(MSVC OR MINGW) |
| 38 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,console") |
| 39 | + endif() |
| 40 | + # Optionally add Windows-specific libraries here if needed |
| 41 | +elseif(APPLE) |
| 42 | + # macOS-specific settings (if any) |
| 43 | +elseif(UNIX) |
| 44 | + # Linux-specific settings (if any) |
| 45 | +endif() |
| 46 | + |
| 47 | +# Clang-specific flags |
| 48 | +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 49 | + target_compile_options(cesium PRIVATE -Wno-unused-parameter) |
| 50 | +endif() |
| 51 | + |
| 52 | +# Set output directory for all platforms |
| 53 | +set_target_properties(cesium PROPERTIES |
| 54 | + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin |
| 55 | +) |
| 56 | + |
| 57 | +# Installation rules |
| 58 | +install(TARGETS cesium RUNTIME DESTINATION bin) |
| 59 | + |
| 60 | +include(CTest) |
| 61 | +enable_testing() |
| 62 | + |
| 63 | +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) |
| 64 | +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) |
| 65 | +include(CPack) |
0 commit comments