cpr icon indicating copy to clipboard operation
cpr copied to clipboard

Cmake error "includes target "X" which requires target "cpr" that is not in any export set"

Open Nightyly opened this issue 2 years ago • 1 comments

Description

I am creating a library that depends on cpr, so I followed the instructions in the Usage section of the readme, and added that to my CMakeLists.txt

cmake_minimum_required(VERSION 3.14)

include(cmake/prelude.cmake)

project(
    CPPRAW
    VERSION 0.1.0
    DESCRIPTION "Short description"
    HOMEPAGE_URL "https://example.com/"
    LANGUAGES CXX
)

include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake)

set(JSON_Install ON)

# ---- Declare library ----

add_library(
    CPPRAW_CPPRAW
    source/CPPRAW.cpp
	source/post.cpp
	source/request.cpp
	source/subreddit.cpp
)
add_library(CPPRAW::CPPRAW ALIAS CPPRAW_CPPRAW)

include(GenerateExportHeader)
generate_export_header(
    CPPRAW_CPPRAW
    BASE_NAME CPPRAW
    EXPORT_FILE_NAME export/CPPRAW/CPPRAW_export.hpp
    CUSTOM_CONTENT_FROM_VARIABLE pragma_suppress_c4251
)

if(NOT BUILD_SHARED_LIBS)
  target_compile_definitions(CPPRAW_CPPRAW PUBLIC CPPRAW_STATIC_DEFINE)
endif()

set_target_properties(
    CPPRAW_CPPRAW PROPERTIES
    CXX_VISIBILITY_PRESET hidden
    VISIBILITY_INLINES_HIDDEN YES
    VERSION "${PROJECT_VERSION}"
    SOVERSION "${PROJECT_VERSION_MAJOR}"
    EXPORT_NAME CPPRAW
    OUTPUT_NAME CPPRAW
)

target_include_directories(
    CPPRAW_CPPRAW ${warning_guard}
    PUBLIC
    "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
)

target_include_directories(
    CPPRAW_CPPRAW SYSTEM
    PUBLIC
    "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/export>"
)

include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
                         GIT_TAG 871ed52d350214a034f6ef8a3b8f51c5ce1bd400) # The commit hash for 1.9.0. Replace with the latest from: https://github.com/libcpr/cpr/releases
FetchContent_MakeAvailable(cpr)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.1/json.tar.xz)
FetchContent_MakeAvailable(json)

