[CMake] include_directories converting CMAKE_BINARY_DIR into relative path

Russell L. Carter rcarter at esturion.net
Tue Jan 9 17:46:37 EST 2018


Greetings,

I am trying to generate a platform specific file by copying it from
the source tree into a specific directory in the separate
out-of-source build tree.  The file generation works fine.

When I try the following cmake code:

set(target_dir ${CMAKE_BINARY_DIR}/nail/platform)
message("target_dir: ${target_dir}")
include_directories(${target_dir})

where message displays:

target_dir: /home/rcarter/nail/core/build/g++7.Debug/nail/platform

That's what I want and the generated files exist in that directory.

However, I get the following error:

FAILED: nail/CMakeFiles/nail_core.dir/platform/time.cpp.o
/usr/local/bin/g++7  -Dnail_core_EXPORTS -I../../ -Inail/platform -g -O 
-std=c++17 -fno-omit-frame-pointer -fstack-protector -Wall -Wextra 
-fvisibility=hidden -fvisibility-inlines-hidden -fPIC -MD -MT 
nail/CMakeFiles/nail_core.dir/platform/time.cpp.o -MF 
nail/CMakeFiles/nail_core.dir/platform/time.cpp.o.d -o 
nail/CMakeFiles/nail_core.dir/platform/time.cpp.o -c nail/platform/time.cpp
nail/platform/time.cpp:2:10: fatal error: nail/platform/time.hpp: No 
such file or directory

Evidently the include_directories() command is converting the
the supplied absolute path to a relative path (-Inail/platform).

What should I do to get that include directory in the
build tree added correctly to the includes?  I suppose I could
add it manually to the CXX flags?  What's the best cmake
friendly way to handle this?

Thanks,
Russell


More information about the CMake mailing list