-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
162 lines (132 loc) · 4.78 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
cmake_minimum_required (VERSION 2.6...3.10.2)
project (CGenerator)
cmake_policy(SET CMP0063 NEW)
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
find_package(OpenSSL)
if (OPENSSL_FOUND)
message (STATUS "OPENSSL found")
set(CMAKE_C_FLAGS "-DOPENSSL")
if(CMAKE_VERSION VERSION_LESS 3.4)
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIRS})
link_directories(${OPENSSL_LIBRARIES})
endif()
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
message (STATUS "OpenSSL Not found.")
endif()
set(pkgName "lethean_binary_api")
# this default version can be overridden in PreTarget.cmake
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 1)
find_package(CURL 7.58.0 REQUIRED)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
else(CURL_FOUND)
message(FATAL_ERROR "Could not find the CURL library and development files.")
endif()
set(SRCS
src/list.c
src/apiKey.c
src/apiClient.c
src/binary.c
external/cJSON.c
model/object.c
api/VpnAPI.c
)
set(HDRS
include/apiClient.h
include/list.h
include/binary.h
include/keyValuePair.h
external/cJSON.h
model/object.h
api/VpnAPI.h
)
include(PreTarget.cmake OPTIONAL)
set(PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# Add library with project file with project name as library name
add_library(${pkgName} ${SRCS} ${HDRS})
# Link dependent libraries
if(NOT CMAKE_VERSION VERSION_LESS 3.4)
target_link_libraries(${pkgName} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
endif()
target_link_libraries(${pkgName} PUBLIC ${CURL_LIBRARIES} )
target_include_directories(
${pkgName} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
include(PostTarget.cmake OPTIONAL)
# installation of libraries, headers, and config files
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in)
install(TARGETS ${pkgName} DESTINATION lib)
else()
include(GNUInstallDirs)
install(TARGETS ${pkgName} DESTINATION lib EXPORT ${pkgName}Targets)
foreach(HDR_FILE ${HDRS})
get_filename_component(HDR_DIRECTORY ${HDR_FILE} DIRECTORY)
get_filename_component(ABSOLUTE_HDR_DIRECTORY ${HDR_DIRECTORY} ABSOLUTE)
file(RELATIVE_PATH RELATIVE_HDR_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${ABSOLUTE_HDR_DIRECTORY})
install(FILES ${HDR_FILE} DESTINATION include/${pkgName}/${RELATIVE_HDR_PATH})
endforeach()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION_STRING}"
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${pkgName}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}Targets.cmake"
NAMESPACE ${pkgName}::
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}Config.cmake"
@ONLY
)
set(ConfigPackageLocation lib/cmake/${pkgName})
install(EXPORT ${pkgName}Targets
FILE
${pkgName}Targets.cmake
NAMESPACE
${pkgName}::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}ConfigVersion.cmake"
DESTINATION
${ConfigPackageLocation}
)
endif()
# make installation packages
include(Packing.cmake OPTIONAL)
# Setting file variables to null
set(SRCS "")
set(HDRS "")
## This section shows how to use the above compiled library to compile the source files
## set source files
#set(SRCS
# unit-tests/manual-VpnAPI.c
#)
##set header files
#set(HDRS
#)
## loop over all files in SRCS variable
#foreach(SOURCE_FILE ${SRCS})
# # Get only the file name from the file as add_executable does not support executable with slash("/")
# get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
# # Remove .c from the file name and set it as executable name
# string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
# # Add executable for every source file in SRCS
# add_executable(unit-${EXECUTABLE_FILE} ${SOURCE_FILE})
# # Link above created library to executable and dependent library curl
# target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
#endforeach(SOURCE_FILE ${SRCS})