1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. 9# 10# This software is licensed as described in the file COPYING, which 11# you should have received as part of this distribution. The terms 12# are also available at https://curl.se/docs/copyright.html. 13# 14# You may opt to use, copy, modify, merge, publish, distribute and/or sell 15# copies of the Software, and permit persons to whom the Software is 16# furnished to do so, under the terms of the COPYING file. 17# 18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19# KIND, either express or implied. 20# 21########################################################################### 22set(LIB_NAME libcurl) 23set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library") 24 25if(BUILD_SHARED_LIBS) 26 set(CURL_STATICLIB NO) 27else() 28 set(CURL_STATICLIB YES) 29endif() 30 31# Use: 32# * CURL_STATICLIB 33configure_file(curl_config.h.cmake 34 ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h) 35 36transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") 37include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake) 38 39list(APPEND HHEADERS 40 ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h 41 ) 42 43if(WIN32) 44 list(APPEND CSOURCES libcurl.rc) 45endif() 46 47# SET(CSOURCES 48# # memdebug.c -not used 49# # nwlib.c - Not used 50# # strtok.c - specify later 51# # strtoofft.c - specify later 52# ) 53 54# #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF) 55# MARK_AS_ADVANCED(CURL_MALLOC_DEBUG) 56# IF(CURL_MALLOC_DEBUG) 57# SET(CSOURCES ${CSOURCES} 58# memdebug.c 59# ) 60# ENDIF(CURL_MALLOC_DEBUG) 61 62# # only build compat strtoofft if we need to 63# IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64) 64# SET(CSOURCES ${CSOURCES} 65# strtoofft.c 66# ) 67# ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64) 68 69 70# The rest of the build 71 72include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include) 73include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 74include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include) 75include_directories(${CMAKE_CURRENT_BINARY_DIR}/..) 76include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 77include_directories(${CMAKE_CURRENT_BINARY_DIR}) 78if(USE_ARES) 79 include_directories(${CARES_INCLUDE_DIR}) 80endif() 81 82add_library( 83 ${LIB_NAME} 84 ${HHEADERS} ${CSOURCES} 85 ) 86 87add_library( 88 ${PROJECT_NAME}::${LIB_NAME} 89 ALIAS ${LIB_NAME} 90 ) 91 92if(NOT BUILD_SHARED_LIBS) 93 set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB) 94endif() 95 96target_link_libraries(${LIB_NAME} ${CURL_LIBS}) 97 98if(WIN32) 99 add_definitions(-D_USRDLL) 100endif() 101 102set_target_properties(${LIB_NAME} PROPERTIES 103 COMPILE_DEFINITIONS BUILDING_LIBCURL 104 OUTPUT_NAME ${LIBCURL_OUTPUT_NAME} 105 ) 106 107if(HIDES_CURL_PRIVATE_SYMBOLS) 108 set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS") 109 set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE}) 110endif() 111 112# Remove the "lib" prefix since the library is already named "libcurl". 113set_target_properties(${LIB_NAME} PROPERTIES PREFIX "") 114set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "") 115 116if(CURL_HAS_LTO) 117 set_target_properties(${LIB_NAME} PROPERTIES 118 INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE 119 INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE) 120endif() 121 122if(WIN32) 123 if(BUILD_SHARED_LIBS) 124 if(MSVC) 125 # Add "_imp" as a suffix before the extension to avoid conflicting with 126 # the statically linked "libcurl.lib" 127 set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib") 128 endif() 129 endif() 130endif() 131 132target_include_directories(${LIB_NAME} INTERFACE 133 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 134 $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>) 135 136install(TARGETS ${LIB_NAME} 137 EXPORT ${TARGETS_EXPORT_NAME} 138 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 139 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 140 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 141) 142 143export(TARGETS ${LIB_NAME} 144 APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake 145 NAMESPACE ${PROJECT_NAME}:: 146) 147