edit
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / websocketpp-0.7.0 / CMakeLists.txt
1
2 ############ Setup project and cmake
3
4 # Project name
5 project (websocketpp)
6
7 # Minimum cmake requirement. We should require a quite recent
8 # cmake for the dependency find macros etc. to be up to date.
9 cmake_minimum_required (VERSION 2.6)
10
11 set (WEBSOCKETPP_MAJOR_VERSION 0)
12 set (WEBSOCKETPP_MINOR_VERSION 7)
13 set (WEBSOCKETPP_PATCH_VERSION 0)
14 set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION})
15
16 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
17
18 set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
19 if (WIN32 AND NOT CYGWIN)
20   set (DEF_INSTALL_CMAKE_DIR cmake)
21 else ()
22   set (DEF_INSTALL_CMAKE_DIR lib/cmake/websocketpp)
23 endif ()
24 set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
25
26 # Make relative paths absolute (needed later on)
27 foreach (p INCLUDE CMAKE)
28   set (var INSTALL_${p}_DIR)
29   if (NOT IS_ABSOLUTE "${${var}}")
30     set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
31   endif ()
32 endforeach ()
33
34 # Set CMake library search policy
35 if (COMMAND cmake_policy)
36     cmake_policy (SET CMP0003 NEW)
37     cmake_policy (SET CMP0005 NEW)
38 endif ()
39
40 # Disable unnecessary build types
41 set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Configurations" FORCE)
42
43 # Include our cmake macros
44 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
45 include (CMakeHelpers)
46
47 ############ Paths
48
49 set (WEBSOCKETPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
50 set (WEBSOCKETPP_INCLUDE ${WEBSOCKETPP_ROOT}/websocketpp)
51 set (WEBSOCKETPP_BUILD_ROOT ${CMAKE_CURRENT_BINARY_DIR})
52 set (WEBSOCKETPP_BIN ${WEBSOCKETPP_BUILD_ROOT}/bin)
53 set (WEBSOCKETPP_LIB ${WEBSOCKETPP_BUILD_ROOT}/lib)
54
55 # CMake install step prefix. I assume linux users want the prefix to
56 # be the default /usr or /usr/local so this is only adjusted on Windows.
57 # - Windows: Build the INSTALL project in your solution file.
58 # - Linux/OSX: make install.
59 if (MSVC)
60     set (CMAKE_INSTALL_PREFIX "${WEBSOCKETPP_ROOT}/install")
61 endif ()
62
63 ############  Build customization
64
65 # Override from command line "CMake -D<OPTION>=TRUE/FALSE/0/1/ON/OFF"
66 option (ENABLE_CPP11 "Build websocketpp with CPP11 features enabled." TRUE)
67 option (BUILD_EXAMPLES "Build websocketpp examples." FALSE)
68 option (BUILD_TESTS "Build websocketpp tests." FALSE)
69
70 if (BUILD_TESTS OR BUILD_EXAMPLES)
71
72     enable_testing ()
73
74     ############ Compiler specific setup
75
76     set (WEBSOCKETPP_PLATFORM_LIBS "")
77     set (WEBSOCKETPP_PLATFORM_TLS_LIBS "")
78     set (WEBSOCKETPP_BOOST_LIBS "")
79
80     # VC9 and C++11 reasoning
81     if (ENABLE_CPP11 AND MSVC AND MSVC90)
82         message("* Detected Visual Studio 9 2008, disabling C++11 support.")
83         set (ENABLE_CPP11 FALSE)
84     endif ()
85
86     # Detect clang. Not officially reported by cmake.
87     execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-v" ERROR_VARIABLE CXX_VER_STDERR)
88     if ("${CXX_VER_STDERR}" MATCHES ".*clang.*")
89         set (CMAKE_COMPILER_IS_CLANGXX 1)
90     endif ()
91
92     # C++11 defines
93     if (ENABLE_CPP11)
94         if (MSVC)
95             add_definitions (-D_WEBSOCKETPP_CPP11_FUNCTIONAL_)
96             add_definitions (-D_WEBSOCKETPP_CPP11_SYSTEM_ERROR_)
97             add_definitions (-D_WEBSOCKETPP_CPP11_RANDOM_DEVICE_)
98             add_definitions (-D_WEBSOCKETPP_CPP11_MEMORY_)
99         else()
100             add_definitions (-D_WEBSOCKETPP_CPP11_STL_)
101         endif()
102     endif ()
103
104     # Visual studio
105     if (MSVC)
106         set (WEBSOCKETPP_BOOST_LIBS system thread)
107         set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gy /GF /Ox /Ob2 /Ot /Oi /MP /arch:SSE2 /fp:fast")
108         set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
109         add_definitions (/W3 /wd4996 /wd4995 /wd4355)
110         add_definitions (-DUNICODE -D_UNICODE)
111         add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
112         add_definitions (-DNOMINMAX)
113     endif ()
114
115     # g++
116     if (CMAKE_COMPILER_IS_GNUCXX)
117         set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
118         set (WEBSOCKETPP_PLATFORM_TLS_LIBS ssl crypto)
119         set (WEBSOCKETPP_BOOST_LIBS system thread)
120         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
121         if (NOT APPLE)
122             add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these?
123         endif ()
124
125         # Try to detect version. Note: Not tested!
126         execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION)
127         if ("${GCC_VERSION}" STRGREATER "4.4.0")
128             message("* C++11 support partially enabled due to GCC version ${GCC_VERSION}")
129             set (WEBSOCKETPP_BOOST_LIBS system thread)
130         endif ()
131     endif ()
132
133     # clang
134     if (CMAKE_COMPILER_IS_CLANGXX)
135         if (NOT APPLE)
136             set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
137         else()
138             set (WEBSOCKETPP_PLATFORM_LIBS pthread)
139         endif()
140         set (WEBSOCKETPP_PLATFORM_TLS_LIBS ssl crypto)
141         set (WEBSOCKETPP_BOOST_LIBS system thread)
142         set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x -stdlib=libc++") # todo: is libc++ really needed here?
143         if (NOT APPLE)
144             add_definitions (-DNDEBUG -Wall -Wno-padded) # todo: should we use CMAKE_C_FLAGS for these?
145         endif ()
146     endif ()
147
148     # OSX, can override above.
149     if (APPLE)
150         add_definitions (-DNDEBUG -Wall)
151     endif ()
152
153     if (BUILD_EXAMPLES)
154         list (APPEND WEBSOCKETPP_BOOST_LIBS random)
155     endif()
156
157     if (BUILD_TESTS)
158         list (APPEND WEBSOCKETPP_BOOST_LIBS unit_test_framework)
159     endif()
160
161     ############ Dependencies
162
163     # Set BOOST_ROOT env variable or pass with cmake -DBOOST_ROOT=path.
164     # BOOST_ROOT can also be defined by a previous run from cmake cache.
165     if (NOT "$ENV{BOOST_ROOT_CPP11}" STREQUAL "")
166         # Scons documentation for BOOST_ROOT_CPP11:
167         # "look for optional second boostroot compiled with clang's libc++ STL library
168         # this prevents warnings/errors when linking code built with two different
169         # incompatible STL libraries."
170         file (TO_CMAKE_PATH "$ENV{BOOST_ROOT_CPP11}" BOOST_ROOT)
171         set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
172     endif ()
173     if ("${BOOST_ROOT}" STREQUAL "")
174         file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" BOOST_ROOT)
175         # Cache BOOST_ROOT for runs that do not define $ENV{BOOST_ROOT}.
176         set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
177     endif ()
178
179     message ("* Configuring Boost")
180     message (STATUS "-- Using BOOST_ROOT")
181     message (STATUS "       " ${BOOST_ROOT})
182
183     if (MSVC)
184         set (Boost_USE_MULTITHREADED TRUE)
185         set (Boost_USE_STATIC_LIBS TRUE)
186     else ()
187         set (Boost_USE_MULTITHREADED FALSE)
188         set (Boost_USE_STATIC_LIBS FALSE)
189     endif ()
190
191         if (BOOST_STATIC)
192                 set (Boost_USE_STATIC_LIBS TRUE)
193         endif ()
194
195     if (NOT Boost_USE_STATIC_LIBS)
196         add_definitions (/DBOOST_TEST_DYN_LINK)
197     endif ()
198
199     set (Boost_FIND_REQUIRED TRUE)
200     set (Boost_FIND_QUIETLY TRUE)
201     set (Boost_DEBUG FALSE)
202     set (Boost_USE_MULTITHREADED TRUE)
203     set (Boost_ADDITIONAL_VERSIONS "1.39.0" "1.40.0" "1.41.0" "1.42.0" "1.43.0" "1.44.0" "1.46.1") # todo: someone who knows better spesify these!
204
205     find_package (Boost 1.39.0 COMPONENTS "${WEBSOCKETPP_BOOST_LIBS}")
206
207     if (Boost_FOUND)
208         # Boost is a project wide global dependency.
209         include_directories (${Boost_INCLUDE_DIRS})
210         link_directories (${Boost_LIBRARY_DIRS})
211
212         # Pretty print status
213         message (STATUS "-- Include Directories")
214         foreach (include_dir ${Boost_INCLUDE_DIRS})
215             message (STATUS "       " ${include_dir})
216         endforeach ()
217         message (STATUS "-- Library Directories")
218         foreach (library_dir ${Boost_LIBRARY_DIRS})
219             message (STATUS "       " ${library_dir})
220         endforeach ()
221         message (STATUS "-- Libraries")
222         foreach (boost_lib ${Boost_LIBRARIES})
223             message (STATUS "       " ${boost_lib})
224         endforeach ()
225         message ("")
226     else ()
227         message (FATAL_ERROR "Failed to find required dependency: boost")
228     endif ()
229
230     find_package(OpenSSL)
231     find_package(ZLIB)
232 endif()
233
234 ############ Add projects
235
236 # Add main library
237 add_subdirectory (websocketpp)
238
239 # Add examples
240 if (BUILD_EXAMPLES)
241     include_subdirs ("examples")
242 endif ()
243
244 # Add tests
245 if (BUILD_TESTS)
246     include_subdirs ("test")
247 endif ()
248
249 print_used_build_config()
250
251 export (PACKAGE websocketpp)
252
253 configure_file (websocketpp-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake" @ONLY)
254 configure_file (websocketpp-configVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake" @ONLY)
255
256 # Install the websocketpp-config.cmake and websocketpp-configVersion.cmake
257 install (FILES
258   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-config.cmake"
259   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/websocketpp-configVersion.cmake"
260   DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
261