forked from stpaine/FERS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
154 lines (129 loc) · 5.4 KB
/
CMakeLists.txt
File metadata and controls
154 lines (129 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.22)
set(FERS_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/version.txt")
if (NOT EXISTS "${FERS_VERSION_FILE}")
message(FATAL_ERROR "Missing version file: ${FERS_VERSION_FILE}")
endif ()
file(READ "${FERS_VERSION_FILE}" FERS_PROJECT_VERSION)
string(STRIP "${FERS_PROJECT_VERSION}" FERS_PROJECT_VERSION)
if (NOT FERS_PROJECT_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
message(FATAL_ERROR "Invalid FERS version '${FERS_PROJECT_VERSION}' in ${FERS_VERSION_FILE}")
endif ()
# --- Enforce macOS Deployment Target ---
if (APPLE)
if (NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0" CACHE STRING "Minimum macOS version")
endif ()
# Ensure vcpkg also respects this deployment target
set(VCPKG_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET} CACHE STRING "")
endif ()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# --- Options and Build Type ---
include(FersOptions)
if (NOT FERS_DOCS_ONLY)
# Auto-detect vcpkg toolchain before project() so dependency resolution works in CLion and CLI.
# Note: when building via `cargo build` (the Tauri path), CMAKE_TOOLCHAIN_FILE is always passed
# explicitly by build.rs, so this block is effectively dead in that path. It is retained here
# for developers who invoke CMake directly (e.g. cmake --preset=release from the repo root).
if (NOT DEFINED VCPKG_TARGET_TRIPLET)
if (DEFINED ENV{VCPKG_TARGET_TRIPLET})
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_TARGET_TRIPLET}" CACHE STRING "vcpkg target triplet")
elseif (CMAKE_HOST_WIN32)
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(ARM64|AARCH64|aarch64)")
set(VCPKG_TARGET_TRIPLET "arm64-windows-static-md" CACHE STRING "vcpkg target triplet")
else ()
set(VCPKG_TARGET_TRIPLET "x64-windows-static-md" CACHE STRING "vcpkg target triplet")
endif ()
endif ()
endif ()
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(_fers_vcpkg_candidates)
if (DEFINED ENV{VCPKG_ROOT})
list(APPEND _fers_vcpkg_candidates "$ENV{VCPKG_ROOT}")
endif ()
if (DEFINED ENV{HOME})
list(APPEND _fers_vcpkg_candidates "$ENV{HOME}/vcpkg")
endif ()
if (DEFINED ENV{USERPROFILE})
list(APPEND _fers_vcpkg_candidates "$ENV{USERPROFILE}/vcpkg")
endif ()
list(APPEND _fers_vcpkg_candidates "${CMAKE_SOURCE_DIR}/vcpkg")
find_program(_fers_vcpkg_exe NAMES vcpkg)
if (_fers_vcpkg_exe)
cmake_path(GET _fers_vcpkg_exe PARENT_PATH _fers_vcpkg_bin_dir)
cmake_path(GET _fers_vcpkg_bin_dir PARENT_PATH _fers_vcpkg_root_from_path)
list(APPEND _fers_vcpkg_candidates "${_fers_vcpkg_root_from_path}")
endif ()
list(REMOVE_DUPLICATES _fers_vcpkg_candidates)
foreach (_fers_vcpkg_root IN LISTS _fers_vcpkg_candidates)
set(_fers_vcpkg_toolchain "${_fers_vcpkg_root}/scripts/buildsystems/vcpkg.cmake")
if (EXISTS "${_fers_vcpkg_toolchain}")
set(CMAKE_TOOLCHAIN_FILE "${_fers_vcpkg_toolchain}" CACHE FILEPATH "vcpkg toolchain")
message(STATUS "Using vcpkg toolchain: ${CMAKE_TOOLCHAIN_FILE}")
break()
endif ()
endforeach ()
unset(_fers_vcpkg_candidates)
unset(_fers_vcpkg_exe)
unset(_fers_vcpkg_bin_dir)
unset(_fers_vcpkg_root_from_path)
unset(_fers_vcpkg_root)
unset(_fers_vcpkg_toolchain)
endif ()
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
message(FATAL_ERROR
"Could not locate vcpkg toolchain file. Set VCPKG_ROOT or CMAKE_TOOLCHAIN_FILE before configuring.")
endif ()
endif ()
project(FERS
VERSION ${FERS_PROJECT_VERSION}
DESCRIPTION "The Flexible Extensible Radar Simulator"
LANGUAGES CXX)
if (NOT FERS_DOCS_ONLY)
if (WIN32 AND (MINGW OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
message(FATAL_ERROR
"Unsupported Windows toolchain detected: MinGW/GCC.\n"
"FERS requires native MSVC on Windows. Run CMake from the Visual Studio "
"Developer PowerShell with the x64 MSVC toolchain active, delete the "
"existing build directory so CMake can forget the cached compiler, then "
"configure again.\n"
"Detected compiler: ${CMAKE_CXX_COMPILER}")
endif ()
# --- Project-wide Settings ---
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS simplifies DLL exports on Windows.
# macOS and Linux do not need this but it is harmless there.
# Windows is not a currently supported target but this flag is kept to ease
# a future port.
if (WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()
# --- Compiler Warnings and Flags ---
include(FersCompilerWarnings)
# --- Testing ---
if (FERS_BUILD_TESTS)
enable_testing()
endif ()
if (FERS_ENABLE_COVERAGE)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
message(STATUS "Enabling Code Coverage")
add_compile_options(-fprofile-arcs -ftest-coverage -fprofile-update=atomic)
add_link_options(--coverage)
else ()
message(WARNING "Code coverage is only supported for GCC and Clang")
endif ()
endif ()
# --- macOS Specific Configuration ---
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "macOS with a modern toolchain (e.g., Homebrew LLVM) is recommended.")
message(STATUS "If you are not using the system compiler, please configure with:")
message(STATUS " CC=/path/to/clang CXX=/path/to/clang++ cmake ..")
endif ()
# Add the subdirectory containing the C++ packages.
add_subdirectory(packages)
endif ()
# --- Documentation ---
add_subdirectory(docs)