Skip to content

Commit

Permalink
Started emscripten Cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Surer committed May 18, 2022
1 parent 4f17157 commit 659e703
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 104 deletions.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ if(${BUILD_TARGET} STREQUAL client)

if(${BUILD_PLATFORM} STREQUAL wasm)
set(BUILDPATH "${BUILDPATH}/Wasm")
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS
"-g0 -O3
-fno-rtti
-Wno-error
-Wno-pthreads-mem-growth
-s WASM=1
-pthread -s PTHREAD_POOL_SIZE=5
-s USE_SDL=2
-s USE_SDL_IMAGE=2
-s SDL2_IMAGE_FORMATS='[\"png\"]'
-s USE_SDL_GFX=2
-s USE_FREETYPE=2
-s ALLOW_MEMORY_GROWTH=1
-s MAX_WEBGL_VERSION=2
-s MIN_WEBGL_VERSION=2
-s FULL_ES2=1
-s FULL_ES3=1
-s WEBSOCKET_URL='wss://pi.thissma.fr:55001'
-s WEBSOCKET_SUBPROTOCOL='binary'
--preload-file data --preload-file src -Wno-unused-command-line-argument")
# MESON_ARGS = --prefix=${PWD}/WASM --cross-file=emscripten-crossfile.txt --default-library=static --buildtype=debug --wrap-mode=nofallback

else()
set(BUILDPATH "${BUILDPATH}/App")
Expand Down
215 changes: 111 additions & 104 deletions OpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -427,121 +427,116 @@ if(NOT UNIX)
endif()

# Define the include DIRs
if(${BUILD_PLATFORM} STREQUAL wasm)
message(STATUS "Configuring wasm include directories")
message(STATUS "Configuring include directories")

include_directories(
${CMAKE_SOURCE_DIR}/Dependencies/glm
)

if (UNIX)#zlib
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
else()
include_directories(
${CMAKE_SOURCE_DIR}/Dependencies/EMSFML/src/SFML/Network
${CMAKE_SOURCE_DIR}/Dependencies/EMSFML/src/SFML/System
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/zlib/include/zlib
)
else()
message(STATUS "Configuring app include directories")
target_link_libraries(${PROJECT_NAME} zlib)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:zlib> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
endif(UNIX)

if (UNIX)#glew
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${GLEW_LIBRARIES})
else()
include_directories(
${CMAKE_SOURCE_DIR}/Dependencies/glm
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include
)
target_link_libraries(${PROJECT_NAME} glew)

if (UNIX)#zlib
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:glew> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
endif(UNIX)
if(NOT ${BUILD_PLATFORM} STREQUAL wasm)
if (UNIX)#sfml
find_package(SFML REQUIRED COMPONENTS system network)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-network)
else()
include_directories(
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/zlib/include/zlib
${CMAKE_SOURCE_DIR}/Dependencies/SFML/include
)
target_link_libraries(${PROJECT_NAME} zlib)
target_link_libraries(${PROJECT_NAME} openal32 sfml-network sfml-system)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:zlib> $<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:openal32> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
endif(UNIX)

if (UNIX)#glew
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${GLEW_LIBRARIES})
else()
include_directories(
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:sfml-network> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
target_link_libraries(${PROJECT_NAME} glew)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:glew> $<TARGET_FILE_DIR:${PROJECT_NAME}>
$<TARGET_FILE:sfml-system> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

endif(UNIX)
endif()

if (UNIX)#sfml
find_package(SFML REQUIRED COMPONENTS system network)
target_link_libraries(${PROJECT_NAME} sfml-system sfml-network)
if(${BUILD_TARGET} STREQUAL client)
message(STATUS "Configuring client include directories")
cmake_policy(SET CMP0072 NEW) # OpenGL GLVND
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})

if (UNIX)#sdl2
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
else()
include_directories(
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/SFML/include
${CMAKE_SOURCE_DIR}/Dependencies/SDL2/include
)
target_link_libraries(${PROJECT_NAME} openal32 sfml-network sfml-system)
target_link_libraries(${PROJECT_NAME} SDL2_image SDL2 SDL2main)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:openal32> $<TARGET_FILE_DIR:${PROJECT_NAME}>
$<TARGET_FILE:SDL2_image> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:sfml-network> $<TARGET_FILE_DIR:${PROJECT_NAME}>
$<TARGET_FILE:SDL2> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:sfml-system> $<TARGET_FILE_DIR:${PROJECT_NAME}>
$<TARGET_FILE:libpng16-16> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

endif(UNIX)

if(${BUILD_TARGET} STREQUAL client)

cmake_policy(SET CMP0072 NEW) # OpenGL GLVND
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})

if (UNIX)#sdl2
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
else()
include_directories(
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/SDL2/include
)
target_link_libraries(${PROJECT_NAME} SDL2_image SDL2 SDL2main)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:SDL2_image> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:SDL2> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:libpng16-16> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:zlib1> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:zlib1> $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

endif(UNIX)
endif(UNIX)

if(NOT ${BUILD_PLATFORM} STREQUAL wasm)
if (UNIX)#sfml
find_package(SFML REQUIRED COMPONENTS audio)
target_link_libraries(${PROJECT_NAME} sfml-audio)
Expand All @@ -558,41 +553,53 @@ else()
)

endif(UNIX)
endif()

if (UNIX)#freetype
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${FREETYPE_LIBRARIES})
else()
include_directories(
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/Freetype/include
)
target_link_libraries(${PROJECT_NAME} freetype)
if (UNIX)#freetype
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${FREETYPE_LIBRARIES})
else()
include_directories(
${PROJECT_NAME}
${CMAKE_SOURCE_DIR}/Dependencies/Freetype/include
)
target_link_libraries(${PROJECT_NAME} freetype)

endif(UNIX)
endif(UNIX)

#add missing folders
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data/img $<TARGET_FILE_DIR:${PROJECT_NAME}>/data/img
)
#add missing folders
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data/img $<TARGET_FILE_DIR:${PROJECT_NAME}>/data/img
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data/music $<TARGET_FILE_DIR:${PROJECT_NAME}>/data/music
)
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data/music $<TARGET_FILE_DIR:${PROJECT_NAME}>/data/music
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data/fonts $<TARGET_FILE_DIR:${PROJECT_NAME}>/data/fonts
)
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data/fonts $<TARGET_FILE_DIR:${PROJECT_NAME}>/data/fonts
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/src/shader $<TARGET_FILE_DIR:${PROJECT_NAME}>/src/shader
)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/src/shader $<TARGET_FILE_DIR:${PROJECT_NAME}>/src/shader
)
else() #server

if(${BUILD_PLATFORM} STREQUAL wasm)
message(STATUS "Configuring wasm include directories")
include_directories(
${CMAKE_SOURCE_DIR}/Dependencies/EMSFML/src/SFML/Network
${CMAKE_SOURCE_DIR}/Dependencies/EMSFML/src/SFML/System
)

endif()

else() #server
message(STATUS "Configuring server include directories")
endif()

0 comments on commit 659e703

Please sign in to comment.