target_link_libraries(CPPRAW_CPPRAW PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(CPPRAW_CPPRAW PRIVATE cpr::cpr)

target_compile_features(CPPRAW_CPPRAW PUBLIC cxx_std_17)

# ---- Install rules ----

if(NOT CMAKE_SKIP_INSTALL_RULES)
  include(cmake/install-rules.cmake)
endif()

# ---- Examples ----

if(PROJECT_IS_TOP_LEVEL)
  option(BUILD_EXAMPLES "Build examples tree." "${CPPRAW_DEVELOPER_MODE}")
  if(BUILD_EXAMPLES)
    add_subdirectory(example)
  endif()
endif()

# ---- Developer mode ----

if(NOT CPPRAW_DEVELOPER_MODE)
  return()
elseif(NOT PROJECT_IS_TOP_LEVEL)
  message(
      AUTHOR_WARNING
      "Developer mode is intended for developers of CPPRAW"
  )
endif()

include(cmake/dev-mode.cmake)

Expected Behavior

cpr should link with my project

Actual Behavior

Error when doing cmake ..

-- C++ Requests CMake Options
-- =======================================================
--   CPR_GENERATE_COVERAGE: OFF
--   CPR_CURL_NOSIGNAL: OFF
--   CPR_USE_SYSTEM_GTEST: OFF
--   CPR_FORCE_USE_SYSTEM_CURL: OFF
--   CPR_ENABLE_SSL: ON
--   CPR_FORCE_OPENSSL_BACKEND: OFF
--   CPR_FORCE_WINSSL_BACKEND: OFF
--   CPR_FORCE_DARWINSSL_BACKEND: OFF
--   CPR_FORCE_MBEDTLS_BACKEND: OFF
--   CPR_ENABLE_LINTING: OFF
--   CPR_ENABLE_CPPCHECK: OFF
--   CPR_BUILD_TESTS: OFF
--   CPR_BUILD_TESTS_SSL: OFF
-- =======================================================
-- Automatically detecting SSL backend.
-- Detecting SSL backend...
-- SSL auto detect: Using WinSSL.
-- Configuring build in curl...
-- Using CMake version 3.23.1
-- ZLIB_HEADER_VERSION: 1.2.11
-- ZLIBNG_HEADER_VERSION: 2.0.6
-- Arch detected: 'x86_64'
-- Basearch of 'x86_64' has been detected as: 'x86'
-- Architecture supports unaligned reads
-- Architecture supports unaligned reads of > 4 bytes
-- Architecture-specific source files: arch/x86/x86.c;arch/x86/slide_avx.c;arch/x86/chunkset_avx.c;arch/x86/compare258_avx.c;arch/x86/adler32_avx.c;arch/x86/insert_string_sse.c;arch/x86/compare258_sse.c;arch/x86/chunkset_sse.c;arch/x86/slide_sse.c;arch/x86/adler32_ssse3.c;arch/x86/crc_folding.c
-- The following features have been enabled:

 * CMAKE_BUILD_TYPE, Build type: Debug (selected)
 * WITH_GZFILEOP, Compile with support for gzFile related functions
 * ZLIB_COMPAT, Compile with zlib compatible API
 * WITH_OPTIM, Build with optimisation
 * WITH_NEW_STRATEGIES, Use new strategies
 * WITH_UNALIGNED, Support unaligned reads on platforms that support it
 * WITH_AVX2, Build with AVX2
 * WITH_SSE2, Build with SSE2
 * WITH_SSSE3, Build with SSSE3
 * WITH_SSE4, Build with SSE4
 * WITH_PCLMULQDQ, Build with PCLMULQDQ
 * AVX2_SLIDEHASH, Support AVX2 optimized slide_hash, using "-mavx2"
 * AVX_CHUNKSET, Support AVX optimized chunkset, using "-mavx2"
 * AVX2_COMPARE258, Support AVX2 optimized compare258, using "-mavx2"
 * AVX2_ADLER32, Support AVX2-accelerated adler32, using "-mavx2"
 * SSE42_CRC, Support SSE4.2 optimized CRC hash generation, using "-msse4"
 * SSE42_COMPARE258, Support SSE4.2 optimized compare258, using "-msse4"
 * SSSE3_ADLER32, Support SSSE3-accelerated adler32, using "-mssse3"
 * PCLMUL_CRC, Support CRC hash generation using PCLMULQDQ, using "-mssse3 -msse4 -mpclmul"

-- The following OPTIONAL packages have been found:

 * Git

-- The following features have been disabled:

 * ZLIB_ENABLE_TESTS, Build test binaries
 * ZLIB_DUAL_LINK, Dual link tests against system zlib
 * WITH_FUZZERS, Build test/fuzz
 * WITH_NATIVE_INSTRUCTIONS, Instruct the compiler to use the full instruction set on this host (gcc/clang -march=native)
 * WITH_MAINTAINER_WARNINGS, Build with project maintainer warnings
 * WITH_CODE_COVERAGE, Enable code coverage reporting
 * WITH_INFLATE_STRICT, Build with strict inflate distance checking
 * WITH_INFLATE_ALLOW_INVALID_DIST, Build with zero fill for inflate invalid distances
 * INSTALL_UTILS, Copy minigzip and minideflate during install

-- Enabled curl SSL
-- curl version=[7.80.0]
-- Could NOT find LibSSH2 (missing: LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
-- Enabled features: SSL IPv6 unixsockets libz AsynchDNS Largefile SSPI alt-svc HSTS SPNEGO Kerberos NTLM
-- Enabled protocols: HTTP HTTPS
-- Enabled SSL backends: Schannel
-- Using the multi-header code from D:/Docs/C++/prueba/CPPRAW/build/_deps/json-src/include/
-- Configuring done
CMake Error: install(EXPORT "CPPRAWTargets" ...) includes target "CPPRAW_CPPRAW" which requires target "cpr" that is not in any export set.
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Possible Fix

I had the same problem with nlohmann/json, but fixed it with adding set(JSON_Install ON) after analyzing the CMakeLists.txt of the nlohmann repo, but cpr does not seem to have an equivalent

Steps to Reproduce

  1. Use cmake-init to create a new static/shared library
  2. Add
include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
                         GIT_TAG 871ed52d350214a034f6ef8a3b8f51c5ce1bd400) # The commit hash for 1.9.0. Replace with the latest from: https://github.com/libcpr/cpr/releases
FetchContent_MakeAvailable(cpr)
target_link_libraries(PROJECT_NAME PRIVATE cpr::cpr)

to the CMakeLists.txt of the generated project 3. mkdir build && cd build && cmake .. 4. CMake Error: install(EXPORT "PROJECT_NAMETargets" ...) includes target "PROJECT_NAME_PROJECT_NAME" which requires target "cpr" that is not in any export set.

Your Environment

  • Version used: 1.9.0, master
  • Where did you get it from (e.g. conan, vcpkg, master, ...): 1.9.0 via FetchContent
  • Operating System and version: Windows 10

Nightyly avatar Sep 05 '22 18:09 Nightyly

Did you use system curl? In order to install cpr, you have to use system curl.

KingKili avatar Sep 06 '22 06:09 KingKili

Closing due to no response. Feel free to reopen in case this is still an issue for you.

COM8 avatar Sep 27 '22 07:09 COM8