Skip to content

Failed to configure cmake project that consumes cpptrace as 'find_package' dependency and cpptrace_DIR environment variable #291

@xanzarx

Description

@xanzarx

As far as I am aware cmake find_package thing attempting search packages in CMAKE_INSTALL_PREFIX directory or <package_name>_DIR defined in environment variables.
But option with <package_name>_DIR is failing on my system for a some reason.

System Info

  • OS: Ubuntu 24.04.3 LTS x86_64
  • cmake version 3.28.3

Steps to reproduce:

  1. Download, unpack cpptrace https://github.com/jeremy-rifkin/cpptrace/releases/tag/v1.0.4
  2. Cd to cpptrace source dir and configure cpptrace cmake project with all defaults, except CMAKE_INSTALL_PREFIX="<cpptrace_location>", <cpptrace_location> = /home/xxx/Projects/CMakePackages/cpptrace-1.0.4 in my case
cmake -S . -B out -DCMAKE_INSTALL_PREFIX="<cpptrace_location>"
  1. Build and install cpptrace
cmake --build out
cmake --install out
  1. Create 'Sandbox' project
#CMakeLists.txt
cmake_minimum_required(VERSION 3.26)

project(Sandbox CXX)

find_package(zstd)
find_package(cpptrace)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC cpptrace::cpptrace)
//main.cpp
#include <stdio.h>
#include <cpptrace/cpptrace.hpp>

void trace() {
    cpptrace::generate_trace().print();
}

int main(int argc, const char** argv)
{
    trace();
    printf("hello, world\n");
}
  1. Set environment variable cpptrace_DIR="<cpptrace_location>" and for nested zstd
export cpptrace_DIR="<cpptrace_location>"
export zstd_DIR="<cpptrace_location>"
  1. cd to 'Sandbox' project and run cmake configuration
cmake -S . -B out

Cmake gives configuration error

-- The CXX compiler identification is GNU 13.3.0
-- 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
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Could NOT find zstd (missing: zstd_LIBRARY zstd_INCLUDE_DIR)
CMake Warning at CMakeLists.txt:6 (find_package):
  Found package configuration file:

    <cpptrace_location>/lib/cmake/cpptrace/cpptrace-config.cmake

  but it set cpptrace_FOUND to FALSE so package "cpptrace" is considered to
  be NOT FOUND.  Reason given by package:

  cpptrace could not be found because dependency zstd could not be found.



-- Configuring done (0.3s)
CMake Error at CMakeLists.txt:9 (target_link_libraries):
  Target "Sandbox" links to:

    cpptrace::cpptrace

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Expected

Configuration without errors(?)
I am missing something in Sandbox project/system configuration?

If I do configuration of Sandbox project with CMAKE_INSTALL_PREFIX. Both configuration and build will be succeed.

cmake -S . -B out -DCMAKE_INSTALL_PREFIX="<cpptrace_location>"
-- Found zstd: <cpptrace_location>/lib/libzstd.a
-- Found Zstd: <cpptrace_location>/lib/libzstd.a
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.3")
-- Found zstd: <cpptrace_location>lib/libzstd.a (found version "1.5.7")
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: <home>/Sandbox/out

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions