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 these sources separately to avoid memdebug.h redefinitions
|
---|
60 | # applying to them.
|
---|
61 | set_source_files_properties(memdebug.c curl_multibyte.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 | ## Library definition
|
---|
89 |
|
---|
90 | # Add "_imp" as a suffix before the extension to avoid conflicting with
|
---|
91 | # the statically linked "libcurl.lib" (typically with MSVC)
|
---|
92 | if(WIN32 AND
|
---|
93 | NOT IMPORT_LIB_SUFFIX AND
|
---|
94 | CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL CMAKE_IMPORT_LIBRARY_SUFFIX)
|
---|
95 | set(IMPORT_LIB_SUFFIX "_imp")
|
---|
96 | endif()
|
---|
97 |
|
---|
98 | # Whether to do a single compilation pass for libcurl sources and reuse these
|
---|
99 | # objects to generate both static and shared target.
|
---|
100 | if(NOT DEFINED SHARE_LIB_OBJECT)
|
---|
101 | # Enable it by default on platforms where PIC is the default for both shared
|
---|
102 | # and static and there is a way to tell the linker which libcurl symbols it
|
---|
103 | # should export (vs. marking these symbols exportable at compile-time).
|
---|
104 | if(WIN32)
|
---|
105 | set(SHARE_LIB_OBJECT ON)
|
---|
106 | else()
|
---|
107 | # On other platforms, make it an option disabled by default
|
---|
108 | set(SHARE_LIB_OBJECT OFF)
|
---|
109 | endif()
|
---|
110 | endif()
|
---|
111 |
|
---|
112 | if(WIN32)
|
---|
113 | # Define CURL_STATICLIB always, to disable __declspec(dllexport) for exported
|
---|
114 | # libcurl symbols. We handle exports via libcurl.def instead. Except with
|
---|
115 | # symbol hiding disabled or debug mode enabled, when we export _all_ symbols
|
---|
116 | # from libcurl DLL, without using libcurl.def.
|
---|
117 | add_definitions("-DCURL_STATICLIB")
|
---|
118 | endif()
|
---|
119 |
|
---|
120 | if(SHARE_LIB_OBJECT)
|
---|
121 | set(LIB_OBJECT "libcurl_object")
|
---|
122 | add_library(${LIB_OBJECT} OBJECT ${HHEADERS} ${CSOURCES})
|
---|
123 | target_link_libraries(${LIB_OBJECT} PRIVATE ${CURL_LIBS})
|
---|
124 | set_target_properties(${LIB_OBJECT} PROPERTIES
|
---|
125 | POSITION_INDEPENDENT_CODE ON)
|
---|
126 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
127 | set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
128 | set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
129 | endif()
|
---|
130 | if(CURL_HAS_LTO)
|
---|
131 | set_target_properties(${LIB_OBJECT} PROPERTIES
|
---|
132 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
133 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
134 | endif()
|
---|
135 |
|
---|
136 | target_include_directories(${LIB_OBJECT} INTERFACE
|
---|
137 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
138 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
139 |
|
---|
140 | set(LIB_SOURCE $<TARGET_OBJECTS:${LIB_OBJECT}>)
|
---|
141 | else()
|
---|
142 | set(LIB_SOURCE ${HHEADERS} ${CSOURCES})
|
---|
143 | endif()
|
---|
144 |
|
---|
145 | # we want it to be called libcurl on all platforms
|
---|
146 | if(BUILD_STATIC_LIBS)
|
---|
147 | list(APPEND libcurl_export ${LIB_STATIC})
|
---|
148 | add_library(${LIB_STATIC} STATIC ${LIB_SOURCE})
|
---|
149 | add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC})
|
---|
150 | target_link_libraries(${LIB_STATIC} PRIVATE ${CURL_LIBS})
|
---|
151 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
152 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
153 | PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}"
|
---|
154 | SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}"
|
---|
155 | INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB")
|
---|
156 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
157 | set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
158 | set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
159 | endif()
|
---|
160 | if(CURL_HAS_LTO)
|
---|
161 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
162 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
163 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
164 | endif()
|
---|
165 | if(CMAKEVERSION AND CMAKESONAME)
|
---|
166 | set_target_properties(${LIB_STATIC} PROPERTIES
|
---|
167 | VERSION ${CMAKEVERSION} SOVERSION ${CMAKESONAME})
|
---|
168 | endif()
|
---|
169 |
|
---|
170 | target_include_directories(${LIB_STATIC} INTERFACE
|
---|
171 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
172 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
173 | endif()
|
---|
174 |
|
---|
175 | if(BUILD_SHARED_LIBS)
|
---|
176 | list(APPEND libcurl_export ${LIB_SHARED})
|
---|
177 | add_library(${LIB_SHARED} SHARED ${LIB_SOURCE})
|
---|
178 | add_library(${PROJECT_NAME}::${LIB_SHARED} ALIAS ${LIB_SHARED})
|
---|
179 | if(WIN32)
|
---|
180 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libcurl.rc)
|
---|
181 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
182 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "${CURL_SOURCE_DIR}/libcurl.def")
|
---|
183 | endif()
|
---|
184 | endif()
|
---|
185 | target_link_libraries(${LIB_SHARED} PRIVATE ${CURL_LIBS})
|
---|
186 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
187 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
188 | PREFIX "" OUTPUT_NAME "${LIBCURL_OUTPUT_NAME}"
|
---|
189 | IMPORT_PREFIX "" IMPORT_SUFFIX "${IMPORT_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
|
---|
190 | POSITION_INDEPENDENT_CODE ON)
|
---|
191 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
192 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_FLAGS "${CURL_CFLAG_SYMBOLS_HIDE}")
|
---|
193 | set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
194 | endif()
|
---|
195 | if(CURL_HAS_LTO)
|
---|
196 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
197 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
198 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
199 | endif()
|
---|
200 | if(CMAKEVERSION AND CMAKESONAME)
|
---|
201 | set_target_properties(${LIB_SHARED} PROPERTIES
|
---|
202 | VERSION ${CMAKEVERSION} SOVERSION ${CMAKESONAME})
|
---|
203 | endif()
|
---|
204 |
|
---|
205 | target_include_directories(${LIB_SHARED} INTERFACE
|
---|
206 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
207 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
208 | endif()
|
---|
209 |
|
---|
210 | add_library(${LIB_NAME} ALIAS ${LIB_SELECTED})
|
---|
211 | add_library(${PROJECT_NAME}::${LIB_NAME} ALIAS ${LIB_SELECTED})
|
---|
212 |
|
---|
213 | if(CURL_ENABLE_EXPORT_TARGET)
|
---|
214 | if(BUILD_STATIC_LIBS)
|
---|
215 | install(TARGETS ${LIB_STATIC}
|
---|
216 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
217 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
218 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
219 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
220 | )
|
---|
221 | endif()
|
---|
222 | if(BUILD_SHARED_LIBS)
|
---|
223 | install(TARGETS ${LIB_SHARED}
|
---|
224 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
225 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
226 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
227 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
228 | )
|
---|
229 | endif()
|
---|
230 |
|
---|
231 | export(TARGETS ${libcurl_export}
|
---|
232 | FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
---|
233 | NAMESPACE ${PROJECT_NAME}::
|
---|
234 | )
|
---|
235 | endif()
|
---|