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