Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Curl Linking #466

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMake/Dependencies/libcurl-CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ if (WIN32)
set(CMAKE_ARGS ${CMAKE_ARGS} -DCMAKE_USE_WINSSL=1 -DCURL_STATIC_CRT=1)
endif()

SET(PATCH_COMMAND git apply --verbose --ignore-whitespace ${CMAKE_CURRENT_LIST_DIR}/libcurl-cmake-config.patch)

ExternalProject_Add(project_libcurl
GIT_REPOSITORY https://github.com/curl/curl.git
GIT_TAG curl-7_68_0
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
CMAKE_ARGS ${CMAKE_ARGS}
PATCH_COMMAND ${PATCH_COMMAND}
BUILD_ALWAYS TRUE
TEST_COMMAND "")
13 changes: 13 additions & 0 deletions CMake/Dependencies/libcurl-cmake-config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in
index 1294e173a..99c1e535f 100644
--- a/CMake/curl-config.cmake.in
+++ b/CMake/curl-config.cmake.in
@@ -10,3 +10,7 @@ endif()

include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")
+
+# For compatibility with CMake's FindCURL.cmake
+set(CURL_LIBRARIES @PROJECT_NAME@::libcurl)
+set_and_check(CURL_INCLUDE_DIR ${OPEN_SRC_INSTALL_PREFIX}/include)
\ No newline at end of file
7 changes: 7 additions & 0 deletions CMake/Utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function(build_dependency lib_name)
configure_file(
./CMake/Dependencies/lib${lib_name}-CMakeLists.txt
${OPEN_SRC_INSTALL_PREFIX}/lib${lib_name}/CMakeLists.txt COPYONLY)

# when OPEN_SRC_INSTALL_PREFIX has non-default value, patch files must be copied to temporary location,
# otherwise build fails as it couldn't refer to the caller's CMake process directory.
file(GLOB LIB_PATCHES "./CMake/Dependencies/lib${lib_name}-*.patch")
message(STATUS "Copying patches for dependency ${lib_name}: ${LIB_PATCHES}")
file(COPY ${LIB_PATCHES} DESTINATION ${OPEN_SRC_INSTALL_PREFIX}/lib${lib_name}/)

execute_process(
COMMAND ${CMAKE_COMMAND} ${build_args}
-DOPEN_SRC_INSTALL_PREFIX=${OPEN_SRC_INSTALL_PREFIX} -G
Expand Down
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,19 @@ else()
endif()

if(BUILD_COMMON_CURL)
if (WIN32)
if (OPEN_SRC_INSTALL_PREFIX)
set(CMAKE_PREFIX_PATH "${OPEN_SRC_INSTALL_PREFIX}/lib/cmake/curl" ${CMAKE_PREFIX_PATH})
find_package(CURL REQUIRED PATHS ${OPEN_SRC_INSTALL_PREFIX})
else()
find_package(CURL REQUIRED)
endif()
if (WIN32)
set(CURL_LIBRARIES CURL::libcurl)
else()
pkg_check_modules(CURL REQUIRED libcurl)
set(CURL_LIBRARIES curl)
set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${CURL_INCLUDE_DIR})
endif()

set(OPEN_SRC_INCLUDE_DIRS ${OPEN_SRC_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS})
link_directories(${CURL_LIBRARY_DIRS})
endif()

if (BUILD_COMMON_LWS)
Expand Down
Loading