forked from cloudwu/pbc
-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
130 lines (109 loc) · 4.29 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
cmake_minimum_required(VERSION 3.1.0)
cmake_policy(SET CMP0054 NEW)
project(pbc C)
#####################################################################
# output
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
# compiler
if( ${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
add_definitions(-Wall)
if(NOT WIN32 AND NOT CYGWIN AND NOT MINGW)
add_definitions(-fPIC)
endif()
# just for gcc
if( ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
include(CheckCCompilerFlag)
message(STATUS "Check Flag: -rdynamic -- running")
CHECK_C_COMPILER_FLAG(-rdynamic, C_FLAGS_RDYNAMIC_AVAILABLE)
if(C_FLAGS_RDYNAMIC_AVAILABLE)
message(STATUS "Check Flag: -rdynamic -- yes")
add_definitions(-rdynamic)
else()
message(STATUS "Check Flag: -rdynamic -- no")
endif()
# gcc 4.9 and output with color
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.9.0" OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL "4.9.0" )
add_definitions(-fdiagnostics-color=auto)
endif()
endif()
endif()
# Compile flags
if (MSVC)
if(NOT CMAKE_MSVC_RUNTIME)
set(CMAKE_MSVC_RUNTIME "MD")
endif()
list(APPEND CMAKE_C_FLAGS /TP) # force using c++ compiler
list(APPEND CMAKE_C_FLAGS_DEBUG /${CMAKE_MSVC_RUNTIME}d)
list(APPEND CMAKE_C_FLAGS_RELEASE /${CMAKE_MSVC_RUNTIME} /D NDEBUG)
list(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO /${CMAKE_MSVC_RUNTIME}d)
list(APPEND CMAKE_C_FLAGS_MINSIZEREL /${CMAKE_MSVC_RUNTIME} /D NDEBUG)
else()
list(APPEND CMAKE_C_FLAGS_DEBUG -ggdb)
#list(APPEND CMAKE_C_FLAGS_RELEASE)
list(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO -ggdb)
#list(APPEND CMAKE_C_FLAGS_MINSIZEREL)
endif()
# add custom define
macro(add_compiler_define)
foreach(def ${ARGV})
if ( NOT MSVC )
add_definitions(-D${def})
else()
add_definitions("/D ${def}")
endif()
endforeach()
endmacro(add_compiler_define)
if(NOT CMAKE_BUILD_TYPE)
#set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
# convert list to parameters
string(REPLACE ";" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE ";" " " CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE ";" " " CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE ";" " " CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE ";" " " CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
string(REPLACE ";" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
########################################################################
##
## archives and executable files
##
########################################################################
include_directories(${CMAKE_CURRENT_LIST_DIR})
## libpbc.a
set(LIBNAME "pbc")
add_subdirectory(src)
add_custom_target(lib ALL DEPENDS ${LIBNAME})
## tool
if(CYGWIN OR MINGW OR UNIX)
# it use getopt which is only available in UNIX like environment
add_subdirectory(tool)
endif()
## test
find_package(Protobuf)
if (Protobuf_FOUND)
message(STATUS "Test: protobuf found at ${Protobuf_PROTOC_EXECUTABLE}, enable test sub-project now.")
add_subdirectory(test)
endif()
## Lua - binding
if (LUA_INCLUDE_DIR AND LUA_VERSION_STRING AND (CMAKE_OSX_SYSROOT OR LUA_LIBRARIES))
set(LUA_FOUND YES)
else ()
find_package(Lua)
endif()
if (LUA_FOUND)
message(STATUS "Lua: ${LUA_VERSION_STRING} found.INC=${LUA_INCLUDE_DIR},LIB=${LUA_LIBRARIES}")
## Lua 5.3
if ("5.2" VERSION_LESS ${LUA_VERSION_STRING})
message(STATUS "Lua Binding: using binding/lua53 for lua-binding")
add_subdirectory(binding/lua53)
else() ## Lua 5.1 or LuaJIT
message(STATUS "Lua Binding: using binding/lua for lua-binding")
add_subdirectory(binding/lua)
endif()
endif()