aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorMetroWind <chris.corsair@gmail.com>2025-09-07 09:42:33 -0700
committerMetroWind <chris.corsair@gmail.com>2025-09-07 09:42:33 -0700
commitea0d3220db995018335c48eb06b9794235ff436b (patch)
tree892564cdd4946c6ee9c1051bc31ff5c7bba6ddf1 /CMakeLists.txt
Initial commit, mostly just copied from shrt.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt136
1 files changed, 136 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..1378763
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,136 @@
1# cmake -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=include-what-you-use -B build . && cmake --build build -j
2cmake_minimum_required(VERSION 3.24)
3
4set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
5
6# For whatever reason, the C++ stdlib is broken on my Mac.
7#
8# % echo "#include <vector>" | c++ -x c++ -
9# <stdin>:1:10: fatal error: 'vector' file not found
10# 1 | #include <vector>
11# | ^~~~~~~~
12# 1 error generated.
13if(APPLE)
14 set(CMAKE_CXX_FLAGS "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1")
15endif()
16
17project(Webdir)
18option(WEBDIR_BUILD_TESTS "Build unit tests" OFF)
19
20include(FetchContent)
21FetchContent_Declare(
22 libmw
23 GIT_REPOSITORY https://github.com/MetroWind/libmw.git
24)
25
26FetchContent_Declare(
27 cxxopts
28 GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
29 GIT_TAG v3.1.1
30)
31
32FetchContent_Declare(
33 ryml
34 GIT_REPOSITORY https://github.com/biojppm/rapidyaml.git
35 GIT_TAG
36 GIT_SHALLOW FALSE # ensure submodules are checked out
37)
38
39FetchContent_Declare(
40 spdlog
41 GIT_REPOSITORY https://github.com/gabime/spdlog.git
42 GIT_TAG v1.12.0
43)
44
45FetchContent_Declare(
46 json
47 GIT_REPOSITORY https://github.com/nlohmann/json.git
48 GIT_TAG v3.11.3
49)
50
51FetchContent_Declare(
52 inja
53 GIT_REPOSITORY https://github.com/pantor/inja.git
54 GIT_TAG main
55)
56
57set(SPDLOG_USE_STD_FORMAT ON)
58set(LIBMW_BUILD_URL ON)
59set(LIBMW_BUILD_SQLITE ON)
60set(LIBMW_BUILD_HTTP_SERVER ON)
61set(INJA_USE_EMBEDDED_JSON FALSE)
62set(INJA_BUILD_TESTS FALSE)
63FetchContent_MakeAvailable(libmw ryml spdlog cxxopts json inja)
64
65if(WEBDIR_BUILD_TESTS)
66 FetchContent_Declare(
67 googletest
68 URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
69 )
70 FetchContent_MakeAvailable(googletest)
71endif()
72
73set(SOURCE_FILES
74 src/app.cpp
75 src/app.hpp
76 src/config.cpp
77 src/config.hpp
78 src/data.cpp
79 src/data.hpp
80)
81
82set(LIBS
83 cxxopts
84 mw::mw
85 mw::url
86 mw::sqlite
87 mw::http-server
88 ryml::ryml
89 spdlog::spdlog
90)
91
92set(INCLUDES
93 ${libmw_SOURCE_DIR}/includes
94 ${json_SOURCE_DIR}/single_include
95 ${inja_SOURCE_DIR}/single_include/inja
96)
97
98add_executable(webdir ${SOURCE_FILES} src/main.cpp)
99set_property(TARGET webdir PROPERTY CXX_STANDARD 23)
100set_property(TARGET webdir PROPERTY CXX_EXTENSIONS FALSE)
101
102set_property(TARGET webdir PROPERTY COMPILE_WARNING_AS_ERROR TRUE)
103target_compile_options(webdir PRIVATE -Wall -Wextra -Wpedantic)
104target_include_directories(webdir PRIVATE ${INCLUDES})
105target_link_libraries(webdir PRIVATE ${LIBS})
106
107if(WEBDIR_BUILD_TESTS)
108 set(TEST_FILES
109 src/data_mock.hpp
110 src/data_test.cpp
111 src/app_test.cpp
112 )
113
114 # ctest --test-dir build
115 add_executable(webdir_test ${SOURCE_FILES} ${TEST_FILES})
116 set_property(TARGET webdir_test PROPERTY CXX_STANDARD 23)
117 set_property(TARGET webdir_test PROPERTY COMPILE_WARNING_AS_ERROR TRUE)
118 target_compile_options(webdir_test PRIVATE -Wall -Wextra -Wpedantic)
119 target_include_directories(webdir_test PRIVATE
120 ${INCLUDES}
121 ${googletest_SOURCE_DIR}/googletest/include
122 ${googletest_SOURCE_DIR}/googlemock/include
123 )
124
125 target_link_libraries(webdir_test PRIVATE
126 ${LIBS}
127 GTest::gtest_main
128 GTest::gmock_main
129 )
130
131 enable_testing()
132 include(GoogleTest)
133 gtest_discover_tests(webdir_test
134 # Need this so that the unit tests can find the templates.
135 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
136endif()