Skip to content

Commit

Permalink
- CMake
Browse files Browse the repository at this point in the history
   - added CMake configuration and version configuration support (facebookarchive#132)
   - added slikenet.h to simplify CMake include directory detection (facebookarchive#132)
   - tweaked the way to specify the version number (facebookarchive#132)
   - use version based install directories to support installing multiple versions in parallel (#222)
   - use EXPORT handling for the CMake integration (facebookarchive#132)
   - preps for CMake >= 2.8 make use of target_include_directories() (#222)
   - minor tweaks (facebookarchive#130)
  • Loading branch information
Luke1410 committed Sep 2, 2019
1 parent 9430ab7 commit 2c10737
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
49 changes: 26 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

cmake_minimum_required(VERSION 2.6)

project(SLikeNet)

# specify the project version number
set(SLikeNet_VERSION "0.2.0")
set(SLikeNet_API_VERSION "0.2")

# CMake policy settings
if( POLICY CMP0037 )
cmake_policy(SET CMP0037 NEW) # CMake 3.0 warning: Target names should not be reserved and should match a validity pattern (aka: add_*-command target names)
Expand All @@ -25,6 +19,15 @@ if( POLICY CMP0042 )
cmake_policy(SET CMP0042 NEW) # CMake 3.0 warning: Use @rpath in a target's install name.
endif()

project(SLikeNet)

# version number
set(SLikeNet_VERSION_MAJOR "0")
set(SLikeNet_VERSION_MINOR "2")
set(SLikeNet_VERSION_PATCH "0")
set(SLikeNet_VERSION ${SLikeNet_VERSION_MAJOR}.${SLikeNet_VERSION_MINOR}.${SLikeNet_VERSION_PATCH})
set(SLikeNet_API_VERSION ${SLikeNet_VERSION_MAJOR}.${SLikeNet_VERSION_MINOR})

# explicitly enable @rpath in the install name for any shared library being built (for cmake >=2.8.12 and <3.0 - it's enabled by default for >= 3.0)
# note that for cmake < 2.8.12 we do not use rpath but rather keep the RakNet 4.082 behavior
if( CMAKE_VERSION VERSION_LESS 3.0 )
Expand Down Expand Up @@ -54,36 +57,36 @@ if(COMPILER_SUPPORTS_CXX11)
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

# Options
# options
IF (WIN32 AND NOT UNIX)
option( SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." TRUE )
option(SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." TRUE)
ELSE (WIN32 AND NOT UNIX)
# building samples is disabled atm by default on Unix/Mac, since the sample projects won't compile correctly
option( SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." FALSE )
option(SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." FALSE)
ENDIF(WIN32 AND NOT UNIX)
option( SLIKENET_ENABLE_DLL "Generate the DLL / shared object project if true." TRUE )
option( SLIKENET_ENABLE_STATIC "Generate the static library project if true." TRUE )
option( SLIKENET_GENERATE_INCLUDE_ONLY_DIR "Setup an include/slikenet/ directory in which all the headers are copied." FALSE )
option(SLIKENET_ENABLE_DLL "Generate the DLL / shared object project if true." TRUE)
option(SLIKENET_ENABLE_STATIC "Generate the static library project if true." TRUE)
option(SLIKENET_GENERATE_INCLUDE_ONLY_DIR "Setup an include/slikenet/ directory in which all the headers are copied." FALSE)

set( SLIKENET_HEADER_FILES ${SLikeNet_SOURCE_DIR}/Source )
set(SLIKENET_HEADER_FILES ${SLikeNet_SOURCE_DIR}/Source)

# note: while it's straight forward to get the SLikeNet include files directly from source (since they are cleanly organized under Source/include/slikenet/*), copying the headers in RakNet compatibility mode is not that clear
# since we are planning to add support for RakNet compatibility mode to CMake too, we keep this option
# also the planned addition for making experimental features optional/configurable would require additional logic here, so that there certainly is a purpose for this feature even with the cleaner header file structure in SLikeNet
if( SLIKENET_GENERATE_INCLUDE_ONLY_DIR )
set( SLIKENET_INCLUDE_ONLY_DIR ${SLikeNet_SOURCE_DIR}/include ) # this will be visible by client code
set( SLIKENET_NAMED_INCLUDE_ONLY_DIR ${SLIKENET_INCLUDE_ONLY_DIR}/slikenet )
message( STATUS "Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory..." )
if(SLIKENET_GENERATE_INCLUDE_ONLY_DIR)
set(SLIKENET_INCLUDE_ONLY_DIR ${SLikeNet_SOURCE_DIR}/include) # this will be visible by client code
set(SLIKENET_NAMED_INCLUDE_ONLY_DIR ${SLIKENET_INCLUDE_ONLY_DIR}/slikenet)
message(STATUS "Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory...")

# Now setup the include/slikenet directory.
file( MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} )
file( MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR}/crypto )
file( COPY ${SLIKENET_HEADER_FILES}/include/slikenet DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} )
file( COPY ${SLIKENET_HEADER_FILES}/include/slikenet/crypto DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} )
message( STATUS "DONE: Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory." )
file(MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR})
file(MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR}/crypto)
file(COPY ${SLIKENET_HEADER_FILES}/include/slikenet DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR})
file(COPY ${SLIKENET_HEADER_FILES}/include/slikenet/crypto DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR})
message(STATUS "DONE: Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory.")
endif()

include(./CmakeIncludes/CmakeMacros.txt)
Expand Down
2 changes: 1 addition & 1 deletion Lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()

set(SLIKENET_INTERNAL_INCLUDE_DIRS
${SLikeNet_SOURCE_DIR}/Source/include
${SLikeNet_SOURCE_DIR}/Source/include
${SLikeNet_SOURCE_DIR}/DependentExtensions/openssl/include/${SLIKENET_OPENSSL_INCLUDE_PREFIX}/release
${SLikeNet_SOURCE_DIR}/DependentExtensions
)
Expand Down
26 changes: 19 additions & 7 deletions Lib/DLL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC ${SLikeNet_SOURCE_DIR}/Source/*.h)
FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC_2 ${SLikeNet_SOURCE_DIR}/Source/slikenet/*.h)
FILE(GLOB ALL_CPP_SRCS ${SLikeNet_SOURCE_DIR}/Source/src/*.cpp)

include_directories( ${SLIKENET_INTERNAL_INCLUDE_DIRS} )

add_library(SLikeNetDLL SHARED ${ALL_CPP_SRCS} ${ALL_HEADER_SRCS})

#if(NOT (CMAKE_VERSION VERSION_LESS 2.8))
# target_include_directories is only supported since CMake 2.8
# target_include_directories(SLikeNetLibDLL PUBLIC
# $<BUILD_INTERFACE:${SLIKENET_INTERNAL_INCLUDE_DIRS}>
# $<INSTALL_INTERFACE:include/slikenet-${SLikeNet_VERSION}>
# )
#else()
include_directories(${SLIKENET_INTERNAL_INCLUDE_DIRS})
#endif()

# set the version number
set_target_properties(SLikeNetDLL PROPERTIES
VERSION ${SLikeNet_VERSION}
Expand All @@ -40,10 +48,14 @@ ELSE(WIN32 AND NOT UNIX)
)
ENDIF(WIN32 AND NOT UNIX)

target_link_libraries (SLikeNetDLL ${SLIKENET_LIBRARY_LIBS})
target_link_libraries(SLikeNetDLL ${SLIKENET_LIBRARY_LIBS})
IF(NOT WIN32 OR UNIX)
install(TARGETS SLikeNetDLL DESTINATION lib)
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet)
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet/slikenet)
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet/include/slikenet)
configure_file(../../slikenet-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake @ONLY)

install(TARGETS SLikeNetDLL EXPORT SLikeNetDLL DESTINATION lib/slikenet-${SLikeNet_VERSION})
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet-${SLikeNet_VERSION})
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet-${SLikeNet_VERSION}/slikenet/slikenet)
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet-${SLikeNet_VERSION}/slikenet/include/slikenet)
INSTALL(FILES ../../slikenet-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake DESTINATION lib/slikenet-${SLikeNet_VERSION})
INSTALL(EXPORT SLikeNetDLL DESTINATION lib/slikenet-${SLikeNet_VERSION})
ENDIF(NOT WIN32 OR UNIX)
26 changes: 19 additions & 7 deletions Lib/LibStatic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC ${SLikeNet_SOURCE_DIR}/Source/*.h)
FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC_2 ${SLikeNet_SOURCE_DIR}/Source/slikenet/*.h)
FILE(GLOB ALL_CPP_SRCS ${SLikeNet_SOURCE_DIR}/Source/src/*.cpp)

include_directories( ${SLIKENET_INTERNAL_INCLUDE_DIRS} )

add_library(SLikeNetLibStatic STATIC ${ALL_CPP_SRCS} ${ALL_HEADER_SRCS})

#if(NOT (CMAKE_VERSION VERSION_LESS 2.8))
# target_include_directories is only supported since CMake 2.8
# target_include_directories(SLikeNetLibStatic PUBLIC
# $<BUILD_INTERFACE:${SLIKENET_INTERNAL_INCLUDE_DIRS}>
# $<INSTALL_INTERFACE:include/slikenet-${SLikeNet_VERSION}>
# )
#else()
include_directories(${SLIKENET_INTERNAL_INCLUDE_DIRS})
#endif()

# set the version number
set_target_properties(SLikeNetLibStatic PROPERTIES
VERSION ${SLikeNet_VERSION}
Expand All @@ -40,14 +48,18 @@ ELSE(WIN32 AND NOT UNIX)
)
ENDIF(WIN32 AND NOT UNIX)

target_link_libraries (SLikeNetLibStatic ${SLIKENET_LIBRARY_LIBS})
target_link_libraries(SLikeNetLibStatic ${SLIKENET_LIBRARY_LIBS})
IF(WIN32 AND NOT UNIX)
IF(NOT ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles")
set_target_properties(SLikeNetLibStatic PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB:\"LIBCD.lib LIBCMTD.lib MSVCRT.lib\"" )
ENDIF(NOT ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles")
ELSE(WIN32 AND NOT UNIX)
INSTALL(TARGETS SLikeNetLibStatic DESTINATION lib)
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet)
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet/slikenet)
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet/include/slikenet)
configure_file(../../slikenet-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake @ONLY)

INSTALL(TARGETS SLikeNetLibStatic EXPORT SLikeNetLibStatic DESTINATION lib/slikenet-${SLikeNet_VERSION})
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet-${SLikeNet_VERSION})
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet-${SLikeNet_VERSION}/slikenet)
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet-${SLikeNet_VERSION}/include/slikenet)
INSTALL(FILES ../../slikenet-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake DESTINATION lib/slikenet-${SLikeNet_VERSION})
INSTALL(EXPORT SLikeNetLibStatic FILE slikenet.cmake DESTINATION lib/slikenet-${SLikeNet_VERSION})
ENDIF(WIN32 AND NOT UNIX)
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Building:
* change projects to consistently use warning level 4 in all configurations with Visual Studio (#128, #129, #135, #137, #138, #139, #140, #142, #144, #146, #147, #149, #151, #152, #153, #154, #155, #162)
CMake:
* changed the project names from RakNetXXXX -> SLikeNetXXXX (#222)
* changed default install location for SLikeNet to CMAKE_INSTALL_PREFIX-based include/lib directories (#54 - RAKNET_29, #67 - RAKNET_41)
* changed default install location for SLikeNet to CMAKE_INSTALL_PREFIX-based include/lib directories (#54 - RAKNET_29, #67 - RAKNET_41, #222)
* changed default library names on Linux/OSX to use libslikenet.so / libslikenet.a and create related symlinks (#189 - RAKNET_86)
* changed install target directory for include files to use include/slikenet (instead of include/raknet) (#222)
* changed default configuration to build the retail version instead of the release one (#222)
Expand Down

0 comments on commit 2c10737

Please sign in to comment.