forked from jeaye/color_coded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
158 lines (129 loc) · 3.8 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
cmake_minimum_required(VERSION 2.8)
project(color_coded)
option(DOWNLOAD_CLANG "Download pre-built clang+llvm" TRUE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# Shut up the warning about CMake policy CMP0042.
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
message(STATUS "Found 32bit system")
set(64_BIT_PLATFORM 0)
else()
message(STATUS "Found 64bit system")
set(64_BIT_PLATFORM 1)
endif()
# Add custom find modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Submodules
message(STATUS "Updating submodules")
execute_process(
COMMAND git submodule update --recursive --init
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
# C++14
include(cmake/cxx14.cmake)
# Boost
include(cmake/boost.cmake)
# Lua
include(cmake/lua.cmake)
# Curses
find_package(Curses REQUIRED)
# ZLib
find_package(ZLIB REQUIRED)
# PThread
find_package(Threads REQUIRED)
if (NOT DOWNLOAD_CLANG)
find_package(LLVM)
if(LLVM_FOUND)
find_package(LibClang)
else()
message(STATUS "LLVM not found on system")
endif()
endif()
if ((NOT LLVM_FOUND) OR (NOT CLANG_FOUND) OR (${DOWNLOAD_CLANG}))
set(DOWNLOAD_CLANG 1)
include(cmake/clang/download.cmake)
find_package(LLVM REQUIRED)
find_package(LibClang REQUIRED)
endif()
include_directories(
include
${LLVM_INCLUDE_DIRS}
${CLANG_INCLUDE_DIRS}
${CURSES_INCLUDE_PATH}
${ZLIB_INCLUDE_PATH}
$ENV{PWD}/include/
)
# Allow easier dynamic linking with clang
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH ${LLVM_LIB_PATH})
include(cmake/generate_sources.cmake)
include(cmake/check_luajit.cmake)
add_library(${PROJECT_NAME} SHARED src/main.cpp)
add_custom_target(${PROJECT_NAME}_track_api
COMMAND ${CMAKE_CURRENT_LIST_DIR}/lib/track_api
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_track_api)
# Force the same naming across platforms
set_property(TARGET ${PROJECT_NAME} PROPERTY PREFIX "")
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "${PROJECT_NAME}.so")
set_property(TARGET ${PROJECT_NAME} PROPERTY SUFFIX "")
# Enable warnings
set(WARNING_FLAGS
"-Wall -Wextra -pedantic -Wno-missing-field-initializers -Wno-unused-variable -Wno-deprecated-declarations -Wno-unused-parameter"
)
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_FLAGS ${WARNING_FLAGS})
# Fix compilation problem: relocation R_X86_64_32 against `a local symbol' can not be
# used when making a shared object; recompile with -fPIC.
# See http://www.cmake.org/pipermail/cmake/2007-May/014350.html
if(64_BIT_PLATFORM)
set_property(TARGET ${PROJECT_NAME}_boost PROPERTY COMPILE_FLAGS "-fPIC")
endif()
target_link_libraries(${PROJECT_NAME}
${CLANG_LIBS}
${LLVM_LIBRARIES}
${LLVM_LDFLAGS}
)
target_link_libraries(${PROJECT_NAME}
${PROJECT_NAME}_boost
${LUA_LIBRARIES}
${CURSES_LIBRARY}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
# Install locally
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR})
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_CURRENT_LIST_DIR})
# Tests
include_directories(
lib/jest/include
test/include
)
add_definitions(
-D__STDC_CONSTANT_MACROS
-D__STDC_LIMIT_MACROS
)
if(${DOWNLOAD_CLANG})
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()
add_executable(${PROJECT_NAME}_config_test ${CMAKE_CURRENT_LIST_DIR}/test/src/config/main.cpp)
target_link_libraries(${PROJECT_NAME}_config_test
${CLANG_LIBS}
${LLVM_LIBRARIES}
${LLVM_LDFLAGS}
${PROJECT_NAME}_boost
${LUA_LIBRARIES}
${CURSES_LIBRARY}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
set_property(TARGET ${PROJECT_NAME}_config_test PROPERTY COMPILE_FLAGS ${WARNING_FLAGS})
add_custom_target(${PROJECT_NAME}_test
COMMAND ${PROJECT_NAME}_config_test
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
add_dependencies(${PROJECT_NAME}_test ${PROJECT_NAME}_config_test)