sqred
sqred

Reputation: 51

CMake is ignoring include directories

I've got another problem with my project. I managed to get cmake to compile it, but make won't run through. I get the error message, that some headers are not found, so I checked my include_directories according to this questions answer: Listing include_directories in CMake

My include_directories has all specified folders listed as I want, but the makefile neither does include an "INC" tag nor does cmake-gui display the include_directories property. Has anyone encountered a similar or likewise problem an can help me?

Edit:

top level cmake:

PROJECT(MyProject) 
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
# set the compiler flags
SET(CMAKE_CXX_COMPILER g++)
SET(CMAKE_CXX_FLAGS "-fPIC -g -D DEBUG -Wall -Wfatal-errors -fstrict-aliasing")

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}
                    ${GLEW_INCLUDE_DIR}
                    ${GLUT_INCLUDE_DIR}
                    ${GSL_INCLUDE_DIRS}                 
                    ${OpenCV_INCLUDE_DIRS} 
                    ${QT_INCLUDE_DIR}           
                    ${MyProject_SOURCE_DIR}/include)

and after that i've got some add_subdirectories. CMake runs without error, but make seems to ignore the last include_directories line.

Upvotes: 4

Views: 21627

Answers (1)

CoffeDeveloper
CoffeDeveloper

Reputation: 8317

Here's a quick checklist:

  • Make sure directory paths have no whitespaces, it may not affect CMake directly but it could cause problems to other tools (GCC, mingw-make/make)
  • Make sure you have correct Make command (try to run make in the directory in which you call cmake). Otherwise you can simply add a path to Make in environment so you are sure cmake see it.
  • print directory paths to be sure they are correct and inspect to see if they have whitespaces

    MESSAGE("${Boost_INCLUDE_DIR}")

    MESSAGE("${GLEW_INCLUDE_DIR}")

    ...

  • You actually should add headers to executable (not needed, but if you generate IDE project files you will see headers there to)

  • For each external library used try to compile a simple hello world to detect if that library is correctly installed (make a simple project using simple functions to see if that compiles, links and runs)
  • Make sure include directories path are correct #include <something.h> or #include "something.h" or #include <path/something.h> (or change include path that CMake set up in a wrong way)
  • Do you have installed those external libraries, haven't you? (CMake is not able to find them if you just "unzipped" them somewhere)

The way CMake packages are thought is the only thing I hate about CMake. (I manually setup 1 CMake project for every external library and then link it manually from my projects instead of using "Global Variables"). Most times it relies on some kind of installation process of those libraries, but it could be altered or go wrong in many ways you can't predict, while if you download a specific revision of a external library, build it yourself and set a path manually you are sure that if something is going wrong is fault of library maintainers and not yours or of some missing install information (if that goes wrong that means you are no longer on a working operating system :D )

Upvotes: 3

Related Questions