examples : refactor common code

This commit is contained in:
Georgi Gerganov
2020-11-29 18:21:57 +02:00
parent fb02177c96
commit 88e9ed79f0
7 changed files with 123 additions and 105 deletions

View File

@@ -1,5 +1,35 @@
# dependencies
find_package(Threads REQUIRED)
if (GGWAVE_SUPPORT_SDL2)
# SDL2
if (EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "-s ALLOW_MEMORY_GROWTH=1 -s USE_SDL=2 -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"writeArrayToMemory\"]'")
unset(SDL2_INCLUDE_DIRS)
unset(SDL2_LIBRARIES)
endif()
if (NOT EMSCRIPTEN)
find_package(SDL2)
if (NOT USE_FINDSDL2 AND NOT SDL2_FOUND)
message(WARNING "Unable to find SDL2 library. It is either not installed or CMake cannot find it."
" In the latter case, setting the USE_FINDSDL2 variable might help:\n"
" $ cmake -D USE_FINDSDL2 .."
)
message(FATAL_ERROR "Aborting")
endif()
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
message(STATUS "SDL2_INCLUDE_DIRS = ${SDL2_INCLUDE_DIRS}")
message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}")
endif()
endif()
# third-party
add_subdirectory(third-party)
@@ -14,42 +44,19 @@ target_link_libraries(ggwave-common PRIVATE
)
if (GGWAVE_SUPPORT_SDL2)
# SDL2
if (EMSCRIPTEN)
set (CMAKE_CXX_FLAGS "-s ALLOW_MEMORY_GROWTH=1 -s USE_SDL=2 -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"writeArrayToMemory\"]'")
endif()
# ggwave-common-sdl2
add_library(ggwave-common-sdl2 ${GGWAVE_LIBRARY_TYPE}
ggwave-common-sdl2.cpp
)
if (NOT EMSCRIPTEN)
find_package(SDL2)
if (NOT USE_FINDSDL2 AND NOT SDL2_FOUND)
message(WARNING "Unable to find SDL2 library. It is either not installed or CMake cannot find it."
" In the latter case, setting the USE_FINDSDL2 variable might help:\n"
" $ cmake -D USE_FINDSDL2 .."
)
message(FATAL_ERROR "Aborting")
endif()
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
endif()
message(STATUS "SDL2_INCLUDE_DIRS = ${SDL2_INCLUDE_DIRS}")
message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}")
# ggwave-common-sdl2
target_include_directories(ggwave-common-sdl2 PUBLIC
${SDL2_INCLUDE_DIRS}
)
target_link_libraries(ggwave-common-sdl2 PRIVATE
ggwave
imgui-sdl2
${SDL2_LIBRARIES}
)
endif()