-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
156 lines (144 loc) · 5.73 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
# CMakeLists.txt
#
# This file is for building classlib using CMake configuration
# and build tool. Download CMake from http://www.cmake.org.
PROJECT(CLASSLIB C CXX)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cfg)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckCXXSourceRuns)
# Options.
SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries instead of static ones.")
OPTION(CLASSLIB_BUILD_TESTS "Build tests." OFF)
OPTION(CLASSLIB_DEBUGGING "Validation (ASSERTs)." ON)
OPTION(CLASSLIB_LOGGING "Logging (LOG)." ON)
# Externals.
FIND_PACKAGE(BZip2)
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(PCRE)
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(LZO)
FIND_PACKAGE(LZMA)
# Default to "release with debug info", i.e. "-O2 -g".
IF(NOT CMAKE_CONFIGURATION_TYPE AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Build type: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
ENDIF()
# Flags we need.
IF(${CMAKE_SYSTEM_NAME} MATCHES Linux)
ADD_DEFINITIONS(-D_GNU_SOURCE)
ENDIF()
IF(WIN32)
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0502 -DNOMINMAX -DWIN32_LEAN_AND_MEAN)
IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DCLASSLIB_BUILD_DLL)
ELSE()
ADD_DEFINITIONS(-DCLASSLIB_BUILD_ARCHIVE)
ENDIF()
ENDIF()
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
ADD_DEFINITIONS(-D__STDC_FORMAT_MACROS)
ADD_DEFINITIONS(-D__STDC_LIMIT_MACROS)
IF(NOT CLASSLIB_DEBUGGING)
ADD_DEFINITIONS(-DNDEBUG)
ENDIF()
IF(NOT CLASSLIB_LOGGING)
ADD_DEFINITIONS(-DNLOG)
ENDIF()
# Use ANSI mode for C and stricter compile options with GCC.
SET(CMAKE_C_FLAGS "${CMAKE_ANSI_FLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_FLAGS})
IF(CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-ansi -pedantic -W -Wall -Wno-long-long -Werror)
ELSEIF(MSVC)
ADD_DEFINITIONS(/W3)
ENDIF()
# Check which system-specific extra libraries we need
MACRO(LOCATE_SYMBOL_IN SYMBOL EXTLIBS VARIABLE)
CHECK_FUNCTION_EXISTS(${SYMBOL} ${VARIABLE}_DEFAULT)
IF(NOT ${VARIABLE}_DEFAULT)
FOREACH(EXTLIB ${EXTLIBS})
CHECK_LIBRARY_EXISTS("${EXTLIB};${CLASSLIB_LIBS}" ${SYMBOL} "" ${VARIABLE}_INLIB)
IF(${VARIABLE}_INLIB)
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${EXTLIB})
BREAK()
ENDIF()
ENDFOREACH()
ENDIF()
ENDMACRO()
IF(UNIX)
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${CMAKE_DL_LIBS})
CHECK_SYMBOL_EXISTS(__bss_start "${PROJECT_SOURCE_DIR}/cfg/check-syms.h" CLASSLIB_HAVE_SYM_BSS_START)
CHECK_SYMBOL_EXISTS(__data_start "${PROJECT_SOURCE_DIR}/cfg/check-syms.h" CLASSLIB_HAVE_SYM_DATA_START)
CHECK_SYMBOL_EXISTS(_edata "${PROJECT_SOURCE_DIR}/cfg/check-syms.h" CLASSLIB_HAVE_SYM_EDATA)
CHECK_SYMBOL_EXISTS(_etext "${PROJECT_SOURCE_DIR}/cfg/check-syms.h" CLASSLIB_HAVE_SYM_ETEXT)
CHECK_SYMBOL_EXISTS(_end "${PROJECT_SOURCE_DIR}/cfg/check-syms.h" CLASSLIB_HAVE_SYM_END)
CHECK_INCLUDE_FILES(dlfcn.h CLASSLIB_HAVE_DLFCN_H)
LOCATE_SYMBOL_IN(socket "socket;inet" HAVE_SOCKET)
LOCATE_SYMBOL_IN(gethostbyname "nsl" HAVE_GETHOSTBYNAME)
LOCATE_SYMBOL_IN(clock_gettime "rt" HAVE_CLOCK_GETTIME)
IF(${CMAKE_SYSTEM_NAME} MATCHES AIX)
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} pmapi xlf90)
ENDIF()
ENDIF()
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LZO_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LZMA_INCLUDE_DIR})
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${ZLIB_LIBRARIES})
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${BZIP2_LIBRARIES})
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${PCRE_LIBRARIES})
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${OPENSSL_LIBRARIES})
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${LZO_LIBRARIES})
SET(CLASSLIB_LIBS ${CLASSLIB_LIBS} ${LZMA_LIBRARIES})
#IF(WIN32)
# SET(CLASSLIB_EXTRA_SRC ${CLASSLIB_EXTRA_SRC}
# ext/rx/hashrexp.c ext/rx/rx.c ext/rx/rxanal.c
# ext/rx/rxbasic.c ext/rx/rxbitset.c ext/rx/rxcset.c
# ext/rx/rxdbug.c ext/rx/rxgnucomp.c ext/rx/rxhash.c
# ext/rx/rxnfa.c ext/rx/rxnode.c ext/rx/rxposix.c
# ext/rx/rxsimp.c ext/rx/rxspencer.c ext/rx/rxstr.c
# ext/rx/rxsuper.c ext/rx/rxunfa.c) # ext/rx/rgx.c
#ENDIF()
# Build targets.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/classlib/sysapi/config.h.cmake
${PROJECT_BINARY_DIR}/classlib/sysapi/config.h)
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}")
FILE(GLOB CLASSLIB_SRC "src/*/*.cpp")
ADD_LIBRARY(classlib ${CLASSLIB_SRC} ${CLASSLIB_EXTRA_SRC})
TARGET_LINK_LIBRARIES(classlib ${CLASSLIB_LIBS})
INSTALL(TARGETS classlib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
INSTALL(DIRECTORY classlib DESTINATION include)
INSTALL(FILES ${PROJECT_BINARY_DIR}/classlib/sysapi/config.h
DESTINATION include/classlib/sysapi)
# Tests.
IF(CLASSLIB_BUILD_TESTS)
FILE(GLOB CLASSLIB_TEST_SRC
RELATIVE ${PROJECT_SOURCE_DIR}
"test/*/*[0-9].cpp" "test/*/exa_*.cpp")
CREATE_TEST_SOURCELIST(CLASSLIB_TESTS TestDriver.cpp ${CLASSLIB_TEST_SRC})
ADD_LIBRARY(SharedLibrary01Lib SHARED test/utils/SharedLibrary01Lib.cpp)
ADD_EXECUTABLE(classlib-test ${CLASSLIB_TESTS})
TARGET_LINK_LIBRARIES(classlib-test classlib ${CLASSLIB_LIB})
SET(CLASSLIB_TESTS_TO_RUN ${CLASSLIB_TEST_SRC})
REMOVE(CLASSLIB_TESTS_TO_RUN TestDriver.cpp)
FOREACH(TEST ${CLASSLIB_TESTS_TO_RUN})
STRING(REPLACE // / TEST "${TEST}")
STRING(REPLACE / _ TEST_NAME "${TEST}")
STRING(REPLACE .cpp "" TEST_NAME "${TEST_NAME}")
GET_FILENAME_COMPONENT(TEST_FILE ${TEST} NAME_WE)
ADD_TEST(${TEST_FILE} ${CXX_TEST_PATH}/classlib-test ${TEST_FILE})
SET_TESTS_PROPERTIES(${TEST_FILE} PROPERTIES ENVIRONMENT "QUIET_ASSERT=a")
SET_SOURCE_FILES_PROPERTIES(${TEST} PROPERTIES COMPILE_FLAGS "-DTEST_NAME=${TEST_NAME}")
# PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH?
ENDFOREACH()
ENDIF()