Skip to content

Commit 2c10737

Browse files
committed
- CMake
- 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)
1 parent 9430ab7 commit 2c10737

File tree

5 files changed

+66
-39
lines changed

5 files changed

+66
-39
lines changed

CMakeLists.txt

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
cmake_minimum_required(VERSION 2.6)
1313

14-
project(SLikeNet)
15-
16-
# specify the project version number
17-
set(SLikeNet_VERSION "0.2.0")
18-
set(SLikeNet_API_VERSION "0.2")
19-
2014
# CMake policy settings
2115
if( POLICY CMP0037 )
2216
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)
@@ -25,6 +19,15 @@ if( POLICY CMP0042 )
2519
cmake_policy(SET CMP0042 NEW) # CMake 3.0 warning: Use @rpath in a target's install name.
2620
endif()
2721

22+
project(SLikeNet)
23+
24+
# version number
25+
set(SLikeNet_VERSION_MAJOR "0")
26+
set(SLikeNet_VERSION_MINOR "2")
27+
set(SLikeNet_VERSION_PATCH "0")
28+
set(SLikeNet_VERSION ${SLikeNet_VERSION_MAJOR}.${SLikeNet_VERSION_MINOR}.${SLikeNet_VERSION_PATCH})
29+
set(SLikeNet_API_VERSION ${SLikeNet_VERSION_MAJOR}.${SLikeNet_VERSION_MINOR})
30+
2831
# 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)
2932
# note that for cmake < 2.8.12 we do not use rpath but rather keep the RakNet 4.082 behavior
3033
if( CMAKE_VERSION VERSION_LESS 3.0 )
@@ -54,36 +57,36 @@ if(COMPILER_SUPPORTS_CXX11)
5457
elseif(COMPILER_SUPPORTS_CXX0X)
5558
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
5659
else()
57-
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
60+
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
5861
endif()
5962

60-
# Options
63+
# options
6164
IF (WIN32 AND NOT UNIX)
62-
option( SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." TRUE )
65+
option(SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." TRUE)
6366
ELSE (WIN32 AND NOT UNIX)
6467
# building samples is disabled atm by default on Unix/Mac, since the sample projects won't compile correctly
65-
option( SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." FALSE )
68+
option(SLIKENET_ENABLE_SAMPLES "Generate sample projects if true." FALSE)
6669
ENDIF(WIN32 AND NOT UNIX)
67-
option( SLIKENET_ENABLE_DLL "Generate the DLL / shared object project if true." TRUE )
68-
option( SLIKENET_ENABLE_STATIC "Generate the static library project if true." TRUE )
69-
option( SLIKENET_GENERATE_INCLUDE_ONLY_DIR "Setup an include/slikenet/ directory in which all the headers are copied." FALSE )
70+
option(SLIKENET_ENABLE_DLL "Generate the DLL / shared object project if true." TRUE)
71+
option(SLIKENET_ENABLE_STATIC "Generate the static library project if true." TRUE)
72+
option(SLIKENET_GENERATE_INCLUDE_ONLY_DIR "Setup an include/slikenet/ directory in which all the headers are copied." FALSE)
7073

71-
set( SLIKENET_HEADER_FILES ${SLikeNet_SOURCE_DIR}/Source )
74+
set(SLIKENET_HEADER_FILES ${SLikeNet_SOURCE_DIR}/Source)
7275

7376
# 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
7477
# since we are planning to add support for RakNet compatibility mode to CMake too, we keep this option
7578
# 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
76-
if( SLIKENET_GENERATE_INCLUDE_ONLY_DIR )
77-
set( SLIKENET_INCLUDE_ONLY_DIR ${SLikeNet_SOURCE_DIR}/include ) # this will be visible by client code
78-
set( SLIKENET_NAMED_INCLUDE_ONLY_DIR ${SLIKENET_INCLUDE_ONLY_DIR}/slikenet )
79-
message( STATUS "Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory..." )
79+
if(SLIKENET_GENERATE_INCLUDE_ONLY_DIR)
80+
set(SLIKENET_INCLUDE_ONLY_DIR ${SLikeNet_SOURCE_DIR}/include) # this will be visible by client code
81+
set(SLIKENET_NAMED_INCLUDE_ONLY_DIR ${SLIKENET_INCLUDE_ONLY_DIR}/slikenet)
82+
message(STATUS "Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory...")
8083

8184
# Now setup the include/slikenet directory.
82-
file( MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} )
83-
file( MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR}/crypto )
84-
file( COPY ${SLIKENET_HEADER_FILES}/include/slikenet DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} )
85-
file( COPY ${SLIKENET_HEADER_FILES}/include/slikenet/crypto DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} )
86-
message( STATUS "DONE: Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory." )
85+
file(MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR})
86+
file(MAKE_DIRECTORY ${SLIKENET_NAMED_INCLUDE_ONLY_DIR}/crypto)
87+
file(COPY ${SLIKENET_HEADER_FILES}/include/slikenet DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR})
88+
file(COPY ${SLIKENET_HEADER_FILES}/include/slikenet/crypto DESTINATION ${SLIKENET_NAMED_INCLUDE_ONLY_DIR})
89+
message(STATUS "DONE: Setting up the ${SLIKENET_NAMED_INCLUDE_ONLY_DIR} directory.")
8790
endif()
8891

