Skip to content

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

Open

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

Activity

  1. jeremy-rifkin commented on Oct 17, 2025

    @jeremy-rifkin
    Owner

    Hi, it looks like cmake is finding cpptrace just fine but failing to find zstd. My guess is that zstd_DIR needs to be adjusted.

  2. xanzarx commented on Oct 17, 2025

    @xanzarx
    Author

    Thanks for reply.
    Were you able to configure cmake project using both cpptrace_DIR and zstd_dir at your end?
    If so, could you please share your zstd_DIR value?
    I tried different combinations of paths inside cpptrace install directory but no use (attempting to hinting cmake to cpptrace's nested zstd)
    e.g.

    export zstd_DIR="/home/xxxx/Projects/CMakePackages/cpptrace-1.0.4/lib/cmake/zstd"
    export zstd_DIR="/home/xxxx/Projects/CMakePackages/cpptrace-1.0.4/lib/cmake"
    export zstd_DIR="/home/xxxx/Projects/CMakePackages/cpptrace-1.0.4/lib"
    export zstd_DIR="/home/xxxx/Projects/CMakePackages/cpptrace-1.0.4"
  3. jeremy-rifkin commented on Feb 22, 2026

    @jeremy-rifkin
    Owner

    Hi, thanks for your patience. I was able to reproduce and I'll push a fix to dev, it will be part of the next release.

  4. added a commit that references this issue on Feb 22, 2026
    4bfe356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions