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
                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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With