forked from modio/modio-sdk-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
159 lines (131 loc) · 5.26 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
cmake_minimum_required(VERSION 3.5)
set (CMAKE_OSX_DEPLOYMENT_TARGET "10.4")
project(modio)
set (CMAKE_CXX_STANDARD 11)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Set this to ON if you want to enable testing
option(TEST "Enable UNIT TESTING" OFF)
# set BUILD_SHARED_LIBs to OFF to compile statically, for example:
# cmake -D BUILD_SHARED_LIBS=OFF .
option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
# set INCLUDE_EXAMPLES to ON to include the examples in the project
option(INCLUDE_EXAMPLES "Build examples" OFF)
# This needs to happen early, so that we force the build to be static
IF(TEST)
message("Testing enabled, disabling shared libraries to be able to access internal functions")
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build Shared Libraries" FORCE)
# To be able to link with google test suite
set(crtmode "static" CACHE STRING "" FORCE)
ENDIF()
# MSVC: set the crtmode flag to 'static' to include the Visual C++
# runtime statically. Requires libcurl to be built with /MT as well.
# cmake -D crtmode=static .
include_directories(include additional_dependencies include/dependencies/miniz include/dependencies/filesystem include/dependencies/utf8)
file(GLOB_RECURSE SOURCES
"src/*.cpp"
"src/*.c"
"src/*.h"
"include/*.h")
message(${CMAKE_SOURCE_DIR})
# Make pretty folders in visual studio/xcode
foreach(source IN LISTS SOURCES)
get_filename_component(source_path "${source}" PATH)
string(REPLACE ${CMAKE_SOURCE_DIR} "" source_path_folder ${source_path} )
string(REPLACE "/" "\\" source_path_folder "${source_path_folder}")
string(REPLACE ${CMAKE_SOURCE_DIR} "" source_path_folder ${source_path_folder} )
source_group("${source_path_folder}" FILES "${source}")
endforeach()
add_library(modio ${SOURCES})
if( BUILD_SHARED_LIBS )
message("Building mod.io SDK dynamically")
add_definitions(-DMODIO_DYNAMICLIB -DCURL_STATICLIB)
else()
message("Building mod.io SDK statically")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_definitions(-DMODIO_STATICLIB -DCURL_STATICLIB)
endif()
IF (APPLE)
find_package(CURL REQUIRED)
target_link_libraries(modio ${CURL_LIBRARIES})
ENDIF()
IF (UNIX AND NOT APPLE)
add_definitions(-D_LARGEFILE64_SOURCE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
target_link_libraries (modio curl)
ENDIF ()
IF (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE)
target_link_libraries(modio ws2_32.lib wldap32.lib advapi32.lib kernel32.lib comdlg32.lib crypt32.lib normaliz.lib )
IF (crtmode AND crtmode STREQUAL "static")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_link_libraries(modio ${CMAKE_CURRENT_SOURCE_DIR}/lib/MSVC/x64/static/libcurl_a.lib)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_link_libraries(modio ${CMAKE_CURRENT_SOURCE_DIR}/lib/MSVC/x86/static/libcurl_a.lib)
endif()
ELSE()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_link_libraries(modio ${CMAKE_CURRENT_SOURCE_DIR}/lib/MSVC/x64/libcurl_a.lib)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_link_libraries(modio ${CMAKE_CURRENT_SOURCE_DIR}/lib/MSVC/x86/libcurl_a.lib)
endif()
ENDIF()
ENDIF()
IF(TEST)
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/test/*.cpp)
# This is needed to get release compiling
SET(gtest_force_shared_crt ON)
add_subdirectory(ext/googletest-master)
enable_testing()
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(runUnitTests ${TEST_SRC_FILES})
target_link_libraries(runUnitTests gtest gtest_main modio)
add_test(UnitTests runUnitTests)
ENDIF()
if( INCLUDE_EXAMPLES )
set(CPP_EXAMPLE_DIR "examples/code-samples/cpp")
set(C_EXAMPLE_DIR "examples/code-samples/c")
add_subdirectory(${CPP_EXAMPLE_DIR})
add_subdirectory(${C_EXAMPLE_DIR})
add_custom_command(TARGET modio POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:modio> "${CMAKE_CURRENT_BINARY_DIR}/${CPP_EXAMPLE_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:modio> "${CMAKE_CURRENT_BINARY_DIR}/${C_EXAMPLE_DIR}"
COMMENT "Copying library binaries into examples dir..."
)
# Copy pdb's on platforms that support it
IF (MSVC)
IF(BUILD_SHARED_LIBS)
add_custom_command(TARGET modio POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:modio> "${CMAKE_CURRENT_BINARY_DIR}/${CPP_EXAMPLE_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PDB_FILE:modio> "${CMAKE_CURRENT_BINARY_DIR}/${C_EXAMPLE_DIR}"
COMMENT "Copying library pdbs into examples dir..."
)
ENDIF()
ENDIF()
endif()
if(BUILD_SHARED_LIBS)
set(PREFIX ${CMAKE_SHARED_MODULE_PREFIX})
set(POSTFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
set(PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
set(POSTFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
# Set properties let projects that use this project as a subdirectory know how to play along with it
set_target_properties(modio
PROPERTIES
PREFIX "${PREFIX}"
OUTPUT_NAME modio
SUFFIX "${POSTFIX}")