Hemant Zope 3be4902444 [C] C generator refactored (#2463)
* New modified model header and body mustache for c client generator

* remove uncrustify from cmake as it is used during code generation, also remove valgrind as it is not used

* add function to encode and decode binary data

* update model mustache

* update api body and header mustache for handling all types of parameters

* update model mustache with variable names and address few more issues to generate working codes

* updated api body and header mustaches with support for various new parameters and fix some issues as per new changes in code flow structure

* update apiClient header and body mustache as per new modifications for handling binary data and few more stuff

* updated samples generated by new modified mustache

* update handling of file and binary data type to binary_t

* update samples with recent commit on master regarding c-generator

* update cmakelist which was ignored by .openapi-generator-ignore, cleanup external folder

* update CMakeList mustache to show how to use compiled libary to compile source files

* update samples with new cmake

* Add comments explaining what each command is doing inshort

* remove freeing of base path as it is not memory allocated

* update samples to free apiclient object when the requirement is over

* add missing cJSON delete to fix memory not freed bugs

* use uncrustify to beautify manual written test code
2019-04-15 11:27:34 +08:00

86 lines
2.2 KiB
CMake

cmake_minimum_required (VERSION 2.6)
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_BUILD_TYPE Debug)
set(pkgName "openapi_petstore")
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
external/cJSON.c
model/api_response.c
model/category.c
model/order.c
model/pet.c
model/tag.c
model/user.c
api/PetAPI.c
api/StoreAPI.c
api/UserAPI.c
)
set(HDRS
include/apiClient.h
include/list.h
include/keyValuePair.h
external/cJSON.h
model/api_response.h
model/category.h
model/order.h
model/pet.h
model/tag.h
model/user.h
api/PetAPI.h
api/StoreAPI.h
api/UserAPI.h
)
add_library(${pkgName} SHARED ${SRCS} ${HDRS})
target_link_libraries(${pkgName} ${CURL_LIBRARIES} )
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
set(SRCS "")
set(HDRS "")
# This section shows how to use the above compiled libary to compile the source files
# set source files
set(SRCS
unit-tests/manual-PetAPI.c
unit-tests/manual-StoreAPI.c
unit-tests/manual-UserAPI.c
unit-tests/manual-order.c
unit-tests/manual-user.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 doesnot 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 libary to executable and dependent libary curl
target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
endforeach(SOURCE_FILE ${SRCS})