2020-03-23 21:44:29 +08:00
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
2023-01-02 20:51:48 +08:00
|
|
|
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2020-03-23 21:44:29 +08:00
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
# are also available at https://curl.se/docs/copyright.html.
|
2020-03-23 21:44:29 +08:00
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
2018-08-01 20:02:26 +08:00
|
|
|
# SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
#
|
2020-03-23 21:44:29 +08:00
|
|
|
###########################################################################
|
2021-04-21 21:03:04 +08:00
|
|
|
set(LIB_NAME libcurl)
|
2021-04-22 23:29:45 +08:00
|
|
|
set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library")
|
2022-09-13 20:43:40 +08:00
|
|
|
add_definitions(-DBUILDING_LIBCURL)
|
2009-04-02 21:14:53 +08:00
|
|
|
|
2018-07-10 17:54:34 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set(CURL_STATICLIB NO)
|
|
|
|
else()
|
|
|
|
set(CURL_STATICLIB YES)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Use:
|
|
|
|
# * CURL_STATICLIB
|
2009-07-14 21:25:14 +08:00
|
|
|
configure_file(curl_config.h.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
|
2009-04-02 21:14:53 +08:00
|
|
|
|
2009-06-10 01:29:16 +08:00
|
|
|
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
|
|
|
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
|
2009-04-07 06:45:17 +08:00
|
|
|
|
2009-06-10 01:29:16 +08:00
|
|
|
list(APPEND HHEADERS
|
2009-07-14 21:25:14 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
|
2009-06-10 01:29:16 +08:00
|
|
|
)
|
2009-04-02 21:14:53 +08:00
|
|
|
|
2022-05-26 23:54:47 +08:00
|
|
|
if(WIN32 AND NOT CURL_STATICLIB)
|
2009-06-10 01:29:16 +08:00
|
|
|
list(APPEND CSOURCES libcurl.rc)
|
|
|
|
endif()
|
2009-04-02 21:14:53 +08:00
|
|
|
|
|
|
|
# The rest of the build
|
|
|
|
|
2009-06-10 01:29:16 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
2014-11-06 08:32:45 +08:00
|
|
|
if(USE_ARES)
|
2009-07-15 03:03:31 +08:00
|
|
|
include_directories(${CARES_INCLUDE_DIR})
|
|
|
|
endif()
|
2009-04-02 21:14:53 +08:00
|
|
|
|
2009-06-10 01:29:16 +08:00
|
|
|
add_library(
|
|
|
|
${LIB_NAME}
|
|
|
|
${HHEADERS} ${CSOURCES}
|
|
|
|
)
|
2009-04-02 21:14:53 +08:00
|
|
|
|
2020-04-10 04:42:22 +08:00
|
|
|
add_library(
|
|
|
|
${PROJECT_NAME}::${LIB_NAME}
|
|
|
|
ALIAS ${LIB_NAME}
|
|
|
|
)
|
|
|
|
|
2018-08-01 20:02:26 +08:00
|
|
|
if(NOT BUILD_SHARED_LIBS)
|
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
|
|
|
|
endif()
|
|
|
|
|
2022-07-08 19:30:57 +08:00
|
|
|
target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
|
2009-04-02 21:14:53 +08:00
|
|
|
|
2022-12-03 20:20:14 +08:00
|
|
|
transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
|
|
|
|
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
|
|
|
|
|
2021-04-22 23:29:45 +08:00
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES
|
|
|
|
COMPILE_DEFINITIONS BUILDING_LIBCURL
|
|
|
|
OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
|
|
|
|
)
|
2009-04-07 04:44:01 +08:00
|
|
|
|
2022-12-03 20:20:14 +08:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
|
|
|
|
CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
|
2023-01-03 21:31:57 +08:00
|
|
|
CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
|
2023-03-22 21:07:54 +08:00
|
|
|
CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR
|
2022-12-03 20:20:14 +08:00
|
|
|
CMAKE_SYSTEM_NAME STREQUAL "GNU/kFreeBSD" OR
|
|
|
|
|
|
|
|
# FreeBSD comes with the a.out and elf flavours
|
|
|
|
# but a.out was supported up to version 3.x and
|
2022-12-22 22:22:11 +08:00
|
|
|
# elf from 3.x. I cannot imagine someone running
|
2022-12-03 20:20:14 +08:00
|
|
|
# CMake on those ancient systems
|
|
|
|
CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
|
|
|
|
|
|
|
|
CMAKE_SYSTEM_NAME STREQUAL "Haiku")
|
|
|
|
|
|
|
|
math(EXPR CMAKESONAME "${VERSIONCHANGE} - ${VERSIONDEL}")
|
|
|
|
set(CMAKEVERSION "${CMAKESONAME}.${VERSIONDEL}.${VERSIONADD}")
|
|
|
|
|
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES
|
|
|
|
VERSION ${CMAKEVERSION}
|
|
|
|
SOVERSION ${CMAKESONAME}
|
|
|
|
)
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2016-09-04 18:37:46 +08:00
|
|
|
if(HIDES_CURL_PRIVATE_SYMBOLS)
|
|
|
|
set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
|
|
|
set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
|
|
|
|
endif()
|
|
|
|
|
2009-04-07 03:43:52 +08:00
|
|
|
# Remove the "lib" prefix since the library is already named "libcurl".
|
2009-06-10 01:29:16 +08:00
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
|
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
|
|
|
|
|
2020-01-09 19:10:55 +08:00
|
|
|
if(CURL_HAS_LTO)
|
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES
|
|
|
|
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
|
|
|
INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
|
|
|
endif()
|
|
|
|
|
2009-06-10 01:29:16 +08:00
|
|
|
if(WIN32)
|
2018-07-10 17:54:34 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2020-11-20 02:34:43 +08:00
|
|
|
if(MSVC)
|
|
|
|
# Add "_imp" as a suffix before the extension to avoid conflicting with
|
|
|
|
# the statically linked "libcurl.lib"
|
|
|
|
set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
|
|
|
|
endif()
|
2009-06-10 01:29:16 +08:00
|
|
|
endif()
|
2023-04-06 16:06:30 +08:00
|
|
|
else()
|
|
|
|
# on not-Windows, check for writable argv[]
|
|
|
|
include(CheckCSourceRuns)
|
|
|
|
check_c_source_runs("
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
argv[0][0] = ' ';
|
|
|
|
return (argv[0][0] == ' ')?0:1;
|
|
|
|
}"
|
|
|
|
HAVE_WRITABLE_ARGV)
|
2009-06-10 01:29:16 +08:00
|
|
|
endif()
|
2011-04-28 04:05:07 +08:00
|
|
|
|
2017-09-10 22:56:16 +08:00
|
|
|
target_include_directories(${LIB_NAME} INTERFACE
|
2021-01-12 21:11:07 +08:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
2018-09-07 21:45:11 +08:00
|
|
|
$<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
2017-09-10 22:56:16 +08:00
|
|
|
|
2022-10-03 03:43:07 +08:00
|
|
|
if(CURL_ENABLE_EXPORT_TARGET)
|
|
|
|
install(TARGETS ${LIB_NAME}
|
|
|
|
EXPORT ${TARGETS_EXPORT_NAME}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
export(TARGETS ${LIB_NAME}
|
|
|
|
FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
|
|
)
|
|
|
|
endif()
|