From ea0d3220db995018335c48eb06b9794235ff436b Mon Sep 17 00:00:00 2001 From: MetroWind Date: Sun, 7 Sep 2025 09:42:33 -0700 Subject: Initial commit, mostly just copied from shrt. --- CMakeLists.txt | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 CMakeLists.txt (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1378763 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,136 @@ +# cmake -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=include-what-you-use -B build . && cmake --build build -j +cmake_minimum_required(VERSION 3.24) + +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + +# For whatever reason, the C++ stdlib is broken on my Mac. +# +# % echo "#include " | c++ -x c++ - +# :1:10: fatal error: 'vector' file not found +# 1 | #include +# | ^~~~~~~~ +# 1 error generated. +if(APPLE) + set(CMAKE_CXX_FLAGS "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1") +endif() + +project(Webdir) +option(WEBDIR_BUILD_TESTS "Build unit tests" OFF) + +include(FetchContent) +FetchContent_Declare( + libmw + GIT_REPOSITORY https://github.com/MetroWind/libmw.git +) + +FetchContent_Declare( + cxxopts + GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git + GIT_TAG v3.1.1 +) + +FetchContent_Declare( + ryml + GIT_REPOSITORY https://github.com/biojppm/rapidyaml.git + GIT_TAG + GIT_SHALLOW FALSE # ensure submodules are checked out +) + +FetchContent_Declare( + spdlog + GIT_REPOSITORY https://github.com/gabime/spdlog.git + GIT_TAG v1.12.0 +) + +FetchContent_Declare( + json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 +) + +FetchContent_Declare( + inja + GIT_REPOSITORY https://github.com/pantor/inja.git + GIT_TAG main +) + +set(SPDLOG_USE_STD_FORMAT ON) +set(LIBMW_BUILD_URL ON) +set(LIBMW_BUILD_SQLITE ON) +set(LIBMW_BUILD_HTTP_SERVER ON) +set(INJA_USE_EMBEDDED_JSON FALSE) +set(INJA_BUILD_TESTS FALSE) +FetchContent_MakeAvailable(libmw ryml spdlog cxxopts json inja) + +if(WEBDIR_BUILD_TESTS) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz + ) + FetchContent_MakeAvailable(googletest) +endif() + +set(SOURCE_FILES + src/app.cpp + src/app.hpp + src/config.cpp + src/config.hpp + src/data.cpp + src/data.hpp +) + +set(LIBS + cxxopts + mw::mw + mw::url + mw::sqlite + mw::http-server + ryml::ryml + spdlog::spdlog +) + +set(INCLUDES + ${libmw_SOURCE_DIR}/includes + ${json_SOURCE_DIR}/single_include + ${inja_SOURCE_DIR}/single_include/inja +) + +add_executable(webdir ${SOURCE_FILES} src/main.cpp) +set_property(TARGET webdir PROPERTY CXX_STANDARD 23) +set_property(TARGET webdir PROPERTY CXX_EXTENSIONS FALSE) + +set_property(TARGET webdir PROPERTY COMPILE_WARNING_AS_ERROR TRUE) +target_compile_options(webdir PRIVATE -Wall -Wextra -Wpedantic) +target_include_directories(webdir PRIVATE ${INCLUDES}) +target_link_libraries(webdir PRIVATE ${LIBS}) + +if(WEBDIR_BUILD_TESTS) + set(TEST_FILES + src/data_mock.hpp + src/data_test.cpp + src/app_test.cpp + ) + + # ctest --test-dir build + add_executable(webdir_test ${SOURCE_FILES} ${TEST_FILES}) + set_property(TARGET webdir_test PROPERTY CXX_STANDARD 23) + set_property(TARGET webdir_test PROPERTY COMPILE_WARNING_AS_ERROR TRUE) + target_compile_options(webdir_test PRIVATE -Wall -Wextra -Wpedantic) + target_include_directories(webdir_test PRIVATE + ${INCLUDES} + ${googletest_SOURCE_DIR}/googletest/include + ${googletest_SOURCE_DIR}/googlemock/include + ) + + target_link_libraries(webdir_test PRIVATE + ${LIBS} + GTest::gtest_main + GTest::gmock_main + ) + + enable_testing() + include(GoogleTest) + gtest_discover_tests(webdir_test + # Need this so that the unit tests can find the templates. + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endif() -- cgit v1.2.3-70-g09d2