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

Libcurl CMake adaptations #10249

Merged
merged 5 commits into from
Aug 27, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required (VERSION 2.6...3.10.2)
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)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

find_package(OpenSSL)

if (OPENSSL_FOUND)
message (STATUS "OPENSSL found")
set (CMAKE_C_FLAGS "-DOPENSSL")
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIRS})
link_directories(${OPENSSL_LIBRARIES})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
message (STATUS "OPENSSL found")

set(CMAKE_C_FLAGS "-DOPENSSL")
ahmedyarub marked this conversation as resolved.
Show resolved Hide resolved
if(CMAKE_VERSION VERSION_LESS 3.4)
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIRS})
link_directories(${OPENSSL_LIBRARIES})
endif()

message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
message (STATUS "OpenSSL Not found.")
message (STATUS "OpenSSL Not found.")
endif()

set(pkgName "{{projectName}}")

find_package(CURL 7.58.0 REQUIRED)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${CURL_LIBRARIES} )
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.")
message(FATAL_ERROR "Could not find the CURL library and development files.")
endif()

set(SRCS
Expand Down Expand Up @@ -75,10 +80,18 @@ set(HDRS

)

# Add library with project file with projectname as library name
add_library(${pkgName} SHARED ${SRCS} ${HDRS})
include(PreTarget OPTIONAL)

# Add library with project file with project name as library name
add_library(${pkgName} ${SRCS} ${HDRS})
ahmedyarub marked this conversation as resolved.
Show resolved Hide resolved
# Link dependent libraries
if(NOT CMAKE_VERSION VERSION_LESS 3.4)
target_link_libraries(${pkgName} OpenSSL::SSL OpenSSL::Crypto)
endif()
target_link_libraries(${pkgName} ${CURL_LIBRARIES} )

include(PostTarget OPTIONAL)

#install library to destination
install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})

Expand All @@ -87,7 +100,7 @@ set(SRCS "")
set(HDRS "")


## This section shows how to use the above compiled libary to compile the source files
## This section shows how to use the above compiled library to compile the source files
## set source files
#set(SRCS
{{#apiInfo}}
Expand All @@ -105,12 +118,12 @@ 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 only the file name from the file as add_executable does not 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
# # Link above created library to executable and dependent libary curl
# target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
#endforeach(SOURCE_FILE ${SRCS})