6

I want CMake to find the header for add_executable and find the .so file for target_link_libraries.

The header file I want to find is lcm-cpp.hpp (on ubunthu)

ls /usr/local/include/lcm/
eventlog.h  lcm_coretypes.h  lcm-cpp.hpp  lcm-cpp-impl.hpp  lcm.h

The CMakeLists.txt file in the root of my project

 cmake_minimum_required (VERSION 2.6)
 project (libFoo)
 include_directories(include /usr/local/include/lcm/)

 set(PROJECT_SRC
     src/Foo.cpp )

 set(PROJECT_H
     include/Foo.hpp )

 find_library(LCM_LIBRARY
     NAMES liblcm.so
     PATHS
     /usr/local/lib/
 )

add_library(liblcm STATIC IMPORTED)

add_library(foo_lib ${PROJECT_SRC} ${PROJECT_H})

add_executable(foo_lcm src/lcm_foo.cpp ${PROJECT_H} lcm-cpp.hpp)

The error I get:

  Cannot find source file:

  lcm-cpp.hpp

 Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
 .hxx .in .txx
3
  • Your question is very unclear. Can you elaborate? Wild guess: are you perhaps looking for include_directories and passing a full path to target_link_libraries? Commented Feb 26, 2014 at 21:26
  • @Angew include_directories(include /usr/local/include) does not work (I have a directory ./include for my own header files) Commented Feb 26, 2014 at 21:28
  • Please post an SSCCE: a minimal CMakeList & source code which demonstrates the problem, post your header file locations & any errors you are getting (compiler errors, I assume). Commented Feb 26, 2014 at 21:32

1 Answer 1

1

The CMake command include_directories() is used for specifying additional directories where the compiler should search for #included files. It does not affect CMake's search for source files at all.

If the file /usr/local/include/lcm/lcm-cpp.hpp is really a part of your executable (you'd want it listed in the project in Visual Studio, for example), you'll have to specify it with the full path:

add_executable(foo_lcm src/lcm_foo.cpp ${PROJECT_H} /usr/local/include/lcm/lcm-cpp.hpp)

However, based on its location, it looks more like a library external to your executable. If that's the case, it should not be listed in add_executable() at all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.