This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
186 lines (152 loc) · 5.91 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
cmake_minimum_required(VERSION 3.0)
project(libhelium)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-scripts)
include(CheckIncludeFiles)
include(CheckFunctionExists)
# Build with blocks by default. If you don't have clang it'll whine at you.
option(BLOCKS "BLOCKS" ON)
set(VERSION_MAJOR "0")
set(VERSION_MINOR "1")
set(VERSION_PATCH "0")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
add_definitions(-DLIBHELIUM_VERSION="${VERSION}")
add_definitions(-D_GNU_SOURCE) # you need this or libuv will not be happy
add_definitions(-DHAVE_CONFIG_H)
set(Crypto_FIND_REQUIRED 1)
find_package(uv)
find_package(openssl)
find_package(crypto)
find_package(cunit)
if(WIN32)
set(MATH_LIB "")
else()
find_library(MATH_LIB m)
endif(WIN32)
if(BLOCKS AND NOT APPLE)
find_package(blocksruntime)
endif(BLOCKS AND NOT APPLE)
set(HELIUM_INCLUDES
include
${CMAKE_CURRENT_BINARY_DIR}/include/
)
set(HELIUM_LIBS ${OPENSSL_LIBRARIES} ${MATH_LIB} ${HELIUM_LIBS} ${UV_LIBRARIES} ${CRYPTO_LIBRARIES})
set(HELIUM_INCLUDES ${OPENSSL_INCLUDE_DIR} ${HELIUM_INCLUDES} ${UV_INCLUDE_DIR} ${CRYPTO_INCLUDE_DIR} )
if(BLOCKS AND BLOCKS_FOUND)
set(HELIUM_LIBS ${HELIUM_LIBS} ${CBLOCKS_LIBRARIES})
set(HELIUM_INCLUDES ${HELIUM_INCLUDES} ${CBLOCKS_INCLUDE_DIR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks")
endif(BLOCKS AND BLOCKS_FOUND)
CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
CHECK_INCLUDE_FILES("stdarg.h" HAVE_STDARG_H)
CHECK_INCLUDE_FILES("stddef.h" HAVE_STDDEF_H)
CHECK_INCLUDE_FILES("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILES("stdlib.h" HAVE_STDLIB_H)
CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES("locale.h" HAVE_LOCALE_H)
CHECK_FUNCTION_EXISTS(localeconv HAVE_LOCALECONV)
CHECK_FUNCTION_EXISTS(lconv_decimal_point HAVE_LCONV_DECIMAL_POINT)
CHECK_FUNCTION_EXISTS(lconv_thousands_sep HAVE_LCONV_THOUSANDS_SEP)
if((${CMAKE_C_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_C_COMPILER_ID} STREQUAL "GNU"))
set(CMAKE_C_FLAGS "-Wall -pedantic -Werror -std=c90 -funsigned-char -Wno-long-long")
endif((${CMAKE_C_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_C_COMPILER_ID} STREQUAL "GNU"))
configure_file ("include/config.h.in"
"include/config.h" )
set(HELIUM_SOURCE_FILES
src/logging.c
src/hashmap.c
src/helium.c
src/snprintf.c
include/helium.h
include/helium_logging.h
include/helium_internal.h)
set(HELIUM_HEADER_FILES
include/helium_logging.h
include/helium.h)
if(CMAKE_C_COMPILER_ID MATCHES "clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks -fsanitize=undefined")
add_definitions(-DHAVE_BLOCKS=1)
else()
add_definitions(-DHAVE_BLOCKS=0)
endif(CMAKE_C_COMPILER_ID MATCHES "clang")
if(WIN32)
include(GenerateExportHeader)
set(HELIUM_LIBS ${HELIUM_LIBS} ws2_32 psapi iphlpapi)
endif()
if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCMTD.lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:LIBCMTD.lib")
endif()
add_library(helium SHARED ${HELIUM_SOURCE_FILES})
if(WIN32)
generate_export_header(helium)
else()
add_library(heliumStatic STATIC ${HELIUM_SOURCE_FILES})
set_target_properties(heliumStatic PROPERTIES OUTPUT_NAME helium)
target_include_directories(heliumStatic PUBLIC ${HELIUM_INCLUDES})
target_link_libraries(heliumStatic PUBLIC ${HELIUM_LIBS})
target_compile_options(heliumStatic PUBLIC "-fPIC")
endif()
target_include_directories(helium PUBLIC ${HELIUM_INCLUDES})
target_link_libraries(helium PUBLIC ${HELIUM_LIBS})
# fPIC is needed to link a static lib to a shared object
target_compile_options(helium PUBLIC "-fPIC")
install(TARGETS helium DESTINATION lib)
if(NOT WIN32)
install(TARGETS heliumStatic DESTINATION lib)
endif()
install(FILES ${HELIUM_HEADER_FILES} DESTINATION include)
set(SAMPLE_INCLUDES
${PROJECT_SOURCE_DIR}/include
${OPENSSL_INCLUDE_DIR}
${UV_INCLUDE_DIR}
${CRYPTO_INCLUDE_DIR})
set(SAMPLE_LIBRARIES
${MATH_LIB}
${OPENSSL_LIBRARIES}
${UV_LIBRARIES}
${CRYPTO_LIBRARIES})
IF(UNIX)
set(SAMPLE_LIBRARIES $<TARGET_LINKER_FILE:heliumStatic> ${SAMPLE_LIBRARIES})
ENDIF(UNIX)
if(WIN32)
set(SAMPLE_LIBRARIES ${SAMPLE_LIBRARIES} Debug/helium)
endif()
set(TEST_LIBRARIES
${CUNIT_LIBRARY}
${SAMPLE_LIBRARIES})
add_executable(shell samples/shell.c)
add_dependencies(shell helium)
target_include_directories(shell PUBLIC ${SAMPLE_INCLUDES})
target_link_libraries(shell PUBLIC ${SAMPLE_LIBRARIES})
add_executable(multiloop_test samples/multiloop_test.c)
add_dependencies(multiloop_test helium)
target_include_directories(multiloop_test PUBLIC ${SAMPLE_INCLUDES})
target_link_libraries(multiloop_test PUBLIC ${SAMPLE_LIBRARIES})
if(CUNIT_FOUND)
enable_testing()
add_executable(test_basic tests/test_basic.c)
add_dependencies(test_basic helium)
target_include_directories(test_basic PUBLIC ${SAMPLE_INCLUDES})
target_link_libraries(test_basic PUBLIC ${TEST_LIBRARIES})
add_test(test_basic test_basic)
add_executable(test_base64 tests/test_base64.c)
add_dependencies(test_base64 helium)
target_include_directories(test_base64 PUBLIC ${SAMPLE_INCLUDES})
target_link_libraries(test_base64 PUBLIC ${TEST_LIBRARIES})
add_test(test_base64 test_base64)
add_executable(modem_test tests/modem_test.c)
add_dependencies(modem_test helium)
target_include_directories(modem_test PUBLIC ${SAMPLE_INCLUDES})
target_link_libraries(modem_test PUBLIC ${TEST_LIBRARIES})
add_test(modem_test modem_test)
endif(CUNIT_FOUND)
find_package(Doxygen)
if (DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.out @ONLY)
add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.out WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
COMMENT "Generating API documentation with Doxygen" )
endif(DOXYGEN_FOUND)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake")