Skip to content

Commit

Permalink
Added ENET library to dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
klei1984 committed Nov 6, 2023
1 parent eefcf8e commit 4b90f80
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
)

if(NOT BUILD_SHARED_LIBS)
set(${PROJECT_NAME}_deps SDL2::SDL2main Iconv::Iconv Freetype::Freetype Miniaudio::Miniaudio SDL2::SDL2-static SDL2_net::SDL2_net-static)
set(${PROJECT_NAME}_deps SDL2::SDL2main Iconv::Iconv Freetype::Freetype Miniaudio::Miniaudio Enet::Enet SDL2::SDL2-static SDL2_net::SDL2_net-static)

target_link_options(${PROJECT_NAME} PUBLIC -static -static-libgcc -static-libstdc++)
target_link_libraries(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_deps})
else()
set(${PROJECT_NAME}_deps SDL2::SDL2main Iconv::Iconv Freetype::Freetype Miniaudio::Miniaudio SDL2::SDL2 SDL2_net::SDL2_net)
set(${PROJECT_NAME}_deps SDL2::SDL2main Iconv::Iconv Freetype::Freetype Miniaudio::Miniaudio Enet::Enet SDL2::SDL2 SDL2_net::SDL2_net)

target_link_libraries(${PROJECT_NAME} PRIVATE ${${PROJECT_NAME}_deps})
endif()
Expand All @@ -45,6 +45,9 @@ include(sdl2_net)
include(freetype)
include(miniaudio)

set(ENET_RELEASE ON)
include(enet)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ARGS --only-keep-debug $<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.debug
COMMAND ${CMAKE_STRIP} ARGS --strip-debug --strip-unneeded $<TARGET_FILE:${PROJECT_NAME}>
Expand Down
43 changes: 43 additions & 0 deletions cmake/enet.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
include(versions)
include(FetchContent)

if(ENET_RELEASE)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/${ENET_FILE})
file(${ENET_HASH_TYPE} ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/${ENET_FILE} ENET_FILE_HASH)

if(${ENET_FILE_HASH} STREQUAL ${ENET_HASH})
set(ENET_URI file://${CMAKE_CURRENT_SOURCE_DIR}/dependencies/${ENET_FILE})
endif()
endif()

FetchContent_Declare(
ENET
TIMEOUT 60
URL ${ENET_URI}
URL_HASH ${ENET_HASH_TYPE}=${ENET_HASH}
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
OVERRIDE_FIND_PACKAGE
)
else()
FetchContent_Declare(
ENET
TIMEOUT 60
GIT_REPOSITORY ${ENET_REPOSITORY}
GIT_TAG ${ENET_TAG}
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
OVERRIDE_FIND_PACKAGE
)
endif()

FetchContent_MakeAvailable(ENET)

set(ENET_BINARY_DIR ${PROJECT_BINARY_DIR}/_deps/enet-build)
set(ENET_SOURCE_DIR ${PROJECT_BINARY_DIR}/_deps/enet-src)

file(COPY ${ENET_SOURCE_DIR}/include DESTINATION ${ENET_BINARY_DIR})

set_property(TARGET enet APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ENET_BINARY_DIR}/include")

if(NOT TARGET Enet::Enet)
add_library(Enet::Enet ALIAS enet)
endif()
6 changes: 6 additions & 0 deletions cmake/versions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ set(SDL2_NET_URI https://github.com/libsdl-org/SDL_net/releases/download/release
set(SDL2_NET_HASH ba1cc690ddde85ee90c80e15be9f3bf9)
set(SDL2_NET_HASH_TYPE MD5)

set(ENET_VERSION 1.3.17)
set(ENET_FILE enet-${ENET_VERSION}.tar.gz)
set(ENET_URI https://github.com/lsalzman/enet/archive/refs/tags/${ENET_VERSION}.tar.gz)
set(ENET_HASH 1c3270f1e03ccb2a8544a88d91d2a368)
set(ENET_HASH_TYPE MD5)

set(GTEST_VERSION 1.14.0)
set(GTEST_FILE googletest-${GTEST_VERSION}.tar.gz)
set(GTEST_URI https://github.com/google/googletest/archive/refs/tags/v${GTEST_VERSION}.tar.gz)
Expand Down

0 comments on commit 4b90f80

Please sign in to comment.