forked from cmarshall108/hCraft-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
117 lines (97 loc) · 3 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
#
# hCraft's CMakeLists file.
#
IF (NOT ${CMAKE_BUILD_TYPE})
SET(CMAKE_BUILD_TYPE "Release")
ENDIF()
MESSAGE(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(hCraft2)
FILE(GLOB_RECURSE hCraft2_Headers ${CMAKE_SOURCE_DIR}/include/*.hpp)
FILE(GLOB_RECURSE hCraft2_SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/)
SET(LIB_SUFFIX "64")
INCLUDE_DIRECTORIES(include/)
ADD_EXECUTABLE(hCraft2 ${hCraft2_SOURCES} ${hCraft2_Headers})
IF (WIN32)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) # for windows
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()
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
ENDIF()
#
# Dependencies.
#
#-------------------------------------------------------------------------------
# libevent
SET(LibEvent_FIND_REQUIRED TRUE)
FIND_PACKAGE(LibEvent)
INCLUDE_DIRECTORIES(${LIBEVENT_INCLUDE_DIR})
# pthreads
IF (NOT WIN32)
FIND_PACKAGE(Threads)
ELSE()
UNSET(CMAKE_THREAD_LIBS_INIT)
ENDIF()
# Winsock & WinHTTP
IF (WIN32)
SET(WS2_LIB ws2_32)
SET(HTTP_LIB winhttp)
ENDIF()
# libcurl
IF (NOT WIN32)
FIND_PACKAGE(CURL)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
ENDIF()
# zlib
IF (WIN32)
SET(ZLIB_LIBRARIES ${CMAKE_SOURCE_DIR}/win32/lib/zdll.lib)
SET(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/win32/include)
ADD_CUSTOM_COMMAND(TARGET hCraft2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/win32/lib/zlib1.dll"
$<TARGET_FILE_DIR:hCraft2>)
ELSE()
FIND_PACKAGE(ZLIB)
ENDIF()
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
# Crypto++
IF (WIN32)
SET(CRYPTOPP_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/win32/include)
IF (${CMAKE_BUILD_TYPE} STREQUAL "Release")
SET(CRYPTOPP_LIBRARIES ${CMAKE_SOURCE_DIR}/win32/lib/Release/cryptlib.lib)
ELSE()
SET(CRYPTOPP_LIBRARIES ${CMAKE_SOURCE_DIR}/win32/lib/Debug/cryptlib.lib)
ENDIF()
ELSE()
FIND_PACKAGE(CryptoPP)
ENDIF()
INCLUDE_DIRECTORIES(${CRYPTOPP_INCLUDE_DIR})
#-------------------------------------------------------------------------------
TARGET_LINK_LIBRARIES(hCraft2 ${LIBEVENT_LIB} ${LIBEVENT_PTHREADS_LIB}
${CMAKE_THREAD_LIBS_INIT} ${WS2_LIB} ${HTTP_LIB} ${ZLIB_LIBRARIES}
${CRYPTOPP_LIBRARIES} ${CURL_LIBRARIES})
# linux stuff
IF (NOT WIN32)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
IF(COMPILER_SUPPORTS_CXX11)
MESSAGE(STATUS "C++11 enabled")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -Wall")
IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
ENDIF()
ENDIF()