Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows adaptations and installer configuration #10326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/generators/c.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>static</li>
<li>static_assert</li>
<li>static_cast</li>
<li>stderr</li>
<li>stdin</li>
<li>stdout</li>
<li>struct</li>
<li>switch</li>
<li>synchronized</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ public CLibcurlClientCodegen() {
"final",
"override",
"transaction_safe",
"transaction_safe_dynamic")
"transaction_safe_dynamic",

// VC++ reserved keywords
"stdin",
ahmedyarub marked this conversation as resolved.
Show resolved Hide resolved
"stdout",
"stderr")
);

instantiationTypes.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

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 "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/c/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down