1 | #***************************************************************************
|
---|
2 | # _ _ ____ _
|
---|
3 | # Project ___| | | | _ \| |
|
---|
4 | # / __| | | | |_) | |
|
---|
5 | # | (__| |_| | _ <| |___
|
---|
6 | # \___|\___/|_| \_\_____|
|
---|
7 | #
|
---|
8 | # Copyright (C) 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 | configure_file(curl_config.h.cmake
|
---|
29 | ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
|
---|
30 |
|
---|
31 | transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
---|
32 | include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
|
---|
33 |
|
---|
34 | list(APPEND HHEADERS
|
---|
35 | ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
|
---|
36 | )
|
---|
37 |
|
---|
38 | # The rest of the build
|
---|
39 |
|
---|
40 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
|
---|
41 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
|
---|
42 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
---|
43 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
|
---|
44 | include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
---|
45 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
---|
46 | if(USE_ARES)
|
---|
47 | include_directories(${CARES_INCLUDE_DIR})
|
---|
48 | endif()
|
---|
49 |
|
---|
50 | add_library(
|
---|
51 | curlu # special libcurlu library just for unittests
|
---|
52 | STATIC
|
---|
53 | EXCLUDE_FROM_ALL
|
---|
54 | ${HHEADERS} ${CSOURCES}
|
---|
55 | )
|
---|
56 | target_compile_definitions(curlu PUBLIC UNITTESTS CURL_STATICLIB)
|
---|
57 |
|
---|
58 | if(ENABLE_CURLDEBUG)
|
---|
59 | # We must compile memdebug.c separately to avoid memdebug.h redefinitions
|
---|
60 | # being applied to memdebug.c itself.
|
---|
61 | set_source_files_properties(memdebug.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
|
---|
62 | endif()
|
---|
63 | target_link_libraries(curlu PRIVATE ${CURL_LIBS})
|
---|
64 |
|
---|
65 | transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
|
---|
66 | include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
|
---|
67 |
|
---|
68 | if(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
|
---|
69 | CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
|
---|
70 | CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
|
---|
71 | CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR
|
---|
72 | CMAKE_SYSTEM_NAME STREQUAL "GNU/kFreeBSD" OR
|
---|
73 |
|
---|
74 | # FreeBSD comes with the a.out and elf flavours
|
---|
75 | # but a.out was supported up to version 3.x and
|
---|
76 | # elf from 3.x. I cannot imagine someone running
|
---|
77 | # CMake on those ancient systems
|
---|
78 | CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
|
---|
79 |
|
---|
80 | CMAKE_SYSTEM_NAME STREQUAL "Haiku")
|
---|
81 |
|
---|
82 | math(EXPR CMAKESONAME "${VERSIONCHANGE} - ${VERSIONDEL}")
|
---|
83 | set(CMAKEVERSION "${CMAKESONAME}.${VERSIONDEL}.${VERSIONADD}")
|
---|
84 | else()
|
---|
85 | unset(CMAKESONAME)
|
---|
86 | endif()
|
---|
87 |
|
---|
88 | if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
|
---|
89 | # on not-Windows and not-crosscompiling, check for writable argv[]
|
---|
90 | include(CheckCSourceRuns)
|
---|
91 | check_c_source_runs("
|
---|
92 | int main(int argc, char **argv)
|
---|
93 | {
|
---|
94 | (void)argc;
|
---|
95 | argv[0][0] = ' ';
|
---|
96 | return (argv[0][0] == ' ')?0:1;
|
---|
97 | }"
|
---|
98 | HAVE_WRITABLE_ARGV)
|
---|
99 | endif()
|
---|
100 |
|
---|
101 | ## Library definition
|
---|
102 |
|
---|
103 | # Add "_imp" as a suffix before the extension to avoid conflicting with
|
---|
104 | # the statically linked "libcurl.lib" (typically with MSVC)
|
---|
105 | if(WIN32 AND
|
---|
106 | NOT IMPORT_LIB_SUFFIX AND
|
---|
107 | CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL CMAKE_IMPORT_LIBRARY_SUFFIX)
|
---|
108 | set(IMPORT_LIB_SUFFIX "_imp")
|
---|
109 | endif()
|
---|
110 |
|
---|
111 | # Whether to do a single compilation pass for libcurl sources and reuse these
|
---|
112 | # objects to generate both static and shared target.
|
---|
113 | if(NOT DEFINED SHARE_LIB_OBJECT)
|
---|
114 | # Enable it by default on platforms where PIC is the default for both shared
|
---|
115 | # and static and there is a way to tell the linker which libcurl symbols it
|
---|
116 | # should export (vs. marking these symbols exportable at compile-time).
|
---|
117 | if(WIN32)
|
---|
118 | set(SHARE_LIB_OBJECT ON)
|
---|
119 | else()
|
---|
120 | # On other platforms, make it an option disabled by default
|
---|
121 | set(SHARE_LIB_OBJECT OFF)
|
---|
122 | endif()
|
---|
123 | endif()
|
---|
124 |
|
---|
125 | if(SHARE_LIB_OBJECT)
|
---|
126 | set(LIB_OBJECT "libcurl_object")
|
---|
127 | add_library(${LIB_OBJECT} OBJECT ${HHEADERS} ${CSOURCES})
|
---|
128 | target_link_libraries(${LIB_OBJECT} PRIVATE ${CURL_LIBS})
|
---|
129 | set_target_properties(${LIB_OBJECT} PROPERTIES
|
---|
130 | COMPILE_DEFINITIONS "BUILDING_LIBCURL"
|
---|
131 | INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB"
|
---|
132 | POSITION_INDEPENDENT_CODE ON)
|
---|
133 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
134 | set_target_properties(${LIB_OBJECT} PROPERTIES
|
---|
135 | COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS"
|
---|
136 | COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
137 | endif()
|
---|
138 | if(CURL_HAS_LTO)
|
---|
139 | set_target_properties(${LIB_OBJECT} PROPERTIES
|
---|
140 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
141 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
142 | endif()
|
---|
143 |
|
---|
144 | target_include_directories(${LIB_OBJECT} INTERFACE
|
---|
145 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
146 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
147 |
|
---|
148 | set(LIB_SOURCE $<TARGET_OBJECTS:${LIB_OBJECT}>)
|
---|
149 | else()
|
---|
150 | set(LIB_SOURCE ${HHEADERS} ${CSOURCES})
|
---|
151 | endif()
|
---|
152 |
|
---|
153 | # we want it to be called libcurl on all platforms
|
---|
154 | if(BUILD_STATIC_LIBS)
|
---|
155 | list(APPEND libcurl_export ${LIB_STATIC})
|
---|
156 | add_library(${LIB_STATIC} STATIC ${LIB_SOURCE})
|
---|
157 | add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC})
|
---|
158 | target_link_libraries(${LIB_STATIC} PRIVATE ${CURL_LIBS})
|
---|
159 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
160 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
161 | PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}"
|
---|
162 | SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}"
|
---|
163 | COMPILE_DEFINITIONS "BUILDING_LIBCURL"
|
---|
164 | INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB")
|
---|
165 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
166 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
167 | COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS"
|
---|
168 | COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
169 | endif()
|
---|
170 | if(CURL_HAS_LTO)
|
---|
171 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
172 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
173 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
174 | endif()
|
---|
175 | if(CMAKEVERSION AND CMAKESONAME)
|
---|
176 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
177 | VERSION ${CMAKEVERSION} SOVERSION ${CMAKESONAME})
|
---|
178 | endif()
|
---|
179 |
|
---|
180 | target_include_directories(${LIB_STATIC} INTERFACE
|
---|
181 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
182 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
183 | endif()
|
---|
184 |
|
---|
185 | if(BUILD_SHARED_LIBS)
|
---|
186 | list(APPEND libcurl_export ${LIB_SHARED})
|
---|
187 | add_library(${LIB_SHARED} SHARED ${LIB_SOURCE})
|
---|
188 | add_library(${PROJECT_NAME}::${LIB_SHARED} ALIAS ${LIB_SHARED})
|
---|
189 | if(WIN32)
|
---|
190 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libcurl.rc ${CURL_SOURCE_DIR}/libcurl.def)
|
---|
191 | endif()
|
---|
192 | target_link_libraries(${LIB_SHARED} PRIVATE ${CURL_LIBS})
|
---|
193 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
194 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
195 | PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}"
|
---|
196 | IMPORT_PREFIX "" IMPORT_SUFFIX "${IMPORT_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
|
---|
197 | COMPILE_DEFINITIONS "BUILDING_LIBCURL"
|
---|
198 | POSITION_INDEPENDENT_CODE ON)
|
---|
199 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
200 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
201 | COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS"
|
---|
202 | COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
203 | endif()
|
---|
204 | if(CURL_HAS_LTO)
|
---|
205 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
206 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
207 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
208 | endif()
|
---|
209 | if(CMAKEVERSION AND CMAKESONAME)
|
---|
210 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
211 | VERSION ${CMAKEVERSION} SOVERSION ${CMAKESONAME})
|
---|
212 | endif()
|
---|
213 |
|
---|
214 | target_include_directories(${LIB_SHARED} INTERFACE
|
---|
215 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
216 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
217 | endif()
|
---|
218 |
|
---|
219 | add_library(${LIB_NAME} ALIAS ${LIB_SELECTED})
|
---|
220 | add_library(${PROJECT_NAME}::${LIB_NAME} ALIAS ${LIB_SELECTED})
|
---|
221 |
|
---|
222 | if(CURL_ENABLE_EXPORT_TARGET)
|
---|
223 | if(BUILD_STATIC_LIBS)
|
---|
224 | install(TARGETS ${LIB_STATIC}
|
---|
225 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
226 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
227 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
228 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
229 | )
|
---|
230 | endif()
|
---|
231 | if(BUILD_SHARED_LIBS)
|
---|
232 | install(TARGETS ${LIB_SHARED}
|
---|
233 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
234 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
235 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
236 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
237 | )
|
---|
238 | endif()
|
---|
239 |
|
---|
240 | export(TARGETS ${libcurl_export}
|
---|
241 | FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
---|
242 | NAMESPACE ${PROJECT_NAME}::
|
---|
243 | )
|
---|
244 | endif()
|
---|