1- cmake_minimum_required (VERSION 2.6)
2- project (CGenerator)
1+ cmake_minimum_required (VERSION 2.6...3.10.2 )
2+ project (CGenerator C )
33
44cmake_policy (SET CMP0063 NEW)
55
66set (CMAKE_C_VISIBILITY_PRESET default)
7- set (CMAKE_CXX_VISIBILITY_PRESET default)
87set (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 ()
1025
1126set (pkgName "openapi_petstore" )
1227
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 ()
1942endif ()
2043
2144set (SRCS
2245 src/list.c
2346 src/apiKey.c
2447 src/apiClient.c
48+ src/binary.c
2549 external/cJSON.c
2650 model/object.c
51+ model/mapped_model.c
2752 model/api_response.c
53+ model/bit.c
2854 model/category.c
55+ model/model_with_set_propertes.c
2956 model/order.c
3057 model/pet.c
58+ model/preference.c
3159 model/tag.c
3260 model/user.c
3361 api/PetAPI.c
@@ -39,13 +67,19 @@ set(SRCS
3967set (HDRS
4068 include /apiClient.h
4169 include /list.h
70+ include /binary.h
4271 include /keyValuePair.h
4372 external/cJSON.h
4473 model/object.h
74+ model/any_type.h
75+ model/mapped_model.h
4576 model/api_response.h
77+ model/bit.h
4678 model/category.h
79+ model/model_with_set_propertes.h
4780 model/order.h
4881 model/pet.h
82+ model/preference.h
4983 model/tag.h
5084 model/user.h
5185 api/PetAPI.h
@@ -54,12 +88,75 @@ set(HDRS
5488
5589)
5690
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} )
5997# 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 )
63160
64161# Setting file variables to null
65162set (SRCS "" )
@@ -72,16 +169,15 @@ set(HDRS "")
72169# unit-tests/manual-PetAPI.c
73170# unit-tests/manual-StoreAPI.c
74171# unit-tests/manual-UserAPI.c
75- # unit-tests/manual-order.c
76- # unit-tests/manual-user.c)
172+ #)
77173
78174##set header files
79175#set(HDRS
80176#)
81177
82178## loop over all files in SRCS variable
83179#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("/")
85181# get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
86182# # Remove .c from the file name and set it as executable name
87183# string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
0 commit comments