cmake_minimum_required(VERSION 3.12)

project(golf)

message(${CMAKE_SYSTEM_NAME})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

include_directories(SYSTEM src/3rd_party)
include_directories(src)

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
    add_compile_definitions(SOKOL_GLCORE33)
    add_compile_definitions(GOLF_PLATFORM_WINDOWS)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Darwin)
    add_compile_definitions(SOKOL_GLCORE33)
    add_compile_definitions(GOLF_PLATFORM_LINUX)
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
    add_compile_definitions(SOKOL_GLES3)
    add_compile_definitions(GOLF_PLATFORM_ANDROID)
    add_compile_options("SHELL:-O3")
    add_compile_options("SHELL:-DNDEBUG")
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
    set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM RMF5MGUCT2 CACHE INTERNAL "")
    add_compile_definitions(SOKOL_GLES3)
    add_compile_definitions(GOLF_PLATFORM_IOS)
    add_compile_options("SHELL:-O3")
    add_compile_options("SHELL:-DNDEBUG")
elseif(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
    configure_file("build/emscripten/coi-serviceworker.min.js" ${CMAKE_BINARY_DIR} COPYONLY)
    add_compile_definitions(SOKOL_GLES3)
    add_compile_definitions(GOLF_PLATFORM_EMSCRIPTEN)
    add_compile_options("SHELL:-s USE_PTHREADS=1")
    add_compile_options("SHELL:-O3")
    add_compile_options("SHELL:-DNDEBUG")
    add_link_options("SHELL:-s USE_WEBGL2=1")
    add_link_options("SHELL:-s FULL_ES3=1")
    add_link_options("SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1")
    add_link_options("SHELL:-s ALLOW_MEMORY_GROWTH=1")
    add_link_options("SHELL:-s USE_PTHREADS=1")
    add_link_options("SHELL:-s WASM_MEM_MAX=100Mb")
    add_link_options("SHELL:-s PTHREAD_POOL_SIZE=2")
    add_link_options("SHELL:-lidbfs.js")
    add_link_options("SHELL:--shell-file ../../build/emscripten/shell.html")
    add_link_options("SHELL:-s TOTAL_MEMORY=32Mb")
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Windows)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
    add_compile_options(-g)
endif()

add_subdirectory(src/3rd_party/cimgui)
add_subdirectory(src/3rd_party/fast_obj)
add_subdirectory(src/3rd_party/glad)
add_subdirectory(src/3rd_party/glfw)
add_subdirectory(src/3rd_party/lightmapper)
add_subdirectory(src/3rd_party/mattiasgustavsson_libs)
add_subdirectory(src/3rd_party/miniz)
add_subdirectory(src/3rd_party/parson)
add_subdirectory(src/3rd_party/sokol)
add_subdirectory(src/3rd_party/stb)
add_subdirectory(src/3rd_party/xatlas)
add_subdirectory(src/common)
add_subdirectory(src/golf)

if(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Linux)
    add_subdirectory(src/editor)
endif()
