better cmake for emscripten flags

This commit is contained in:
Green Sky 2022-10-30 16:36:17 +01:00 committed by Erik Scholz
parent c13dff8eb3
commit 4d0f731d8d
12 changed files with 59 additions and 58 deletions

1
external/glm.cmake vendored
View File

@ -2,4 +2,5 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
add_library(glm INTERFACE)
target_include_directories(glm INTERFACE "${CMAKE_CURRENT_LIST_DIR}/glm")
target_compile_definitions(glm INTERFACE GLM_ENABLE_EXPERIMENTAL)

View File

@ -46,7 +46,7 @@ if(MM_OPENGL_3_GLES)
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM) # bug?
else()
target_compile_definitions(imgui PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(imgui glad)
target_link_libraries(imgui PUBLIC glad)
endif()
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
@ -56,15 +56,21 @@ target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui") # i
target_compile_definitions(imgui PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1)
if(EMSCRIPTEN)
set_target_properties(imgui PROPERTIES COMPILE_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES2=1 -s FULL_ES3=1")
set_target_properties(imgui PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FULL_ES2=1 -s FULL_ES3=1")
target_compile_options(imgui PUBLIC -sUSE_SDL=2)
target_link_libraries(imgui PUBLIC -sUSE_SDL=2 -sUSE_WEBGL2=1 -sFULL_ES3=1)
elseif(ANDROID)
target_link_libraries(imgui SDL)
target_link_libraries(imgui PUBLIC SDL)
elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(imgui SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
target_link_libraries(imgui
PUBLIC
SDL2::SDL2
PRIVATE
SDL2::SDL2main
SDL2::SDL2-static
)
else()
target_include_directories(imgui PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(imgui ${SDL2_LIBRARY})
target_link_libraries(imgui PUBLIC ${SDL2_LIBRARY})
endif()
target_compile_definitions(imgui PUBLIC ImTextureID=unsigned\ long)

View File

@ -163,10 +163,16 @@ target_include_directories(soloud SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/sol
#if not android or emscripten
if(VCPKG_TARGET_TRIPLET)
target_link_libraries(soloud SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
target_link_libraries(soloud
PUBLIC
SDL2::SDL2
PRIVATE
SDL2::SDL2main
SDL2::SDL2-static
)
else()
target_include_directories(soloud PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(soloud ${SDL2_LIBRARY})
target_link_libraries(soloud PUBLIC ${SDL2_LIBRARY})
endif()
#if android
@ -174,14 +180,14 @@ endif()
#endif
if(EMSCRIPTEN)
set_target_properties(soloud PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(soloud PROPERTIES LINK_FLAGS "-s USE_SDL=2")
target_compile_options(soloud PUBLIC -sUSE_SDL=2)
target_link_libraries(soloud PUBLIC -sUSE_SDL=2)
endif()
# TODO: remove
if(UNIX)
target_link_libraries(soloud
target_link_libraries(soloud PUBLIC
-ldl
)
endif()

View File

@ -14,7 +14,7 @@ add_library(filesystem_service
target_include_directories(filesystem_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(filesystem_service
target_link_libraries(filesystem_service PUBLIC
engine
logger
entt
@ -30,14 +30,20 @@ if(NOT MM_HEADLESS)
#endif
if(EMSCRIPTEN)
set_target_properties(filesystem_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(filesystem_service PROPERTIES LINK_FLAGS "-s USE_SDL=2")
target_compile_options(filesystem_service PUBLIC -sUSE_SDL=2)
target_link_libraries(filesystem_service PUBLIC -sUSE_SDL=2)
elseif(VCPKG_TARGET_TRIPLET)
target_link_libraries(filesystem_service SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
target_link_libraries(filesystem_service
PUBLIC
SDL2::SDL2
PRIVATE
SDL2::SDL2main
SDL2::SDL2-static
)
else()
#if not android or emscripten
target_include_directories(filesystem_service PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(filesystem_service ${SDL2_LIBRARY})
target_link_libraries(filesystem_service PUBLIC ${SDL2_LIBRARY})
#endif
endif()
endif()

View File

@ -33,6 +33,7 @@ bool FilesystemService::enable(Engine&, std::vector<UpdateStrategies::TaskInfo>&
return false;
}
// TODO: why exclude EMSCRIPTEN here? also wrong macro
#if !defined(MM_HEADLESS) && !defined(EMSCRIPTEN)
char* pref_path = SDL_GetPrefPath("made_of_jelly", _app_name);
#else

View File

@ -15,12 +15,9 @@ target_link_libraries(input_service
sdl_service
)
if(EMSCRIPTEN)
set_target_properties(input_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(input_service PROPERTIES LINK_FLAGS "-s USE_SDL=2")
else()
target_include_directories(input_service PUBLIC "${SDL2_INCLUDE_DIR}")
endif()
#if(NOT EMSCRIPTEN)
#target_include_directories(input_service PUBLIC "${SDL2_INCLUDE_DIR}")
#endif()
if (BUILD_TESTING)
add_subdirectory(test)

View File

@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(opengl_primitives CXX)
file(GLOB_RECURSE CPP_FILES src/*.cpp)
file(GLOB_RECURSE HPP_FILES src/*.hpp)
add_library(opengl_primitives
src/mm/opengl/buffer.hpp
src/mm/opengl/buffer.cpp
@ -31,7 +28,7 @@ add_library(opengl_primitives
target_include_directories(opengl_primitives PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(opengl_primitives
target_link_libraries(opengl_primitives PUBLIC
glm
stb_image
#sdl
@ -43,14 +40,16 @@ target_link_libraries(opengl_primitives
)
if(MM_OPENGL_3_GLES)
target_link_libraries(opengl_primitives "GL") # TODO: make more specific
target_link_libraries(opengl_primitives PUBLIC "GL") # TODO: make more specific
if(EMSCRIPTEN)
set_target_properties(opengl_primitives PROPERTIES COMPILE_FLAGS "-s USE_WEBGL2=1 -s USE_SDL=2")
set_target_properties(opengl_primitives PROPERTIES LINK_FLAGS "-s USE_WEBGL2=1 -s USE_SDL=2")
# USE_SDL=2 inherited from sdl_service
# TODO: USE_WEBGL2 -> MIN_WEBGL_VERSION=2 maybe
# technically only FULL_ES3 would be needed
target_link_libraries(opengl_primitives PUBLIC -sUSE_WEBGL2=1 -sFULL_ES3=1)
endif()
else()
target_link_libraries(opengl_primitives glad)
target_link_libraries(opengl_primitives PUBLIC glad)
endif()
if (BUILD_TESTING)

View File

@ -17,7 +17,6 @@ add_library(opengl_renderer_s
target_include_directories(opengl_renderer_s PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
add_definitions(-DGLM_ENABLE_EXPERIMENTAL)
target_link_libraries(opengl_renderer_s
engine
logger
@ -26,11 +25,6 @@ target_link_libraries(opengl_renderer_s
sdl_service
)
if(EMSCRIPTEN)
set_target_properties(opengl_renderer_s PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(opengl_renderer_s PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
############# imgui opengl renderer tools ###########
add_library(imgui_opengl_renderer_tools

View File

@ -12,7 +12,7 @@ add_library(sdl_service
target_include_directories(sdl_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(sdl_service
target_link_libraries(sdl_service PUBLIC
entt
logger
#glm
@ -25,23 +25,29 @@ target_link_libraries(sdl_service
#endif
if(EMSCRIPTEN)
set_target_properties(sdl_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(sdl_service PROPERTIES LINK_FLAGS "-s USE_SDL=2")
target_compile_options(sdl_service PUBLIC -sUSE_SDL=2)
target_link_libraries(sdl_service PUBLIC -sUSE_SDL=2)
else()
#if not android or emscripten
target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}")
target_link_libraries(sdl_service ${SDL2_LIBRARY})
target_link_libraries(sdl_service PUBLIC ${SDL2_LIBRARY})
#endif
endif()
if(MM_OPENGL_3_GLES)
target_link_libraries(sdl_service "GL") # TODO: make more specific
target_link_libraries(sdl_service PRIVATE "GL") # TODO: make more specific
else()
target_link_libraries(sdl_service glad)
target_link_libraries(sdl_service PRIVATE glad)
endif()
if(VCPKG_TARGET_TRIPLET)
target_link_libraries(sdl_service SDL2::SDL2 SDL2::SDL2main SDL2::SDL2-static)
target_link_libraries(sdl_service
PUBLIC
SDL2::SDL2
PRIVATE
SDL2::SDL2main
SDL2::SDL2-static
)
endif()
if(BUILD_TESTING)

View File

@ -18,11 +18,6 @@ target_link_libraries(simple_sdl_renderer_service
sdl_service
)
if(EMSCRIPTEN)
set_target_properties(simple_sdl_renderer_service PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(simple_sdl_renderer_service PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
if (BUILD_TESTING)
add_subdirectory(test)
endif()

View File

@ -15,8 +15,3 @@ target_link_libraries(fast_sky_sun_system
common_components
)
if(EMSCRIPTEN)
set_target_properties(fast_sky_sun_system PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(fast_sky_sun_system PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()

View File

@ -17,11 +17,6 @@ target_link_libraries(player_velocity_system
input_service
)
if(EMSCRIPTEN)
set_target_properties(player_velocity_system PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
set_target_properties(player_velocity_system PROPERTIES LINK_FLAGS "-s USE_SDL=2")
endif()
if (BUILD_TESTING)
add_subdirectory(test)
endif()