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 | if(BUILD_TESTING)
|
---|
51 | add_library(
|
---|
52 | curlu # special libcurlu library just for unittests
|
---|
53 | STATIC
|
---|
54 | EXCLUDE_FROM_ALL
|
---|
55 | ${HHEADERS} ${CSOURCES}
|
---|
56 | )
|
---|
57 | target_compile_definitions(curlu PUBLIC UNITTESTS CURL_STATICLIB)
|
---|
58 | endif()
|
---|
59 |
|
---|
60 | if(ENABLE_CURLDEBUG)
|
---|
61 | # We must compile these sources separately to avoid memdebug.h redefinitions
|
---|
62 | # applying to them.
|
---|
63 | set_source_files_properties(memdebug.c curl_multibyte.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
|
---|
64 | endif()
|
---|
65 |
|
---|
66 | if(BUILD_TESTING)
|
---|
67 | target_link_libraries(curlu PRIVATE ${CURL_LIBS})
|
---|
68 | endif()
|
---|
69 |
|
---|
70 | transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
|
---|
71 | include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
|
---|
72 |
|
---|
73 | if(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
|
---|
74 | CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
|
---|
75 | CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
|
---|
76 | CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR
|
---|
77 | CMAKE_SYSTEM_NAME STREQUAL "GNU/kFreeBSD" OR
|
---|
78 |
|
---|
79 | # FreeBSD comes with the a.out and elf flavours
|
---|
80 | # but a.out was supported up to version 3.x and
|
---|
81 | # elf from 3.x. I cannot imagine someone running
|
---|
82 | # CMake on those ancient systems
|
---|
83 | CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
|
---|
84 |
|
---|
85 | CMAKE_SYSTEM_NAME STREQUAL "Haiku")
|
---|
86 |
|
---|
87 | math(EXPR CMAKESONAME "${VERSIONCHANGE} - ${VERSIONDEL}")
|
---|
88 | set(CMAKEVERSION "${CMAKESONAME}.${VERSIONDEL}.${VERSIONADD}")
|
---|
89 | else()
|
---|
90 | unset(CMAKESONAME)
|
---|
91 | endif()
|
---|
92 |
|
---|
93 | ## Library definition
|
---|
94 |
|
---|
95 | # Add "_imp" as a suffix before the extension to avoid conflicting with
|
---|
96 | # the statically linked "libcurl.lib" (typically with MSVC)
|
---|
97 | if(WIN32 AND
|
---|
98 | NOT IMPORT_LIB_SUFFIX AND
|
---|
99 | CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL CMAKE_IMPORT_LIBRARY_SUFFIX)
|
---|
100 | set(IMPORT_LIB_SUFFIX "_imp")
|
---|
101 | endif()
|
---|
102 |
|
---|
103 | # Whether to do a single compilation pass for libcurl sources and reuse these
|
---|
104 | # objects to generate both static and shared target.
|
---|
105 | if(NOT DEFINED SHARE_LIB_OBJECT)
|
---|
106 | # Enable it by default on platforms where PIC is the default for both shared
|
---|
107 | # and static and there is a way to tell the linker which libcurl symbols it
|
---|
108 | # should export (vs. marking these symbols exportable at compile-time).
|
---|
109 | if(WIN32)
|
---|
110 | set(SHARE_LIB_OBJECT ON)
|
---|
111 | else()
|
---|
112 | # On other platforms, make it an option disabled by default
|
---|
113 | set(SHARE_LIB_OBJECT OFF)
|
---|
114 | endif()
|
---|
115 | endif()
|
---|
116 |
|
---|
117 | if(WIN32)
|
---|
118 | # Define CURL_STATICLIB always, to disable __declspec(dllexport) for exported
|
---|
119 | # libcurl symbols. We handle exports via libcurl.def instead. Except with
|
---|
120 | # symbol hiding disabled or debug mode enabled, when we export _all_ symbols
|
---|
121 | # from libcurl DLL, without using libcurl.def.
|
---|
122 | add_definitions("-DCURL_STATICLIB")
|
---|
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 | POSITION_INDEPENDENT_CODE ON)
|
---|
131 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
132 | set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
133 | set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
134 | endif()
|
---|
135 | if(CURL_HAS_LTO)
|
---|
136 | set_target_properties(${LIB_OBJECT} PROPERTIES
|
---|
137 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
138 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
139 | endif()
|
---|
140 |
|
---|
141 | target_include_directories(${LIB_OBJECT} INTERFACE
|
---|
142 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
143 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
144 |
|
---|
145 | set(LIB_SOURCE $<TARGET_OBJECTS:${LIB_OBJECT}>)
|
---|
146 | else()
|
---|
147 | set(LIB_SOURCE ${HHEADERS} ${CSOURCES})
|
---|
148 | endif()
|
---|
149 |
|
---|
150 | # we want it to be called libcurl on all platforms
|
---|
151 | if(BUILD_STATIC_LIBS)
|
---|
152 | list(APPEND libcurl_export ${LIB_STATIC})
|
---|
153 | add_library(${LIB_STATIC} STATIC ${LIB_SOURCE})
|
---|
154 | add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC})
|
---|
155 | target_link_libraries(${LIB_STATIC} PRIVATE ${CURL_LIBS})
|
---|
156 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
157 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
158 | PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}"
|
---|
159 | SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}"
|
---|
160 | INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB")
|
---|
161 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
162 | set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
163 | set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
164 | endif()
|
---|
165 | if(CURL_HAS_LTO)
|
---|
166 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
167 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
168 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
169 | endif()
|
---|
170 | if(CMAKEVERSION AND CMAKESONAME)
|
---|
171 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
172 | VERSION ${CMAKEVERSION} SOVERSION ${CMAKESONAME})
|
---|
173 | endif()
|
---|
174 |
|
---|
175 | target_include_directories(${LIB_STATIC} INTERFACE
|
---|
176 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
177 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
178 | endif()
|
---|
179 |
|
---|
180 | if(BUILD_SHARED_LIBS)
|
---|
181 | list(APPEND libcurl_export ${LIB_SHARED})
|
---|
182 | add_library(${LIB_SHARED} SHARED ${LIB_SOURCE})
|
---|
183 | add_library(${PROJECT_NAME}::${LIB_SHARED} ALIAS ${LIB_SHARED})
|
---|
184 | if(WIN32)
|
---|
185 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libcurl.rc)
|
---|
186 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
187 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "${CURL_SOURCE_DIR}/libcurl.def")
|
---|
188 | endif()
|
---|
189 | endif()
|
---|
190 | target_link_libraries(${LIB_SHARED} PRIVATE ${CURL_LIBS})
|
---|
191 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
192 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
193 | PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}"
|
---|
194 | IMPORT_PREFIX "" IMPORT_SUFFIX "${IMPORT_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
|
---|
195 | POSITION_INDEPENDENT_CODE ON)
|
---|
196 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
197 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
198 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
199 | endif()
|
---|
200 | if(CURL_HAS_LTO)
|
---|
201 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
202 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
203 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
204 | endif()
|
---|
205 | if(CMAKEVERSION AND CMAKESONAME)
|
---|
206 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
207 | VERSION ${CMAKEVERSION} SOVERSION ${CMAKESONAME})
|
---|
208 | endif()
|
---|
209 |
|
---|
210 | target_include_directories(${LIB_SHARED} INTERFACE
|
---|
211 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
212 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
213 | endif()
|
---|
214 |
|
---|
215 | add_library(${LIB_NAME} ALIAS ${LIB_SELECTED})
|
---|
216 | add_library(${PROJECT_NAME}::${LIB_NAME} ALIAS ${LIB_SELECTED})
|
---|
217 |
|
---|
218 | if(CURL_ENABLE_EXPORT_TARGET)
|
---|
219 | if(BUILD_STATIC_LIBS)
|
---|
220 | install(TARGETS ${LIB_STATIC}
|
---|
221 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
222 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
223 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
224 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
225 | )
|
---|
226 | endif()
|
---|
227 | if(BUILD_SHARED_LIBS)
|
---|
228 | install(TARGETS ${LIB_SHARED}
|
---|
229 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
230 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
231 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
232 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
233 | )
|
---|
234 | endif()
|
---|
235 |
|
---|
236 | export(TARGETS ${libcurl_export}
|
---|
237 | FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
---|
238 | NAMESPACE ${PROJECT_NAME}::
|
---|
239 | )
|
---|
240 | endif()
|
---|