-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
75 lines (67 loc) · 2.51 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
cmake_minimum_required(VERSION 3.24)
option(SUPERBUILD "Perform a superbuild (or not)" OFF)
project(sdl-bgfx-imgui-starter LANGUAGES CXX)
if (SUPERBUILD)
if (EMSCRIPTEN)
set(THIRD_PARTY_BUILD_DIR_NAME embuild)
else ()
set(THIRD_PARTY_BUILD_DIR_NAME build)
endif ()
include(third-party/CMakeLists.txt)
include(cmake/superbuild.cmake)
return()
endif ()
find_package(SDL2 REQUIRED CONFIG CMAKE_FIND_ROOT_PATH_BOTH)
find_package(bgfx REQUIRED CONFIG CMAKE_FIND_ROOT_PATH_BOTH)
find_package(imgui.cmake REQUIRED CONFIG CMAKE_FIND_ROOT_PATH_BOTH)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp sdl-imgui/imgui_impl_sdl2.cpp
bgfx-imgui/imgui_impl_bgfx.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
target_link_libraries(
${PROJECT_NAME} PRIVATE SDL2::SDL2-static SDL2::SDL2main bgfx::bgfx bgfx::bx
imgui.cmake::imgui.cmake)
target_link_options(
${PROJECT_NAME} PRIVATE $<$<BOOL:${EMSCRIPTEN}>:-sMAX_WEBGL_VERSION=2
-sALLOW_MEMORY_GROWTH=1 --preload-file=shader/embuild/v_simple.bin
--preload-file=shader/embuild/f_simple.bin>)
target_compile_definitions(
${PROJECT_NAME} PRIVATE $<$<BOOL:${EMSCRIPTEN}>:USE_SDL=2>)
if (EMSCRIPTEN)
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
add_custom_command(
TARGET ${PROJECT_NAME}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
$<TARGET_FILE_DIR:${PROJECT_NAME}>/shader/embuild
COMMAND
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/shader/embuild/v_simple.bin
$<TARGET_FILE_DIR:${PROJECT_NAME}>/shader/embuild
COMMAND
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/shader/embuild/f_simple.bin
$<TARGET_FILE_DIR:${PROJECT_NAME}>/shader/embuild
VERBATIM)
else ()
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/shader/build
$<TARGET_FILE_DIR:${PROJECT_NAME}>/shader/build
VERBATIM)
endif ()
set_target_properties(
${PROJECT_NAME}
# required for project when using visual studio generator
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>)
if (WIN32)
# copy the SDL2.dll to the same folder as the executable
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SDL2::SDL2>
$<TARGET_FILE_DIR:${PROJECT_NAME}>
VERBATIM)
endif ()