Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
185 lines (160 loc) · 8.29 KB
/
Copy pathCMakeLists.txt
File metadata and controls
185 lines (160 loc) · 8.29 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# The embedding project's CMP0155 setting (module scanning by default), read before this file's own
# cmake_minimum_required resets the policies; empty when unknown or set.
if(CMAKE_VERSION VERSION_LESS "3.31")
message(FATAL_ERROR
"WebFront requires CMake 3.31 or newer (found ${CMAKE_VERSION}). "
"See README.md#build-tools-on-lts-distributions for installation instructions.")
endif()
cmake_policy(GET CMP0155 WEBFRONT_PARENT_CMP0155)
cmake_minimum_required (VERSION 3.31)
# Top-level detection must precede project(): an embedding parent project owns global settings.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(WEBFRONT_IS_TOP_LEVEL ON)
else()
set(WEBFRONT_IS_TOP_LEVEL OFF)
endif()
option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
option(WEBFRONT_BUILD_EXAMPLES "Build the example applications" ${WEBFRONT_IS_TOP_LEVEL})
option(WEBFRONT_DISTRIBUTION "Require WebKitGTK sandboxing for distribution (development disables it by default)" OFF)
option(WEBFRONT_GZIP_DIFFERENTIAL "Build test-only gzip/zlib differential checks" OFF)
option(WEBFRONT_USE_MDDLOG "Use the compiled mddlog diagnostic adapter" OFF)
# The experimental gate must be selected before project() probes the compiler.
if(WEBFRONT_USE_MDDLOG)
include(cmake/MddlogPreProject.cmake)
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/webfront/WebFront.hpp")
set(VERSION_STRING_REGEX "inline constexpr std::string_view version = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/webfront/WebFront.hpp" VERSION_STRING REGEX ${VERSION_STRING_REGEX})
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_STRING "${VERSION_STRING}")
project(WebFront LANGUAGES CXX VERSION ${VERSION_STRING})
# After project(): a toolchain file's variables are then visible, as they were to the former option() calls.
include(cmake/WebFrontTestOptions.cmake)
webfront_declare_test_options(${WEBFRONT_IS_TOP_LEVEL})
include(cmake/Frontends.cmake)
# Applications need no -DWEBFRONT_EMBED_* option: unless the user decided, this platform's native window
# engine is enabled when its dependencies are present. Test and fuzzing builds keep explicit selection.
if(NOT WEBFRONT_ENABLE_TESTING AND NOT WEBFRONT_ENABLE_FUZZING)
set(WEBFRONT_AUTODETECT_NATIVE_DEFAULT ON)
else()
set(WEBFRONT_AUTODETECT_NATIVE_DEFAULT OFF)
endif()
option(WEBFRONT_AUTODETECT_NATIVE "Enable the native window engine of this platform when its dependencies are found" ${WEBFRONT_AUTODETECT_NATIVE_DEFAULT})
if(WEBFRONT_AUTODETECT_NATIVE)
webfront_autodetect_native_frontends()
endif()
webfront_declare_frontend_options()
# The library requires threads; consumers inherit the flag through the WebFront target.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_library(WebFront INTERFACE)
add_library(WebFront::WebFront ALIAS WebFront)
# The public test framework (WebFront::Bdd, webfront_bdd_discover_tests), which WebFront's own tests use.
include(cmake/WebFrontBddTarget.cmake)
if(WEBFRONT_DISTRIBUTION)
target_compile_definitions(WebFront INTERFACE WEBFRONT_DISTRIBUTION=1)
endif()
include(cmake/WebFrontDistribution.cmake)
if(WEBFRONT_EMBED_WEBKITGTK AND WEBFRONT_IS_TOP_LEVEL)
if(WEBFRONT_DISTRIBUTION)
message(NOTICE "WebFront WebKitGTK: DISTRIBUTION mode, sandbox required. Package the application profile; see docs/WEBKITGTK.md.")
else()
message(NOTICE "WebFront WebKitGTK default: DEVELOPMENT (per-target distribution may override), sandbox disabled for native views. Select -DWEBFRONT_DISTRIBUTION=ON for distribution; see docs/WEBKITGTK.md.")
endif()
endif()
target_link_libraries(WebFront INTERFACE Threads::Threads)
# dlopen/dlsym: the frontends' run-time loaded toolkits and the system browser's UI loop (needs -ldl before glibc 2.34)
target_link_libraries(WebFront INTERFACE ${CMAKE_DL_LIBS})
if(WIN32)
target_link_libraries(WebFront INTERFACE shell32 bcrypt)
endif()
# Static linkage for CEF compatibility (a global setting: only the top-level project may choose it)
if(MSVC AND NOT WEBFRONT_USE_MDDLOG AND WEBFRONT_IS_TOP_LEVEL)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_CURRENT_LIST_DIR}/js/core ${CMAKE_CURRENT_LIST_DIR}/test/cmake)
if(WEBFRONT_IS_TOP_LEVEL)
include(StandardProjectSettings)
include(PreventInSourceBuilds)
endif()
add_library(WebFront_options INTERFACE)
target_compile_features(WebFront_options INTERFACE cxx_std_23)
# The header-only library instantiates enough templates for the examples to exceed MSVC's default
# object-file section limit (error C1128).
target_compile_options(WebFront_options INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:/bigobj>")
# Do not force-define __cpp_lib_format on the command line: unlike a header setting it after
# actually providing <format>, a command-line -D applies from the start of every translation
# unit, so other standard headers (e.g. <vector>) that gate their own <format> integration on
# this macro see it "on" before <format> has been included and fail to compile. Let each
# toolchain's own <version>/<format> define it accurately; include/webfront/details/C++20Support.hpp
# already falls back to a minimal std::format polyfill when a toolchain leaves it undefined.
add_library(WebFront_warnings INTERFACE)
include(Cache)
include(Linker)
configure_linker(WebFront_options)
include(CompilerWarnings)
set_project_warnings(WebFront_warnings)
include(Sanitizers)
enable_sanitizers(WebFront_options)
if(WEBFRONT_IS_TOP_LEVEL)
include(Doxygen)
enable_doxygen()
include(StaticAnalyzers)
endif()
include(CPM)
CPMAddPackage("gh:ambroise-leclerc/stdnet#8005774eabcba7e73188c02d2eeca2ff43c4ee3a")
webfront_include_frontend_support()
include(ModuleScan)
if(NOT WEBFRONT_IS_TOP_LEVEL)
webfront_check_module_scan()
endif()
if(WEBFRONT_USE_MDDLOG)
include(cmake/MddlogIntegration.cmake)
webfront_add_mddlog()
endif()
# Warnings, sanitizers, coverage and linker choices (WebFront_warnings, WebFront_options) are opt-in per
# internal target, so they never leak into consuming projects; consumers only inherit the C++ standard.
target_compile_features(WebFront INTERFACE cxx_std_23)
target_link_libraries(WebFront INTERFACE stdnet::stdnet)
target_include_directories(WebFront INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
# Only define Windows version macros when building on Windows.
# Defining _WIN32_WINNT on non-Windows (e.g. WSL/Linux) breaks libstdc++ headers.
if (WIN32)
# Prefer Windows 10 (0x0A00). Allow user override by predefining WINVER/_WIN32_WINNT.
if (NOT DEFINED WINVER AND NOT DEFINED _WIN32_WINNT)
target_compile_definitions(WebFront INTERFACE WINVER=0x0A00 _WIN32_WINNT=0x0A00)
endif()
endif()
# Embedded asset regeneration target and CTest freshness checks.
include(WebFrontAssets)
webfront_add_embedded_assets()
# Opt-in consumer test registration; inclusion alone downloads nothing and registers no tests.
include(WebFrontJasmine)
# webfront_embed_directory(): an application's interface directory embedded as a header-only provider, in pure CMake.
include(WebFrontEmbedDirectory)
# The webfront-agent launcher is gone (ADR-025): an application that enables automation serves MCP itself.
if(DEFINED WEBFRONT_BUILD_AUTOMATION OR DEFINED WEBFRONT_AUTOMATION_FRONTEND)
message(WARNING "WEBFRONT_BUILD_AUTOMATION and WEBFRONT_AUTOMATION_FRONTEND no longer build anything: webfront-agent was removed. "
"An application that calls webfront::automation::enableAutomation serves MCP itself (docs/AUTOMATION.md).")
endif()
# What an agent configuring a project must learn at once: the development model, and how it runs wf itself.
include(WebFrontAgentGuide)
webfront_announce_agent_support()
if(WEBFRONT_ENABLE_TESTING OR WEBFRONT_ENABLE_FUZZING)
include(TestHardening)
endif()
if(WEBFRONT_ENABLE_FUZZING)
add_subdirectory(test/fuzz)
endif()
# The host-loop example and its tests share one optional CUDA unit; the language is enabled here, above both.
if(WEBFRONT_ENABLE_TESTING OR WEBFRONT_BUILD_EXAMPLES)
include(BoingCuda)
webfront_enable_host_loop_cuda()
endif()
if(WEBFRONT_ENABLE_TESTING)
enable_testing()
add_subdirectory(test/unit)
add_subdirectory(test/web)
endif()
if(WEBFRONT_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()