1
- cmake_minimum_required (VERSION 2.6)
2
- project (CGenerator)
1
+ cmake_minimum_required (VERSION 2.6...3.10.2 )
2
+ project (CGenerator C )
3
3
4
4
cmake_policy (SET CMP0063 NEW)
5
5
6
6
set (CMAKE_C_VISIBILITY_PRESET default)
7
- set (CMAKE_CXX_VISIBILITY_PRESET default)
8
7
set (CMAKE_VISIBILITY_INLINES_HIDDEN OFF )
9
- set (CMAKE_BUILD_TYPE Debug)
8
+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
9
+
10
+ option (BUILD_SHARED_LIBS "Build using shared libraries" ON )
11
+
12
+ find_package (OpenSSL)
13
+
14
+ if (OPENSSL_FOUND)
15
+ message (STATUS "OPENSSL found" )
16
+
17
+ set (CMAKE_C_FLAGS "-DOPENSSL" )
18
+ if (CMAKE_VERSION VERSION_LESS 3.4)
19
+ include_directories (${OPENSSL_INCLUDE_DIR} )
20
+ include_directories (${OPENSSL_INCLUDE_DIRS} )
21
+ link_directories (${OPENSSL_LIBRARIES} )
22
+ endif ()
23
+
24
+ message (STATUS "Using OpenSSL ${OPENSSL_VERSION} " )
25
+ else ()
26
+ message (STATUS "OpenSSL Not found." )
27
+ endif ()
10
28
11
29
set (pkgName "openapi_petstore" )
12
30
13
- find_package (CURL 7.58.0 REQUIRED)
14
- if (CURL_FOUND)
15
- include_directories (${CURL_INCLUDE_DIR} )
16
- set (PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
17
- else (CURL_FOUND)
18
- message (FATAL_ERROR "Could not find the CURL library and development files." )
31
+ # this default version can be overridden in PreTarget.cmake
32
+ set (PROJECT_VERSION_MAJOR 0)
33
+ set (PROJECT_VERSION_MINOR 0)
34
+ set (PROJECT_VERSION_PATCH 1)
35
+
36
+ if ( (DEFINED CURL_INCLUDE_DIR) AND (DEFINED CURL_LIBRARIES))
37
+ include_directories (${CURL_INCLUDE_DIR} )
38
+ set (PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
39
+ else ()
40
+ find_package (CURL 7.58.0 REQUIRED)
41
+ if (CURL_FOUND)
42
+ include_directories (${CURL_INCLUDE_DIR} )
43
+ set (PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
44
+ else (CURL_FOUND)
45
+ message (FATAL_ERROR "Could not find the CURL library and development files." )
46
+ endif ()
19
47
endif ()
20
48
21
49
set (SRCS
22
50
src/list.c
23
51
src/apiKey.c
24
52
src/apiClient.c
53
+ src/binary.c
25
54
external/cJSON.c
26
55
model/object.c
56
+ model/mapped_model.c
27
57
model/api_response.c
58
+ model/bit.c
28
59
model/category.c
60
+ model/model_with_set_propertes.c
29
61
model/order.c
30
62
model/pet.c
63
+ model/preference.c
31
64
model/tag.c
32
65
model/user.c
33
66
api/PetAPI.c
@@ -39,13 +72,19 @@ set(SRCS
39
72
set (HDRS
40
73
include /apiClient.h
41
74
include /list.h
75
+ include /binary.h
42
76
include /keyValuePair.h
43
77
external/cJSON.h
44
78
model/object.h
79
+ model/any_type.h
80
+ model/mapped_model.h
45
81
model/api_response.h
82
+ model/bit.h
46
83
model/category.h
84
+ model/model_with_set_propertes.h
47
85
model/order.h
48
86
model/pet.h
87
+ model/preference.h
49
88
model/tag.h
50
89
model/user.h
51
90
api/PetAPI.h
@@ -54,12 +93,75 @@ set(HDRS
54
93
55
94
)
56
95
57
- # Add library with project file with projectname as library name
58
- add_library (${pkgName} SHARED ${SRCS} ${HDRS} )
96
+ include (PreTarget.cmake OPTIONAL )
97
+
98
+ set (PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR} .${PROJECT_VERSION_MINOR} .${PROJECT_VERSION_PATCH} " )
99
+
100
+ # Add library with project file with project name as library name
101
+ add_library (${pkgName} ${SRCS} ${HDRS} )
59
102
# Link dependent libraries
60
- target_link_libraries (${pkgName} ${CURL_LIBRARIES} )
61
- #install library to destination
62
- install (TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX} )
103
+ if (NOT CMAKE_VERSION VERSION_LESS 3.4)
104
+ target_link_libraries (${pkgName} PRIVATE OpenSSL::SSL OpenSSL::Crypto)
105
+ endif ()
106
+ target_link_libraries (${pkgName} PUBLIC ${CURL_LIBRARIES} )
107
+ target_include_directories (
108
+ ${pkgName} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} >
109
+ $<INSTALL_INTERFACE:include >
110
+ )
111
+
112
+ include (PostTarget.cmake OPTIONAL )
113
+
114
+ # installation of libraries, headers, and config files
115
+ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /Config.cmake.in)
116
+ install (TARGETS ${pkgName} DESTINATION lib)
117
+ else ()
118
+ include (GNUInstallDirs)
119
+ install (TARGETS ${pkgName} DESTINATION lib EXPORT ${pkgName} Targets)
120
+
121
+ foreach (HDR_FILE ${HDRS} )
122
+ get_filename_component (HDR_DIRECTORY ${HDR_FILE} DIRECTORY )
123
+ get_filename_component (ABSOLUTE_HDR_DIRECTORY ${HDR_DIRECTORY} ABSOLUTE )
124
+ file (RELATIVE_PATH RELATIVE_HDR_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${ABSOLUTE_HDR_DIRECTORY} )
125
+ install (FILES ${HDR_FILE} DESTINATION include /${pkgName} /${RELATIVE_HDR_PATH} )
126
+ endforeach ()
127
+
128
+ include (CMakePackageConfigHelpers)
129
+ write_basic_package_version_file(
130
+ "${CMAKE_CURRENT_BINARY_DIR} /${pkgName} /${pkgName} ConfigVersion.cmake"
131
+ VERSION "${PROJECT_VERSION_STRING} "
132
+ COMPATIBILITY AnyNewerVersion
133
+ )
134
+
135
+ export (EXPORT ${pkgName} Targets
136
+ FILE "${CMAKE_CURRENT_BINARY_DIR} /${pkgName} /${pkgName} Targets.cmake"
137
+ NAMESPACE ${pkgName} ::
138
+ )
139
+
140
+ configure_file (${CMAKE_CURRENT_SOURCE_DIR} /Config.cmake.in
141
+ "${CMAKE_CURRENT_BINARY_DIR} /${pkgName} /${pkgName} Config.cmake"
142
+ @ONLY
143
+ )
144
+
145
+ set (ConfigPackageLocation lib/cmake/${pkgName} )
146
+ install (EXPORT ${pkgName} Targets
147
+ FILE
148
+ ${pkgName} Targets.cmake
149
+ NAMESPACE
150
+ ${pkgName} ::
151
+ DESTINATION
152
+ ${ConfigPackageLocation}
153
+ )
154
+ install (
155
+ FILES
156
+ "${CMAKE_CURRENT_BINARY_DIR} /${pkgName} /${pkgName} Config.cmake"
157
+ "${CMAKE_CURRENT_BINARY_DIR} /${pkgName} /${pkgName} ConfigVersion.cmake"
158
+ DESTINATION
159
+ ${ConfigPackageLocation}
160
+ )
161
+ endif ()
162
+
163
+ # make installation packages
164
+ include (Packing.cmake OPTIONAL )
63
165
64
166
# Setting file variables to null
65
167
set (SRCS "" )
@@ -72,16 +174,15 @@ set(HDRS "")
72
174
# unit-tests/manual-PetAPI.c
73
175
# unit-tests/manual-StoreAPI.c
74
176
# unit-tests/manual-UserAPI.c
75
- # unit-tests/manual-order.c
76
- # unit-tests/manual-user.c)
177
+ #)
77
178
78
179
##set header files
79
180
#set(HDRS
80
181
#)
81
182
82
183
## loop over all files in SRCS variable
83
184
#foreach(SOURCE_FILE ${SRCS})
84
- # # Get only the file name from the file as add_executable doesn't support executable with slash("/")
185
+ # # Get only the file name from the file as add_executable does not support executable with slash("/")
85
186
# get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
86
187
# # Remove .c from the file name and set it as executable name
87
188
# string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
0 commit comments