backward-cpp icon indicating copy to clipboard operation
backward-cpp copied to clipboard

CMAKE_MODULE_PATH doesn't work, but CMAKE_PREFIX_PATH does

Open ArekPiekarz opened this issue 7 years ago • 2 comments

README suggests appending a path to CMAKE_MODULE_PATH to find Backward-cpp.

However that results in a following error:

CMake Warning at CMakeLists.txt:7 (find_package):
  By not providing "FindBackward.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Backward",
  but CMake did not find one.

  Could not find a package configuration file provided by "Backward" with any
  of the following names:

    BackwardConfig.cmake
    backward-config.cmake

  Add the installation prefix of "Backward" to CMAKE_PREFIX_PATH or set
  "Backward_DIR" to a directory containing one of the above files.  If
  "Backward" provides a separate development package or SDK, be sure it has
  been installed.


Configuring done
CMake Warning (dev) at CMakeLists.txt:4 (add_executable):
  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 "backward-cpp-test" links to target "Backward::Backward" 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.

Generating done

Trying to compile it results in this build error:

14:54:43: Running steps for project backward-cpp-test...
14:54:43: Starting: "/usr/bin/cmake" --build . --target all
Scanning dependencies of target backward-cpp-test
[ 50%] Building CXX object CMakeFiles/backward-cpp-test.dir/main.cpp.o
/home/arek/dev/backward-cpp-test/main.cpp:2:10: fatal error: backward.hpp: No such file or directory
 #include <backward.hpp>
          ^~~~~~~~~~~~~~
compilation terminated.

Replacing CMAKE_MODULE_PATH with CMAKE_PREFIX_PATH fixes the problem for me. Note that I haven't checked older versions of CMake.

My setup: Xubuntu 17.10 x64 CMake 3.9.1 GCC 7.2.0

My CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

project(backward-cpp-test)
add_executable(${PROJECT_NAME} "main.cpp")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/external/backward-cpp)
find_package(Backward)
target_link_libraries(${PROJECT_NAME} PUBLIC Backward::Backward)

My main.cpp file:

#include <backward.hpp>

using namespace backward;

int main()
{
    StackTrace st;
    st.load_here(32);
    Printer p;
    p.print(st, std::cerr);

    return 0;
}

ArekPiekarz avatar Nov 19 '17 14:11 ArekPiekarz

Faced the same problem, tried replacing it with CMAKE_PREFIX_PATH in which case it progressed a bit further and failed with Backward_FOUND = FALSE.

aldanor avatar Dec 03 '17 12:12 aldanor

Maybe try this. For me it works...

find_package(Backward REQUIRED PATHS ${CMAKE_SOURCE_DIR}/external/backward-cpp NO_DEFAULT_PATH)
target_link_libraries(${PROJECT_NAME} PUBLIC Backward::Backward)

SirPustekuchen avatar Jun 29 '23 08:06 SirPustekuchen