generated from alistair/sdl-imgui-template
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.8 KiB
107 lines
2.8 KiB
cmake_minimum_required(VERSION 3.14) |
|
|
|
set(CMAKE_CXX_STANDARD 20) |
|
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
|
|
|
set(BUILD_SHARED_LIBS OFF) |
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") |
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fpermissive -Wno-error ") |
|
|
|
|
|
project( |
|
project-name |
|
VERSION 0.1.0 |
|
DESCRIPTION "${REPO_DESCRIPTION}" |
|
HOMEPAGE_URL "https://example.com/" |
|
LANGUAGES CXX |
|
) |
|
|
|
include(cmake/emscripten.cmake) |
|
include(cmake/CPM.cmake) |
|
include(FetchContent) |
|
|
|
CPMAddPackage("gh:onqtam/doctest@2.4.9") |
|
|
|
CPMAddPackage("gh:nlohmann/json@3.10.5") |
|
|
|
CPMAddPackage("gh:ocornut/imgui#docking") |
|
|
|
CPMAddPackage("gh:gabime/spdlog@1.8.2") |
|
|
|
CPMAddPackage("gh:fmtlib/fmt#7.1.3") |
|
|
|
FetchContent_Declare(SDL2 |
|
GIT_REPOSITORY https://github.com/libsdl-org/SDL |
|
GIT_TAG release-2.26.4 |
|
OVERRIDE_FIND_PACKAGE |
|
) |
|
FetchContent_MakeAvailable(SDL2) |
|
|
|
find_package(SDL2 REQUIRED) |
|
|
|
# https://github.com/cpm-cmake/CPM.cmake/issues/368 |
|
add_library(imgui STATIC |
|
${imgui_SOURCE_DIR}/imgui.cpp |
|
${imgui_SOURCE_DIR}/imgui_demo.cpp # optionally comment this out |
|
${imgui_SOURCE_DIR}/imgui_draw.cpp |
|
${imgui_SOURCE_DIR}/imgui_widgets.cpp |
|
${imgui_SOURCE_DIR}/imgui_tables.cpp |
|
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp |
|
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp |
|
${imgui_SOURCE_DIR}/imgui_demo.cpp # optionally comment this out |
|
) |
|
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR}) |
|
target_compile_definitions(imgui PUBLIC -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS) # optional imgui setting |
|
target_link_libraries(imgui PUBLIC SDL2::SDL2-static) |
|
|
|
|
|
add_executable(main_exe source/main.cpp) |
|
add_executable(main::exe ALIAS main_exe) |
|
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG |
|
"${CMAKE_C_FLAGS_DEBUG} -Og -g -Werror -fsanitize=undefined -fsanitize=address -fsanitize=leak" |
|
) |
|
set(CMAKE_CXX_FLAGS_DEBUG |
|
"${CMAKE_CXX_FLAGS_DEBUG} -Og -g -Werror -fsanitize=undefined -fsanitize=address -fsanitize=leak" |
|
) |
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fstack-protector") |
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fstack-protector") |
|
|
|
|
|
|
|
|
|
set_property(TARGET main_exe PROPERTY OUTPUT_NAME main) |
|
|
|
target_compile_features(main_exe PRIVATE cxx_std_20) |
|
|
|
if (EMSCRIPTEN) |
|
hello_imgui_platform_customization(main_exe) |
|
endif() |
|
|
|
|
|
target_link_libraries(main_exe PRIVATE |
|
fmt::fmt |
|
SDL2::SDL2-static |
|
spdlog |
|
imgui |
|
nlohmann_json::nlohmann_json |
|
) |
|
|
|
if (EMSCRIPTEN) |
|
target_link_libraries(imgui PUBLIC SDL2::SDL2-static GLESv2) |
|
endif() |
|
|
|
if (LINUX) |
|
target_link_libraries(imgui PUBLIC SDL2::SDL2-static OpenGL) |
|
endif() |
|
|
|
if (WIN32) |
|
set(CMAKE_EXE_LINKER_FLAGS "-static -fstack-protector") |
|
target_link_libraries(imgui PUBLIC SDL2::SDL2-static opengl32) |
|
target_link_libraries(main_exe PRIVATE SDL2::SDL2main iconv ssp opengl32) |
|
endif() |
|
|
|
|