|
cmake_minimum_required(VERSION 4.0)
|
|
project(example_project VERSION 1.0 LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 26)
|
|
set(VCPKG_TARGET_ARCHITECTURE wasm32)
|
|
set(VCPKG_TARGET_TRIPLET wasm32-emscripten)
|
|
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
|
|
|
if (MSVC)
|
|
add_compile_options(/W4)
|
|
add_compile_options(/WX)
|
|
add_compile_options(/external:anglebrackets)
|
|
add_compile_options(/external:W0)
|
|
add_compile_options(/wd4100)
|
|
add_compile_options(/wd5050)
|
|
add_definitions(-DWIN32_LEAN_AND_MEAN -DVC_EXTRALEAN)
|
|
add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX)
|
|
else ()
|
|
add_compile_options(-Wall)
|
|
add_compile_options(-Wextra)
|
|
add_compile_options(-Wpedantic)
|
|
add_compile_options(-Werror)
|
|
endif ()
|
|
|
|
if (DEFINED VCPKG_INSTALLED_DIR)
|
|
elseif (DEFINED ENV{VCPKG_ROOT})
|
|
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
|
else ()
|
|
message(FATAL_ERROR "VCPKG is not loaded, set VCPKG_ROOT to automatically load it or specify the cmake toolchain")
|
|
endif ()
|
|
|
|
set(${PROJECT_NAME}_src src/main.cpp)
|
|
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_src})
|
|
|
|
# Configure Emscripten to preload the data folder
|
|
if(EMSCRIPTEN)
|
|
# Check if data folder exists and has content before preloading
|
|
file(GLOB_RECURSE DATA_FILES "${CMAKE_SOURCE_DIR}/data/*")
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
LINK_FLAGS "--preload-file ${CMAKE_SOURCE_DIR}/data@/"
|
|
SUFFIX ".html"
|
|
)
|
|
if(DATA_FILES)
|
|
message(STATUS "Preloading data folder with ${CMAKE_SOURCE_DIR}/data")
|
|
else()
|
|
message(STATUS "Data folder is empty ${CMAKE_SOURCE_DIR}/data")
|
|
endif()
|
|
endif()
|
|
|
|
find_package(SDL3 CONFIG REQUIRED)
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3)
|
|
|
|
find_package(Catch2 CONFIG 3 REQUIRED)
|
|
|
|
file(GLOB_RECURSE tests_${PROJECT_NAME}_src CONFIGURE_DEPENDS tests/*.cppm tests/*/*.cppm)
|
|
|
|
add_executable(tests_${PROJECT_NAME} ${tests_${PROJECT_NAME}_src})
|
|
target_link_libraries(tests_${PROJECT_NAME} PRIVATE Catch2::Catch2 Catch2::Catch2WithMain SDL3::SDL3)
|
|
|
|
include(CTest)
|
|
include(Catch)
|
|
catch_discover_tests(tests_${PROJECT_NAME})
|
|
enable_testing()
|
|
|
|
add_custom_target(serve
|
|
COMMAND python3 ${CMAKE_SOURCE_DIR}/serve.py 5245
|
|
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
COMMENT "Serving WebAssembly files at http://localhost:5245"
|
|
USES_TERMINAL
|
|
)
|