-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
36 lines (31 loc) · 1.37 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
cmake_minimum_required(VERSION 3.20.0)
option(GLOBAL_VCPKG "Use global Vcpkg " OFF)
option(EMSCRIPTEN "Use Emscripten" OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (GLOBAL_VCPKG)
set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
else()
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
endif()
if (EMSCRIPTEN)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE $ENV{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake CACHE STRING "Emscripten toolchain file")
set(VCPKG_TARGET_TRIPLET wasm32-emscripten)
# This seems not working correctly (alway .js)
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
if (NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif()
endif()
project(cpp-wasm)
find_package(SDL2 CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
add_executable(main src/main.cpp)
target_link_libraries(main PRIVATE SDL2::SDL2)
target_link_libraries(main PRIVATE glad::glad)
target_link_libraries(main PRIVATE fmt::fmt)
if (EMSCRIPTEN)
target_link_options(main PRIVATE "-sMAX_WEBGL_VERSION=2" "-WASM=1" "-Os" "-sEXPORTED_FUNCTIONS=_main,_sayHello" "-sMIN_SAFARI_VERSION=-1")
add_custom_target(copy_html COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/www/index.html ${CMAKE_BINARY_DIR})
add_dependencies(main copy_html)
endif()