-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
163 lines (138 loc) · 5.03 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
160
161
cmake_minimum_required(VERSION 3.4)
project(io CXX)
include_directories(include)
include_directories(include/net)
# for pre-compiled headers
include_directories(src)
file(GLOB PROJECT_SOURCE_PATH ${PROJECT_SOURCE_DIR}/src)
file(GLOB COMMON_SRC ${PROJECT_SOURCE_PATH}/stdafx.hpp ${PROJECT_SOURCE_PATH}/*.cpp ${PROJECT_SOURCE_PATH}/net/*.cpp)
set(EXTRA_LIBS)
set(CMAKE_BINARY_DIR target)
if( WIN32 OR MSYS OR CYGWIN)
message( STATUS "Building IO for Microsoft Windows")
include_directories(include/win)
file(GLOB PLATFORM_SRC ${PROJECT_SOURCE_PATH}/win/*.cpp)
add_definitions(-D_WIN32_WINNT=0x0600)
if(MSYS OR CYGWIN)
set(THREADING threadwin)
endif()
list(APPEND EXTRA_LIBS Ws2_32)
elseif( UNIX AND NOT WIN32 AND NOT MSYS AND NOT CYGWIN)
message( STATUS "Building IO for UNIX/POSIX ")
include_directories(include/posix)
file(GLOB PLATFORM_SRC ${PROJECT_SOURCE_PATH}/posix/*.cpp)
set(THREADING thread)
list(APPEND EXTRA_LIBS pthread)
endif()
find_package(Boost 1.23.0)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
if(MSVC)
add_definitions(/DIO_HAS_BOOST)
else()
add_definitions(-DIO_HAS_BOOST)
endif()
endif()
# Dependencies
#GnuTLS is not exist for MS VC++
if( NOT MSVC )
# TODO: Use another library, this one is no longer stabile on Windows
if(NOT MSYS AND NOT CYGWIN)
find_package(GnuTLS 3.0)
if(GNUTLS_FOUND)
add_definitions(-DIO_TLS_PROVIDER_GNUTSL ${GNUTLS_DEFINITIONS} )
include_directories(${GNUTLS_INCLUDE_DIR})
list(APPEND EXTRA_LIBS ${GNUTLS_LIBRARIES})
list(APPEND PLATFORM_SRC ${PROJECT_SOURCE_PATH}/tls/gnutls_secure_channel.cpp)
endif(GNUTLS_FOUND) # GNU TLS
endif()
else()
list(APPEND EXTRA_LIBS kernel32.lib)
list(APPEND EXTRA_LIBS user32.lib)
list(APPEND EXTRA_LIBS Ws2_32.lib)
endif()
if(MSYS OR CYGWIN)
find_package(Iconv REQUIRED)
elseif(MSVC)
set(Iconv_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/deps/msvc/include")
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(Iconv_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/deps/msvc/x64/iconv.lib")
endif()
endif()
include_directories(${Iconv_INCLUDE_DIR})
list(APPEND EXTRA_LIBS ${Iconv_LIBRARY})
if( ${CMAKE_BUILD_TYPE} STREQUAL "Release" )
add_definitions(-DNDEBUG)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Release/lib)
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Debug/lib)
endif()
if(BUILD_SHARED_LIBS)
add_library(io SHARED ${COMMON_SRC} ${PLATFORM_SRC})
else()
add_library(io STATIC ${COMMON_SRC} ${PLATFORM_SRC})
endif()
if( CMAKE_COMPILER_IS_GNUCXX )
target_link_libraries(io ${EXTRA_LIBS})
if(BUILD_SHARED_LIBS)
add_definitions(-DIO_SHARED_LIB -DIO_BUILD)
set_target_properties(io PROPERTIES LINKER_LANGUAGE CXX)
endif()
if( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(CPU_SPECIFIC_FLAGS "-minline-stringops-dynamically -mavx -mavx2 -mlzcnt -mmovbe")
else()
set(CPU_SPECIFIC_FLAGS "")
endif()
set(RELEASE_OPTIMIZE_FLAGS "-mtune=generic -s -O3 -fdeclone-ctor-dtor -fdevirtualize-at-ltrans -fwhole-program ${CPU_SPECIFIC_FLAGS}")
if(NO_EXCEPTIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif()
if(NO_RTTI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
set (CMAKE_CXX_STANDARD 17)
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8)
set (CMAKE_CXX_STANDARD 14)
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.1)
set (CMAKE_CXX_STANDARD 11)
else()
message( SEND_ERROR "GCC 4.2+ required")
endif()
if( (WIN32 OR MSYS OR CYGWIN) AND BUILD_SHARED_LIBS )
set(LTO_FLAGS "-flto -Wl,-allow-multiple-definition")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${LTO_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS} -s ${LTO_FLAGS} ${RELEASE_OPTIMIZE_FLAGS}")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${RELEASE_OPTIMIZE_FLAGS}" )
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -Og")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /c /nologo /utf-8 /std:c++latest")
add_definitions(/DUNICODE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /O2 /Oi /Gw /Zc:wchar_t")
if(BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_definitions(/DIO_SHARED_LIB)
add_definitions(/DIO_BUILD)
list(APPEND EXTRA_LIBS msvcrt.lib)
list(APPEND EXTRA_LIB vcruntime.lib)
target_link_libraries(io ${EXTRA_LIBS})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /Zl")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MD")
target_link_libraries(io ${EXTRA_LIBS})
endif()
if(NOT NO_EXCEPTIONS OR BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS AND NO_EXCEPTIONS)
message(SEND_ERROR "Could not build no exceptions DLL from Cmake, use nmake -f NMakefile-msvcx64-dll.mak instead")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
if(NOT NO_RTTI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} /ZI")
endif()