# 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) 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 # TODO: Use 3.12.1. # # Temporarily swtich to develop because of # https://github.com/nlohmann/json/issues/4756. GIT_TAG develop ) 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()