cmake_minimum_required(VERSION 3.24) if(POLICY CMP0205) cmake_policy(SET CMP0205 NEW) endif() project(shweets_sim LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Two builds: Release (the default) and Debug. if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_BUILD_TYPE Release) endif() if(MSVC) add_compile_options(/utf-8) endif() # Release builds: -O2, link-time optimization, unused code and data dropped, and the symbols stripped. if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) add_compile_options("$<$:-O2;-ffunction-sections;-fdata-sections>") add_link_options("$<$:-Wl,--gc-sections;-s>") endif() # SDL: static, with only the video (OpenGL) and audio pieces the game uses. set(SDL_SHARED OFF CACHE BOOL "" FORCE) set(SDL_STATIC ON CACHE BOOL "" FORCE) set(SDL_OPENGL ON CACHE BOOL "" FORCE) set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE) set(SDL_EXAMPLES OFF CACHE BOOL "" FORCE) foreach(OPTION RENDER GPU VULKAN CAMERA HAPTIC HIDAPI JOYSTICK POWER SENSOR DIALOG TRAY OPENGLES OFFSCREEN DUMMYVIDEO DISKAUDIO DUMMYAUDIO OSS JACK SNDIO KMSDRM IBUS LIBURING) set(SDL_${OPTION} OFF CACHE BOOL "" FORCE) endforeach() add_subdirectory(external/sdl EXCLUDE_FROM_ALL) # simdjson: its single-file build, static, without exceptions, with only the AVX2 parser and the portable one. add_library(simdjson STATIC external/simdjson/singleheader/simdjson.cpp) target_include_directories(simdjson SYSTEM PUBLIC external/simdjson/singleheader) target_compile_definitions(simdjson PUBLIC SIMDJSON_EXCEPTIONS=0 SIMDJSON_IMPLEMENTATION_ICELAKE=0 SIMDJSON_IMPLEMENTATION_WESTMERE=0) # Dear ImGui: the core, and its SDL3 and OpenGL 3 backends. add_library(imgui STATIC external/imgui/imgui.cpp external/imgui/imgui_draw.cpp external/imgui/imgui_tables.cpp external/imgui/imgui_widgets.cpp external/imgui/backends/imgui_impl_sdl3.cpp external/imgui/backends/imgui_impl_opengl3.cpp) target_include_directories(imgui SYSTEM PUBLIC external/imgui external/imgui/backends) target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS IMGUI_DISABLE_DEMO_WINDOWS) target_link_libraries(imgui PUBLIC SDL3::SDL3-static) file(GLOB SOURCES CONFIGURE_DEPENDS src/*.cpp) add_executable(shweets_sim ${SOURCES}) target_include_directories(shweets_sim SYSTEM PRIVATE external/stb) target_link_libraries(shweets_sim PRIVATE imgui simdjson) target_compile_definitions(shweets_sim PRIVATE "$<$:DEBUG>") set_target_properties(shweets_sim PROPERTIES OUTPUT_NAME shweets-sim) file(CREATE_LINK ${CMAKE_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/resources COPY_ON_ERROR SYMBOLIC) if(WIN32) set_target_properties(shweets_sim PROPERTIES WIN32_EXECUTABLE ON) target_sources(shweets_sim PRIVATE shweets-sim.rc) endif() # Emscripten: WebGL2, the resources preloaded, the prefs folder kept in browser storage (web/pre.js), and a page whose # canvas fills the window. if(EMSCRIPTEN) set_target_properties(shweets_sim PROPERTIES OUTPUT_NAME index SUFFIX ".html") target_link_options(shweets_sim PRIVATE -sALLOW_MEMORY_GROWTH=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -lidbfs.js "--preload-file=${CMAKE_SOURCE_DIR}/resources@/resources" "--shell-file=${CMAKE_SOURCE_DIR}/web/index.html" "--pre-js=${CMAKE_SOURCE_DIR}/web/pre.js") endif()