Skip to content

`/usr/include` is not added to `INCLUDE_DIRECTORIES` ?

a.h

a.cpp

CMakeLists.txt

B1/B2/b.h

It looks like /usr/include is ignored when populating INCLUDE_DIRECTORIES, but /usr/include/../include works. I am trying to use the compilers distributed by Anaconda 5. I have seen this on CentOS 6, CentOS 7 and Ubuntu 16. Below are files to reproduce the problem and the workaround.

Files

|-- a.cpp
|-- a.h
|-- B1
|   `-- B2
|       `-- b.h
`-- CMakeLists.txt

CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
PROJECT(AAA
		VERSION 1
		LANGUAGES CXX
		)

set(CMAKE_VERBOSE_MAKEFILE ON)
OPTION(DEBUG_CMAKE_TARGETS "enable debug output for cmake target properties" ON)
if(DEBUG_CMAKE_TARGETS)
	set(CMAKE_DEBUG_TARGET_PROPERTIES
            INCLUDE_DIRECTORIES
        )
endif()

add_library(libA SHARED a.cpp)

find_package(OpenGL REQUIRED)
message("OPENGL_INCLUDE_DIR: ${OPENGL_INCLUDE_DIR}")

target_sources(libA PRIVATE a.cpp)
set_target_properties(libA PROPERTIES
		  INCLUDE_DIRECTORIES   "${OPENGL_INCLUDE_DIR};${CMAKE_SOURCE_DIR}/B1"
		  )

a.cpp

#include "a.h"

bool hello(){
	return true;
}

a.h

#ifndef _a_h_
#define _a_h_

#include "B2/b.h"
#include "GL/gl.h"


#endif

B1/B2/b.h

#ifndef __b_h_
#define __b_h_

int GLOBAL_INT = 0;

#endif

Build

$ cmake ~/workspace_work/eman2
-- The CXX compiler identification is GNU 7.2.0
-- Check for working CXX compiler: /home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++
-- Check for working CXX compiler: /home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: /usr/lib64/libGL.so  
OPENGL_INCLUDE_DIR: /usr/include
-- Configuring done
CMake Debug Log at CMakeLists.txt:21 (set_target_properties):
  Used includes for target libA:

   * /usr/include
   * /home/gorgon/workspace_work/eman2/B1



-- Generating done
-- Build files have been written to: /home/gorgon/build-eman-deps-11

$ make
$ make
/home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -H/home/gorgon/workspace_work/eman2 -B/home/gorgon/build-eman-deps-11 --check-build-system CMakeFiles/Makefile.cmake 0
/home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -E cmake_progress_start /home/gorgon/build-eman-deps-11/CMakeFiles /home/gorgon/build-eman-deps-11/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/gorgon/build-eman-deps-11'
make -f CMakeFiles/libA.dir/build.make CMakeFiles/libA.dir/depend
make[2]: Entering directory `/home/gorgon/build-eman-deps-11'
cd /home/gorgon/build-eman-deps-11 && /home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -E cmake_depends "Unix Makefiles" /home/gorgon/workspace_work/eman2 /home/gorgon/workspace_work/eman2 /home/gorgon/build-eman-deps-11 /home/gorgon/build-eman-deps-11 /home/gorgon/build-eman-deps-11/CMakeFiles/libA.dir/DependInfo.cmake --color=
Scanning dependencies of target libA
make[2]: Leaving directory `/home/gorgon/build-eman-deps-11'
make -f CMakeFiles/libA.dir/build.make CMakeFiles/libA.dir/build
make[2]: Entering directory `/home/gorgon/build-eman-deps-11'
[ 50%] Building CXX object CMakeFiles/libA.dir/a.cpp.o
/home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++  -DlibA_EXPORTS -I/home/gorgon/workspace_work/eman2/B1  -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC   -o CMakeFiles/libA.dir/a.cpp.o -c /home/gorgon/workspace_work/eman2/a.cpp
In file included from /home/gorgon/workspace_work/eman2/a.cpp:1:0:
/home/gorgon/workspace_work/eman2/a.h:5:10: fatal error: GL/gl.h: No such file or directory
 #include "GL/gl.h"
          ^~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/libA.dir/a.cpp.o] Error 1
