1 | #***************************************************************************
|
---|
2 | # _ _ ____ _
|
---|
3 | # Project ___| | | | _ \| |
|
---|
4 | # / __| | | | |_) | |
|
---|
5 | # | (__| |_| | _ <| |___
|
---|
6 | # \___|\___/|_| \_\_____|
|
---|
7 | #
|
---|
8 | # Copyright (C) 1998 - 2022, Daniel Stenberg, <[email protected]>, 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 | # SPDX-License-Identifier: curl
|
---|
22 | #
|
---|
23 | ###########################################################################
|
---|
24 | set(LIB_NAME libcurl)
|
---|
25 | set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library")
|
---|
26 | add_definitions(-DBUILDING_LIBCURL)
|
---|
27 |
|
---|
28 | if(BUILD_SHARED_LIBS)
|
---|
29 | set(CURL_STATICLIB NO)
|
---|
30 | else()
|
---|
31 | set(CURL_STATICLIB YES)
|
---|
32 | endif()
|
---|
33 |
|
---|
34 | # Use:
|
---|
35 | # * CURL_STATICLIB
|
---|
36 | configure_file(curl_config.h.cmake
|
---|
37 | ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
|
---|
38 |
|
---|
39 | transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
---|
40 | include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
|
---|
41 |
|
---|
42 | list(APPEND HHEADERS
|
---|
43 | ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
|
---|
44 | )
|
---|
45 |
|
---|
46 | if(WIN32 AND NOT CURL_STATICLIB)
|
---|
47 | list(APPEND CSOURCES libcurl.rc)
|
---|
48 | endif()
|
---|
49 |
|
---|
50 | # SET(CSOURCES
|
---|
51 | # # memdebug.c -not used
|
---|
52 | # # nwlib.c - Not used
|
---|
53 | # # strtok.c - specify later
|
---|
54 | # # strtoofft.c - specify later
|
---|
55 | # )
|
---|
56 |
|
---|
57 | # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
|
---|
58 | # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
|
---|
59 | # IF(CURL_MALLOC_DEBUG)
|
---|
60 | # SET(CSOURCES ${CSOURCES}
|
---|
61 | # memdebug.c
|
---|
62 | # )
|
---|
63 | # ENDIF(CURL_MALLOC_DEBUG)
|
---|
64 |
|
---|
65 | # # only build compat strtoofft if we need to
|
---|
66 | # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
|
---|
67 | # SET(CSOURCES ${CSOURCES}
|
---|
68 | # strtoofft.c
|
---|
69 | # )
|
---|
70 | # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
|
---|
71 |
|
---|
72 |
|
---|
73 | # The rest of the build
|
---|
74 |
|
---|
75 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
|
---|
76 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
|
---|
77 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
---|
78 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
|
---|
79 | include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
---|
80 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
---|
81 | if(USE_ARES)
|
---|
82 | include_directories(${CARES_INCLUDE_DIR})
|
---|
83 | endif()
|
---|
84 |
|
---|
85 | add_library(
|
---|
86 | ${LIB_NAME}
|
---|
87 | ${HHEADERS} ${CSOURCES}
|
---|
88 | )
|
---|
89 |
|
---|
90 | add_library(
|
---|
91 | ${PROJECT_NAME}::${LIB_NAME}
|
---|
92 | ALIAS ${LIB_NAME}
|
---|
93 | )
|
---|
94 |
|
---|
95 | if(NOT BUILD_SHARED_LIBS)
|
---|
96 | set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
|
---|
97 | endif()
|
---|
98 |
|
---|
99 | target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
|
---|
100 |
|
---|
101 | transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
|
---|
102 | include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
|
---|
103 |
|
---|
104 | set_target_properties(${LIB_NAME} PROPERTIES
|
---|
105 | COMPILE_DEFINITIONS BUILDING_LIBCURL
|
---|
106 | OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
|
---|
107 | )
|
---|
108 |
|
---|
109 | if(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
|
---|
110 | CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
|
---|
111 | CMAKE_SYSTEM_NAME STREQUAL "GNU/kFreeBSD" OR
|
---|
112 |
|
---|
113 | # FreeBSD comes with the a.out and elf flavours
|
---|
114 | # but a.out was supported up to version 3.x and
|
---|
115 | # elf from 3.x. I cannot imagine someone runnig
|
---|
116 | # CMake on those ancient systems
|
---|
117 | CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
|
---|
118 |
|
---|
119 | CMAKE_SYSTEM_NAME STREQUAL "Haiku")
|
---|
120 |
|
---|
121 | math(EXPR CMAKESONAME "${VERSIONCHANGE} - ${VERSIONDEL}")
|
---|
122 | set(CMAKEVERSION "${CMAKESONAME}.${VERSIONDEL}.${VERSIONADD}")
|
---|
123 |
|
---|
124 | set_target_properties(${LIB_NAME} PROPERTIES
|
---|
125 | VERSION ${CMAKEVERSION}
|
---|
126 | SOVERSION ${CMAKESONAME}
|
---|
127 | )
|
---|
128 |
|
---|
129 | endif()
|
---|
130 |
|
---|
131 |
|
---|
132 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
133 | set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
134 | set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
|
---|
135 | endif()
|
---|
136 |
|
---|
137 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
138 | set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
|
---|
139 | set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
|
---|
140 |
|
---|
141 | if(CURL_HAS_LTO)
|
---|
142 | set_target_properties(${LIB_NAME} PROPERTIES
|
---|
143 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
144 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
145 | endif()
|
---|
146 |
|
---|
147 | if(WIN32)
|
---|
148 | if(BUILD_SHARED_LIBS)
|
---|
149 | if(MSVC)
|
---|
150 | # Add "_imp" as a suffix before the extension to avoid conflicting with
|
---|
151 | # the statically linked "libcurl.lib"
|
---|
152 | set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
|
---|
153 | endif()
|
---|
154 | endif()
|
---|
155 | endif()
|
---|
156 |
|
---|
157 | target_include_directories(${LIB_NAME} INTERFACE
|
---|
158 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
159 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
160 |
|
---|
161 | if(CURL_ENABLE_EXPORT_TARGET)
|
---|
162 | install(TARGETS ${LIB_NAME}
|
---|
163 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
164 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
165 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
166 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
167 | )
|
---|
168 |
|
---|
169 | export(TARGETS ${LIB_NAME}
|
---|
170 | FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
---|
171 | NAMESPACE ${PROJECT_NAME}::
|
---|
172 | )
|
---|
173 | endif()
|
---|