forked from project-z/mutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
123 lines (99 loc) · 3.71 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
set(PROJECT_NAME_STR mutton)
project(${PROJECT_NAME_STR} C CXX)
#-------------------
# The version number
#-------------------
set (libmutton_VERSION_MAJOR 0)
set (libmutton_VERSION_MINOR 5)
set (libmutton_VERSION_STRING ${libmutton_VERSION_MAJOR}.${libmutton_VERSION_MINOR})
#-------------------
# Enable C++11
#-------------------
set(CMAKE_CXX_FLAGS "-Wall -Werror -g3 -O2 -std=c++11 -stdlib=libc++")
#-------------------
# setup deps
#-------------------
set(EXT_PREFIX ${PROJECT_SOURCE_DIR}/ext)
set(CMAKE_MODULE_PATH ${EXT_PREFIX})
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
else()
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
# UTF8-CPP
set(INCLUDES ${INCLUDES} ${PROJECT_SOURCE_DIR}/ext/utf8/source)
# Boost
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.47.0 REQUIRED)
set(INCLUDES ${INCLUDES} ${Boost_INCLUDE_DIRS} )
# Threading
find_package(Threads)
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT} )
# LevelDB
include(leveldb)
# CityHash
find_path(CityHash_INCLUDE_DIRS NAMES city.h HINTS /usr/include /usr/local/include)
find_library(CityHash_LIBRARIES NAMES libcityhash.a libcityhash.lib libcityhash.dylib HINTS /usr/lib /usr/local/lib)
if(CityHash_INCLUDE_DIRS AND CityHash_LIBRARIES)
set(CityHash_FOUND TRUE)
endif(CityHash_INCLUDE_DIRS AND CityHash_LIBRARIES)
if(CityHash_FOUND)
message(STATUS "Found CityHash: ${CityHash_LIBRARIES}")
else(CityHash_FOUND)
message(FATAL_ERROR "Could not find CityHash library.")
endif(CityHash_FOUND)
set(INCLUDES ${INCLUDES} ${CityHash_INCLUDE_DIRS} )
set(LIBS ${LIBS} ${CityHash_LIBRARIES} )
# Lua 5.1
find_package(Lua51 REQUIRED)
set(INCLUDES ${INCLUDES} ${LUA_INCLUDE_DIR} )
set(LIBS ${LIBS} ${LUA_LIBRARIES} )
add_custom_target (AppDependencies ALL
DEPENDS ${APP_DEPENDENCIES}
COMMENT "Installing any missing dependencies.")
#-------------------
# libmutton static, shared and executable
#-------------------
set(PROJECT_LIB_NAME ${PROJECT_NAME_STR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "build/bin/")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin)
set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
include_directories(${INCLUDES} ${PROJECT_INCLUDE_DIR}/libmutton ${PROJECT_SOURCE_DIR}/src)
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
add_library(${PROJECT_LIB_NAME} SHARED ${SRC_FILES})
add_library(${PROJECT_LIB_NAME}-static STATIC ${SRC_FILES})
target_link_libraries(${PROJECT_LIB_NAME} ${LIBS})
SET_TARGET_PROPERTIES(${PROJECT_LIB_NAME}-static PROPERTIES OUTPUT_NAME ${PROJECT_LIB_NAME})
SET_TARGET_PROPERTIES(${PROJECT_LIB_NAME} PROPERTIES VERSION ${libmutton_VERSION_MAJOR}.${libmutton_VERSION_MINOR} SOVERSION ${libmutton_VERSION_MAJOR})
#-------------------
# install target
#-------------------
FILE(GLOB INSTALL_HEADERS "${PROJECT_INCLUDE_DIR}/libmutton/*.hpp")
INSTALL(FILES ${INSTALL_HEADERS} DESTINATION include/libmutton)
INSTALL(TARGETS ${PROJECT_LIB_NAME}-static ${PROJECT_LIB_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
#-------------------
# uninstall target
#-------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
#-------------------
# unit tests
#-------------------
enable_testing()
add_subdirectory(test/unit)
#-------------------
# the demo program
#-------------------
# add_subdirectory(src/demo EXCLUDE_FROM_ALL)