8992
include(./CmakeIncludes/CmakeMacros.txt)

Lib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
2020
endif()
2121

2222
set(SLIKENET_INTERNAL_INCLUDE_DIRS
23-
${SLikeNet_SOURCE_DIR}/Source/include
23+
${SLikeNet_SOURCE_DIR}/Source/include
2424
${SLikeNet_SOURCE_DIR}/DependentExtensions/openssl/include/${SLIKENET_OPENSSL_INCLUDE_PREFIX}/release
2525
${SLikeNet_SOURCE_DIR}/DependentExtensions
2626
)

Lib/DLL/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC ${SLikeNet_SOURCE_DIR}/Source/*.h)
1818
FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC_2 ${SLikeNet_SOURCE_DIR}/Source/slikenet/*.h)
1919
FILE(GLOB ALL_CPP_SRCS ${SLikeNet_SOURCE_DIR}/Source/src/*.cpp)
2020

21-
include_directories( ${SLIKENET_INTERNAL_INCLUDE_DIRS} )
22-
2321
add_library(SLikeNetDLL SHARED ${ALL_CPP_SRCS} ${ALL_HEADER_SRCS})
2422

23+
#if(NOT (CMAKE_VERSION VERSION_LESS 2.8))
24+
# target_include_directories is only supported since CMake 2.8
25+
# target_include_directories(SLikeNetLibDLL PUBLIC
26+
# $<BUILD_INTERFACE:${SLIKENET_INTERNAL_INCLUDE_DIRS}>
27+
# $<INSTALL_INTERFACE:include/slikenet-${SLikeNet_VERSION}>
28+
# )
29+
#else()
30+
include_directories(${SLIKENET_INTERNAL_INCLUDE_DIRS})
31+
#endif()
32+
2533
# set the version number
2634
set_target_properties(SLikeNetDLL PROPERTIES
2735
VERSION ${SLikeNet_VERSION}
@@ -40,10 +48,14 @@ ELSE(WIN32 AND NOT UNIX)
4048
)
4149
ENDIF(WIN32 AND NOT UNIX)
4250

43-
target_link_libraries (SLikeNetDLL ${SLIKENET_LIBRARY_LIBS})
51+
target_link_libraries(SLikeNetDLL ${SLIKENET_LIBRARY_LIBS})
4452
IF(NOT WIN32 OR UNIX)
45-
install(TARGETS SLikeNetDLL DESTINATION lib)
46-
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet)
47-
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet/slikenet)
48-
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet/include/slikenet)
53+
configure_file(../../slikenet-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake @ONLY)
54+
55+
install(TARGETS SLikeNetDLL EXPORT SLikeNetDLL DESTINATION lib/slikenet-${SLikeNet_VERSION})
56+
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet-${SLikeNet_VERSION})
57+
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet-${SLikeNet_VERSION}/slikenet/slikenet)
58+
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet-${SLikeNet_VERSION}/slikenet/include/slikenet)
59+
INSTALL(FILES ../../slikenet-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake DESTINATION lib/slikenet-${SLikeNet_VERSION})
60+
INSTALL(EXPORT SLikeNetDLL DESTINATION lib/slikenet-${SLikeNet_VERSION})
4961
ENDIF(NOT WIN32 OR UNIX)

Lib/LibStatic/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC ${SLikeNet_SOURCE_DIR}/Source/*.h)
1818
FILE(GLOB ALL_COMPATIBILITY_HEADER_SRC_2 ${SLikeNet_SOURCE_DIR}/Source/slikenet/*.h)
1919
FILE(GLOB ALL_CPP_SRCS ${SLikeNet_SOURCE_DIR}/Source/src/*.cpp)
2020

21-
include_directories( ${SLIKENET_INTERNAL_INCLUDE_DIRS} )
22-
2321
add_library(SLikeNetLibStatic STATIC ${ALL_CPP_SRCS} ${ALL_HEADER_SRCS})
2422

23+
#if(NOT (CMAKE_VERSION VERSION_LESS 2.8))
24+
# target_include_directories is only supported since CMake 2.8
25+
# target_include_directories(SLikeNetLibStatic PUBLIC
26+
# $<BUILD_INTERFACE:${SLIKENET_INTERNAL_INCLUDE_DIRS}>
27+
# $<INSTALL_INTERFACE:include/slikenet-${SLikeNet_VERSION}>
28+
# )
29+
#else()
30+
include_directories(${SLIKENET_INTERNAL_INCLUDE_DIRS})
31+
#endif()
32+
2533
# set the version number
2634
set_target_properties(SLikeNetLibStatic PROPERTIES
2735
VERSION ${SLikeNet_VERSION}
@@ -40,14 +48,18 @@ ELSE(WIN32 AND NOT UNIX)
4048
)
4149
ENDIF(WIN32 AND NOT UNIX)
4250

43-
target_link_libraries (SLikeNetLibStatic ${SLIKENET_LIBRARY_LIBS})
51+
target_link_libraries(SLikeNetLibStatic ${SLIKENET_LIBRARY_LIBS})
4452
IF(WIN32 AND NOT UNIX)
4553
IF(NOT ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles")
4654
set_target_properties(SLikeNetLibStatic PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB:\"LIBCD.lib LIBCMTD.lib MSVCRT.lib\"" )
4755
ENDIF(NOT ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles")
4856
ELSE(WIN32 AND NOT UNIX)
49-
INSTALL(TARGETS SLikeNetLibStatic DESTINATION lib)
50-
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet)
51-
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet/slikenet)
52-
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet/include/slikenet)
57+
configure_file(../../slikenet-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake @ONLY)
58+
59+
INSTALL(TARGETS SLikeNetLibStatic EXPORT SLikeNetLibStatic DESTINATION lib/slikenet-${SLikeNet_VERSION})
60+
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC} DESTINATION include/slikenet-${SLikeNet_VERSION})
61+
INSTALL(FILES ${ALL_COMPATIBILITY_HEADER_SRC_2} DESTINATION include/slikenet-${SLikeNet_VERSION}/slikenet)
62+
INSTALL(FILES ${ALL_HEADER_SRCS} DESTINATION include/slikenet-${SLikeNet_VERSION}/include/slikenet)
63+
INSTALL(FILES ../../slikenet-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/slikenet-config-version.cmake DESTINATION lib/slikenet-${SLikeNet_VERSION})
64+
INSTALL(EXPORT SLikeNetLibStatic FILE slikenet.cmake DESTINATION lib/slikenet-${SLikeNet_VERSION})
5365
ENDIF(WIN32 AND NOT UNIX)

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Building:
5555
* 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)
5656
CMake:
5757
* changed the project names from RakNetXXXX -> SLikeNetXXXX (#222)
58-
* changed default install location for SLikeNet to CMAKE_INSTALL_PREFIX-based include/lib directories (#54 - RAKNET_29, #67 - RAKNET_41)
58+
* changed default install location for SLikeNet to CMAKE_INSTALL_PREFIX-based include/lib directories (#54 - RAKNET_29, #67 - RAKNET_41, #222)
5959
* changed default library names on Linux/OSX to use libslikenet.so / libslikenet.a and create related symlinks (#189 - RAKNET_86)
6060
* changed install target directory for include files to use include/slikenet (instead of include/raknet) (#222)
6161
* changed default configuration to build the retail version instead of the release one (#222)

0 commit comments

Comments
 (0)