jpbarrette / curlpp

C++ wrapper around libcURL
http://www.curlpp.org
1.68k stars 360 forks source link

Fix build broken with static linked libcurl.a #172

Open laoshanxi opened 2 months ago

laoshanxi commented 2 months ago

The build with static libcurl.a will fail:

# cmake ..
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- curlpp version=[0.8.1]
-- curlpp version num=[000801]
-- Looking for CURL
CMake Warning (dev) at /usr/local/lib64/cmake/CURL/CURLConfig.cmake:51 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/FindCURL.cmake:68 (find_package)
  CMakeLists.txt:72 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/local/lib64/cmake/CURL/CURLConfig.cmake:54 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/FindCURL.cmake:68 (find_package)
  CMakeLists.txt:72 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found CURL: /usr/local/lib64/cmake/CURL/CURLConfig.cmake (found version "8.5.0")  
-- Found CURL version: 
-- Using CURL include dir(s): 
-- Using CURL lib(s): 
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "curlpp" links to target "OpenSSL::SSL" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "curlpp" links to target "OpenSSL::Crypto" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "curlpp" links to target "ZLIB::ZLIB" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0003 should be set before this line.  Add code such as

    if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
    endif(COMMAND cmake_policy)

  as early as possible but after the most recent call to
  cmake_minimum_required or cmake_policy(VERSION).  This warning appears
  because target "curlpp" links to some libraries for which the linker must
  search:

    -lpthread, OpenSSL::SSL, OpenSSL::Crypto, ZLIB::ZLIB

  and other libraries with known full path:

    /usr/local/lib64/libcurl.a

  CMake is adding directories in the second list to the linker search path in
  case they are needed to find libraries from the first list (for backwards
  compatibility with CMake 2.4).  Set policy CMP0003 to OLD or NEW to enable
  or disable this behavior explicitly.  Run "cmake --help-policy CMP0003" for
  more information.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /workspace/curlpp/build
laoshanxi commented 2 months ago

This change works with with cmake_minimum_required(VERSION 3.5) and -DCMAKE_POSITION_INDEPENDENT_CODE=ON for libcurl

[root@51dba5857ef0 b]# cmake -DOPENSSL_ROOT_DIR=/usr/local/ssl ..
-- curlpp version=[0.8.1]
-- curlpp version num=[000801]
-- Looking for CURL
-- Found CURL version:
-- Using CURL include dir(s):
-- Using CURL lib(s):
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/curlpp/b
[root@51dba5857ef0 b]# make
Consolidate compiler generated dependencies of target curlpp
[ 4%] Linking CXX shared library libcurlpp.so
[ 50%] Built target curlpp
[ 54%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Easy.cpp.o
[ 58%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Exception.cpp.o
[ 62%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Form.cpp.o
[ 66%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Multi.cpp.o
[ 70%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/OptionBase.cpp.o
[ 75%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Options.cpp.o
[ 79%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/cURLpp.cpp.o
[ 83%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/CurlHandle.cpp.o
[ 87%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/OptionList.cpp.o
[ 91%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/OptionSetter.cpp.o
[ 95%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/SList.cpp.o
[100%] Linking CXX static library libcurlpp.a
[100%] Built target curlpp_static
[root@51dba5857ef0 b]# git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f550b5..f30ea0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,4 @@
+cmake_minimum_required(VERSION 3.5)
project(curlpp)