Skip to content

Commit 180871a

Browse files
committed
[build-win]
1 parent 1ba61d7 commit 180871a

36 files changed

Lines changed: 373 additions & 547 deletions

.github/workflows/Windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
4949
- name: Run build inside container
5050
run: |
51-
docker run --rm --cpus 4 `
51+
docker run --rm --memory 16g --cpus 4 `
5252
--mount "type=bind,source=${{ github.workspace }},target=C:\workspace" `
5353
-w "C:\workspace" `
5454
"${{ env.CONTAINER_IMAGE }}" `

CMakeLists.txt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ project(
1010

1111
set(AUTHOR "Jonas Heinle")
1212

13+
include(cmake/BuildTypeHelpers.cmake)
14+
15+
# Resolve symlinks before comparing so aliased source/build paths are still rejected.
16+
get_filename_component(_myproject_source_dir "${CMAKE_SOURCE_DIR}" REALPATH)
17+
get_filename_component(_myproject_binary_dir "${CMAKE_BINARY_DIR}" REALPATH)
18+
if("${_myproject_source_dir}" STREQUAL "${_myproject_binary_dir}")
19+
message(
20+
FATAL_ERROR "In-source builds are disabled. Please create a separate build directory and run CMake from there.")
21+
endif()
22+
1323
set(MYPROJECT_GCC_TOOLCHAIN_PATH
1424
""
1525
CACHE PATH "Optional GCC toolchain root used by Clang and Rust tooling on Linux (for example /opt/gcc-15.2.0)")
1626

17-
include(cmake/PreventInSourceBuilds.cmake)
1827
include(cmake/ProjectOptions.cmake)
1928
include(cmake/MSVCRuntimeConfig.cmake)
2029
include(cmake/RustOptions.cmake)
@@ -57,7 +66,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
5766
# If a profile path is supplied, use it for profile-guided optimizations.
5867
target_compile_options(myproject_options INTERFACE -fprofile-instr-use=${myproject_PGO_PROFILE})
5968
target_link_options(myproject_options INTERFACE -fprofile-instr-use=${myproject_PGO_PROFILE})
60-
elseif(myproject_ENABLE_PGO AND (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release"))
69+
elseif(myproject_ENABLE_PGO AND (MYPROJECT_BUILD_IS_RELWITHDEBINFO OR MYPROJECT_BUILD_IS_RELEASE))
6170
# Instrument the build to generate runtime profiles (.profraw).
6271
target_compile_options(myproject_options INTERFACE -fprofile-instr-generate)
6372
target_link_options(myproject_options INTERFACE -fprofile-instr-generate)
@@ -75,6 +84,18 @@ myproject_configure_msvc_runtime()
7584

7685
add_subdirectory(ExternalLib)
7786

87+
# FUZZTEST pulls antlr4-cpp transitively on Windows clang-cl debug builds.
88+
# antlr4-cpp 4.13.2's ProfilingATNSimulator.cpp uses std::chrono without
89+
# including <chrono>, so fix that at the target level instead of patching the
90+
# vendored source tree.
91+
if(MSVC AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
92+
foreach(_myproject_antlr_target antlr4_static antlr4_shared)
93+
if(TARGET ${_myproject_antlr_target})
94+
target_compile_options(${_myproject_antlr_target} PRIVATE /FIchrono)
95+
endif()
96+
endforeach()
97+
endif()
98+
7899
# If the nlohmann.json module target was created, expose a compile-time macro
79100
# so consumer module units can conditionally import the module. This lets
80101
# translation units fall back to the header-only include if the module BMI
@@ -96,7 +117,7 @@ if(BUILD_TESTING)
96117
include(CTest)
97118
enable_testing()
98119

99-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
120+
if(MYPROJECT_BUILD_IS_DEBUG)
100121
add_subdirectory(Test/commit)
101122
add_subdirectory(Test/compile)
102123
if(NOT USE_THREAD_SANITIZER)
@@ -105,7 +126,7 @@ if(BUILD_TESTING)
105126
endif()
106127
endif()
107128

108-
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
129+
if(MYPROJECT_BUILD_IS_RELWITHDEBINFO)
109130
add_subdirectory(Test/perf)
110131
endif()
111132

ExternalLib/CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
include(FetchContent)
22

3-
message(STATUS "ExternalLib/CMakeLists: RUST_FEATURES=${RUST_FEATURES} CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
4-
3+
include(${CMAKE_SOURCE_DIR}/cmake/BuildTypeHelpers.cmake)
54
include(${CMAKE_SOURCE_DIR}/cmake/CompilerConfigHelpers.cmake)
65

76
if(BUILD_TESTING)
@@ -19,23 +18,37 @@ set(BENCHMARK_USE_BUNDLED_GTEST OFF CACHE BOOL "Disable the bundled GTest usage.
1918

2019
add_subdirectory(GOOGLE_BENCHMARK)
2120

22-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BUILD_TESTING AND CMAKE_BUILD_TYPE STREQUAL "Debug")
23-
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang" AND NOT USE_THREAD_SANITIZER)
24-
message("Adding Fuzztest")
25-
option(KATAGLYPHIS_ENABLE_FUZZTEST_FUZZING_MODE
26-
"Build FUZZTEST in fuzzing mode (injects AddressSanitizer/coverage flags; keep OFF for normal builds)"
27-
ON)
28-
set(FUZZTEST_FUZZING_MODE OFF CACHE BOOL "" FORCE)
29-
add_subdirectory(FUZZTEST)
21+
set(_kataglyphis_enable_fuzztest FALSE)
22+
if(BUILD_TESTING
23+
AND MYPROJECT_BUILD_IS_DEBUG
24+
AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang"
25+
AND NOT USE_THREAD_SANITIZER
26+
AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Windows"))
27+
set(_kataglyphis_enable_fuzztest TRUE)
28+
endif()
29+
30+
if(_kataglyphis_enable_fuzztest)
31+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND FUZZTEST_COMPATIBILITY_MODE STREQUAL "libfuzzer")
32+
message(FATAL_ERROR "FUZZTEST_COMPATIBILITY_MODE=libfuzzer is not supported on Windows clang-cl.")
3033
endif()
34+
35+
set(_kataglyphis_default_fuzztest_fuzzing_mode OFF)
36+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
37+
set(_kataglyphis_default_fuzztest_fuzzing_mode ON)
38+
endif()
39+
40+
option(KATAGLYPHIS_ENABLE_FUZZTEST_FUZZING_MODE
41+
"Build FUZZTEST in fuzzing mode (injects AddressSanitizer/coverage flags; keep OFF for normal builds)"
42+
${_kataglyphis_default_fuzztest_fuzzing_mode})
43+
set(FUZZTEST_FUZZING_MODE OFF CACHE BOOL "" FORCE)
44+
add_subdirectory(FUZZTEST)
3145
endif()
3246

3347
FetchContent_Declare(GSL GIT_REPOSITORY "https://github.com/microsoft/GSL" GIT_TAG "v4.2.1")
3448
FetchContent_MakeAvailable(GSL)
3549

3650
FetchContent_Declare(abseil-cpp GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git GIT_TAG 20260107.1)
3751
FetchContent_MakeAvailable(abseil-cpp)
38-
include_directories(${abseil-cpp_SOURCE_DIR})
3952

4053
if(myproject_DISABLE_EXCEPTIONS)
4154
set(SPDLOG_NO_EXCEPTIONS ON CACHE BOOL "Disable SPDLOG exceptions.")
@@ -95,4 +108,4 @@ endif()
95108

96109
if(TARGET nlohmann_json_modules AND TARGET nlohmann_json)
97110
set_target_properties(nlohmann_json PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
98-
endif()
111+
endif()

Src/CMakeLists.txt

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ set(PROJECT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
33
set(PROJECT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
44
set(EXTERNAL_LIB_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ExternalLib/)
55

6-
include(cmake/filters/SetProjectFilters.cmake)
7-
include(cmake/SetSourceGroups.cmake)
8-
96
file(GLOB_RECURSE KataglyphisCppProject_SOURCES "*.cpp")
107
file(GLOB_RECURSE KataglyphisCppProject_HEADERS "*.hpp")
118
set(KATAGLYPHIS_MAIN_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/Main.cpp")
129
list(REMOVE_ITEM KataglyphisCppProject_SOURCES "${KATAGLYPHIS_MAIN_SOURCE}")
10+
source_group("main" FILES "${KATAGLYPHIS_MAIN_SOURCE}")
1311

1412
# Ensure the Abseil flags translation unit is compiled and linked into the
1513
# executable. We add it explicitly so module-aware compilers see the TU even
@@ -64,25 +62,8 @@ if(MSVC)
6462
target_compile_options(${PROJECT_NAME} PRIVATE /EHsc)
6563
endif()
6664

67-
if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
68-
target_compile_definitions(${PROJECT_NAME} PRIVATE RELATIVE_RESOURCE_PATH="/../../Resources/"
69-
RELATIVE_INCLUDE_PATH="/../../Src/")
70-
else()
71-
target_compile_definitions(${PROJECT_NAME} PRIVATE RELATIVE_RESOURCE_PATH="/../Resources/"
72-
RELATIVE_INCLUDE_PATH="/../Src/")
73-
endif()
74-
7565
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
7666

77-
# Treat MSVC and clang-cl on Windows differently in a sense of deployment
78-
if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
79-
target_compile_definitions(${KATAGLYPHIS_CORE_TARGET} PRIVATE RELATIVE_RESOURCE_PATH="/../../Resources/"
80-
RELATIVE_INCLUDE_PATH="/../../Src/")
81-
else()
82-
target_compile_definitions(${KATAGLYPHIS_CORE_TARGET} PRIVATE RELATIVE_RESOURCE_PATH="/../Resources/"
83-
RELATIVE_INCLUDE_PATH="/../Src/")
84-
endif()
85-
8667
target_sources(
8768
${KATAGLYPHIS_CORE_TARGET}
8869
PRIVATE ${KataglyphisCppProject_SOURCES}

Src/KataglyphisCppProject.ixx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ auto run() -> int
4545
<< "\n";
4646

4747
#if defined(TOMLPLUSPLUS_MODULE_AVAILABLE)
48-
// Parse the example TOML resource to demonstrate module usage.
49-
// Use the no-exceptions API (parse_result) so this code compiles when
50-
// exceptions are disabled for the toolchain.
48+
// Parse an in-memory TOML document to demonstrate module usage without
49+
// depending on the current working directory at runtime.
5150
{
52-
auto res = toml::parse_file("${CMAKE_SOURCE_DIR}/Src/resources/example.toml");
51+
auto res = toml::parse(R"(
52+
[application]
53+
name = "Kataglyphis Runtime"
54+
version = "0.0.1"
55+
)");
5356
if (res) {
5457
// parse_result is convertible to toml::table when successful
5558
const auto &t = static_cast<const toml::table &>(res);

Src/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import kataglyphis_core;
55
// the declaration at global scope avoids declaring `main` with extern "C"
66
// linkage (which triggers a warning) and avoids putting linkage-specifiers
77
// inside the function body which can confuse some frontends.
8-
extern "C" void kataglyphis_parse_flags(int argc, char** argv);
8+
extern "C" void kataglyphis_parse_flags(int argc, char **argv);
99

10-
int main(int argc, char** argv)
10+
int main(int argc, char **argv)
1111
{
1212
// Parse flags in a separate translation unit to avoid including Abseil
1313
// headers in a module-importing TU. The parse_flags function is defined

Src/cmake/SetSourceGroups.cmake

Lines changed: 0 additions & 1 deletion
This file was deleted.

Src/cmake/filters/SetProjectFilters.cmake

Lines changed: 0 additions & 4 deletions
This file was deleted.

Src/flags.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ ABSL_FLAG(bool, verbose, false, "Enable verbose logging");
1717

1818
namespace kataglyphis {
1919

20-
void parse_flags(int argc, char** argv)
20+
void parse_flags(int argc, char **argv)
2121
{
2222
absl::SetProgramUsageMessage("Usage: kataglyphis --input=FILE [options]");
2323
// Parse and ignore leftover positional arguments here.
2424
(void)absl::ParseCommandLine(argc, argv);
2525
}
2626

27-
} // namespace kataglyphis
27+
}// namespace kataglyphis
2828

2929
// Provide a C-linkage wrapper so the module-based main can reliably call the
3030
// flag parsing function without depending on C++ name mangling or module
3131
// visibility rules across translation units.
32-
extern "C" void kataglyphis_parse_flags(int argc, char** argv)
33-
{
34-
kataglyphis::parse_flags(argc, argv);
35-
}
32+
extern "C" void kataglyphis_parse_flags(int argc, char **argv) { kataglyphis::parse_flags(argc, argv); }

0 commit comments

Comments
 (0)