make[2]: Leaving directory `/home/gorgon/build-eman-deps-11'
make[1]: *** [CMakeFiles/libA.dir/all] Error 2
make[1]: Leaving directory `/home/gorgon/build-eman-deps-11'
make: *** [all] Error 2
$ cat CMakeFiles/libA.dir/flags.make 
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.9

# compile CXX with /home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++
CXX_FLAGS = -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC  

CXX_DEFINES = -DlibA_EXPORTS

CXX_INCLUDES = -I/home/gorgon/workspace_work/eman2/B1 

Workaround

set_target_properties(libA PROPERTIES
		  INCLUDE_DIRECTORIES   "${OPENGL_INCLUDE_DIR}/../include;${CMAKE_SOURCE_DIR}/B1"
		  )
$ make
/home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -H/home/gorgon/workspace_work/eman2 -B/home/gorgon/build-eman-deps-11 --check-build-system CMakeFiles/Makefile.cmake 0
OPENGL_INCLUDE_DIR: /usr/include
-- Configuring done
CMake Debug Log at CMakeLists.txt:21 (set_target_properties):
  Used includes for target libA:

   * /usr/include/../include
   * /home/gorgon/workspace_work/eman2/B1



-- Generating done
-- Build files have been written to: /home/gorgon/build-eman-deps-11
/home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -E cmake_progress_start /home/gorgon/build-eman-deps-11/CMakeFiles /home/gorgon/build-eman-deps-11/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/gorgon/build-eman-deps-11'
make -f CMakeFiles/libA.dir/build.make CMakeFiles/libA.dir/depend
make[2]: Entering directory `/home/gorgon/build-eman-deps-11'
cd /home/gorgon/build-eman-deps-11 && /home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -E cmake_depends "Unix Makefiles" /home/gorgon/workspace_work/eman2 /home/gorgon/workspace_work/eman2 /home/gorgon/build-eman-deps-11 /home/gorgon/build-eman-deps-11 /home/gorgon/build-eman-deps-11/CMakeFiles/libA.dir/DependInfo.cmake --color=
Scanning dependencies of target libA
make[2]: Leaving directory `/home/gorgon/build-eman-deps-11'
make -f CMakeFiles/libA.dir/build.make CMakeFiles/libA.dir/build
make[2]: Entering directory `/home/gorgon/build-eman-deps-11'
[ 50%] Building CXX object CMakeFiles/libA.dir/a.cpp.o
/home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++  -DlibA_EXPORTS -I/usr/include/../include -I/home/gorgon/workspace_work/eman2/B1  -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC   -o CMakeFiles/libA.dir/a.cpp.o -c /home/gorgon/workspace_work/eman2/a.cpp
[100%] Linking CXX shared library liblibA.so
/home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -E cmake_link_script CMakeFiles/libA.dir/link.txt --verbose=1
/home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++ -fPIC -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,liblibA.so -o liblibA.so CMakeFiles/libA.dir/a.cpp.o 
make[2]: Leaving directory `/home/gorgon/build-eman-deps-11'
[100%] Built target libA
make[1]: Leaving directory `/home/gorgon/build-eman-deps-11'
/home/gorgon/anaconda2/envs/eman-deps-11/bin/cmake -E cmake_progress_start /home/gorgon/build-eman-deps-11/CMakeFiles 0
$ cat CMakeFiles/libA.dir/flags.make 
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.9

# compile CXX with /home/gorgon/anaconda2/envs/eman-deps-11/bin/x86_64-conda_cos6-linux-gnu-c++
CXX_FLAGS = -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -fPIC  

CXX_DEFINES = -DlibA_EXPORTS

CXX_INCLUDES = -I/usr/include/../include -I/home/gorgon/workspace_work/eman2/B1 
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information