From 4d0f731d8d9fe30d26f2df0d82b50281589f35db Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 30 Oct 2022 16:36:17 +0100 Subject: [PATCH] better cmake for emscripten flags --- external/glm.cmake | 1 + external/imgui/CMakeLists.txt | 18 +++++++++++------ external/soloud/CMakeLists.txt | 16 ++++++++++----- framework/filesystem/CMakeLists.txt | 16 ++++++++++----- .../filesystem/src/mm/services/filesystem.cpp | 1 + framework/input/CMakeLists.txt | 9 +++------ framework/opengl_primitives/CMakeLists.txt | 15 +++++++------- framework/opengl_renderer/CMakeLists.txt | 6 ------ framework/sdl_service/CMakeLists.txt | 20 ++++++++++++------- framework/simple_sdl_renderer/CMakeLists.txt | 5 ----- systems/fast_sky_sun/CMakeLists.txt | 5 ----- systems/player_velocity/CMakeLists.txt | 5 ----- 12 files changed, 59 insertions(+), 58 deletions(-) diff --git a/external/glm.cmake b/external/glm.cmake index 8eea6a4..fa6b0f3 100644 --- a/external/glm.cmake +++ b/external/glm.cmake @@ -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) diff --git a/external/imgui/CMakeLists.txt b/external/imgui/CMakeLists.txt index 0a6ee90..cf2a781 100644 --- a/external/imgui/CMakeLists.txt +++ b/external/imgui/CMakeLists.txt @@ -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) diff --git a/external/soloud/CMakeLists.txt b/external/soloud/CMakeLists.txt index e4cf347..1ecf903 100644 --- a/external/soloud/CMakeLists.txt +++ b/external/soloud/CMakeLists.txt @@ -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() diff --git a/framework/filesystem/CMakeLists.txt b/framework/filesystem/CMakeLists.txt index e3eeac4..1697d54 100644 --- a/framework/filesystem/CMakeLists.txt +++ b/framework/filesystem/CMakeLists.txt @@ -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() diff --git a/framework/filesystem/src/mm/services/filesystem.cpp b/framework/filesystem/src/mm/services/filesystem.cpp index c300242..ef7c9ea 100644 --- a/framework/filesystem/src/mm/services/filesystem.cpp +++ b/framework/filesystem/src/mm/services/filesystem.cpp @@ -33,6 +33,7 @@ bool FilesystemService::enable(Engine&, std::vector& 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 diff --git a/framework/input/CMakeLists.txt b/framework/input/CMakeLists.txt index fabf47e..2c020b9 100644 --- a/framework/input/CMakeLists.txt +++ b/framework/input/CMakeLists.txt @@ -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) diff --git a/framework/opengl_primitives/CMakeLists.txt b/framework/opengl_primitives/CMakeLists.txt index 5e43a5d..723ae66 100644 --- a/framework/opengl_primitives/CMakeLists.txt +++ b/framework/opengl_primitives/CMakeLists.txt @@ -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) diff --git a/framework/opengl_renderer/CMakeLists.txt b/framework/opengl_renderer/CMakeLists.txt index 92d413f..f56b30b 100644 --- a/framework/opengl_renderer/CMakeLists.txt +++ b/framework/opengl_renderer/CMakeLists.txt @@ -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 diff --git a/framework/sdl_service/CMakeLists.txt b/framework/sdl_service/CMakeLists.txt index 4ca7020..2640b33 100644 --- a/framework/sdl_service/CMakeLists.txt +++ b/framework/sdl_service/CMakeLists.txt @@ -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) diff --git a/framework/simple_sdl_renderer/CMakeLists.txt b/framework/simple_sdl_renderer/CMakeLists.txt index c3612f7..63dd1a3 100644 --- a/framework/simple_sdl_renderer/CMakeLists.txt +++ b/framework/simple_sdl_renderer/CMakeLists.txt @@ -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() diff --git a/systems/fast_sky_sun/CMakeLists.txt b/systems/fast_sky_sun/CMakeLists.txt index 692dbb9..d09e333 100644 --- a/systems/fast_sky_sun/CMakeLists.txt +++ b/systems/fast_sky_sun/CMakeLists.txt @@ -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() - diff --git a/systems/player_velocity/CMakeLists.txt b/systems/player_velocity/CMakeLists.txt index d7aaf25..2956650 100644 --- a/systems/player_velocity/CMakeLists.txt +++ b/systems/player_velocity/CMakeLists.txt @@ -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()