diff --git a/docs/generators/c.md b/docs/generators/c.md index c3a79bad9fcf..98f84c458762 100644 --- a/docs/generators/c.md +++ b/docs/generators/c.md @@ -135,6 +135,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
  • static
  • static_assert
  • static_cast
  • +
  • stderr
  • +
  • stdin
  • +
  • stdout
  • struct
  • switch
  • synchronized
  • diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java index 07b16ca17b45..58803d150a15 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java @@ -245,7 +245,12 @@ public CLibcurlClientCodegen() { "final", "override", "transaction_safe", - "transaction_safe_dynamic") + "transaction_safe_dynamic", + + // VC++ reserved keywords + "stdin", + "stdout", + "stderr") ); instantiationTypes.clear(); diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache index 2e6d8480fa00..33d82b5786dc 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/CMakeLists.txt.mustache @@ -6,6 +6,7 @@ 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) @@ -27,6 +28,7 @@ else() endif() set(pkgName "{{projectName}}") +set(VERSION 0.0.1) # this default version can be overridden in PreTarget.cmake find_package(CURL 7.58.0 REQUIRED) if(CURL_FOUND) @@ -86,14 +88,66 @@ include(PreTarget.cmake OPTIONAL) add_library(${pkgName} ${SRCS} ${HDRS}) # Link dependent libraries if(NOT CMAKE_VERSION VERSION_LESS 3.4) - target_link_libraries(${pkgName} OpenSSL::SSL OpenSSL::Crypto) + target_link_libraries(${pkgName} PRIVATE OpenSSL::SSL OpenSSL::Crypto) endif() -target_link_libraries(${pkgName} ${CURL_LIBRARIES} ) +target_link_libraries(${pkgName} PUBLIC ${CURL_LIBRARIES} ) +target_include_directories( + ${pkgName} PUBLIC $ + $ +) include(PostTarget.cmake OPTIONAL) -#install library to destination -install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX}) +# installation of libraries, headers, and config files +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in) + install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX}) +else() + include(GNUInstallDirs) + install(TARGETS ${pkgName} + 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/${RELATIVE_HDR_PATH}) + endforeach() + + include(CMakePackageConfigHelpers) + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${pkgName}/${pkgName}ConfigVersion.cmake" + VERSION "${VERSION}" + 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() # Setting file variables to null set(SRCS "") diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache index d4d387f8f059..38656a5615b3 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/apiClient.c.mustache @@ -570,7 +570,7 @@ size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp) { size_t size_this_time = nmemb * size; apiClient_t *apiClient = (apiClient_t *)userp; apiClient->dataReceived = (char *)realloc( apiClient->dataReceived, apiClient->dataReceivedLen + size_this_time + 1); - memcpy(apiClient->dataReceived + apiClient->dataReceivedLen, buffer, size_this_time); + memcpy((char *)apiClient->dataReceived + apiClient->dataReceivedLen, buffer, size_this_time); apiClient->dataReceivedLen += size_this_time; ((char*)apiClient->dataReceived)[apiClient->dataReceivedLen] = '\0'; // the space size of (apiClient->dataReceived) = dataReceivedLen + 1 if (apiClient->data_callback_func) { diff --git a/samples/client/petstore/c/src/apiClient.c b/samples/client/petstore/c/src/apiClient.c index 2ab296b2e637..ce2f522cda28 100644 --- a/samples/client/petstore/c/src/apiClient.c +++ b/samples/client/petstore/c/src/apiClient.c @@ -476,7 +476,7 @@ size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp) { size_t size_this_time = nmemb * size; apiClient_t *apiClient = (apiClient_t *)userp; apiClient->dataReceived = (char *)realloc( apiClient->dataReceived, apiClient->dataReceivedLen + size_this_time + 1); - memcpy(apiClient->dataReceived + apiClient->dataReceivedLen, buffer, size_this_time); + memcpy((char *)apiClient->dataReceived + apiClient->dataReceivedLen, buffer, size_this_time); apiClient->dataReceivedLen += size_this_time; ((char*)apiClient->dataReceived)[apiClient->dataReceivedLen] = '\0'; // the space size of (apiClient->dataReceived) = dataReceivedLen + 1 if (apiClient->data_callback_func) {