MantisBT - CMake
View Issue Details
0014787CMakeCMakepublic2014-03-05 09:122016-06-10 14:31
tibur 
Kitware Robot 
normalminoralways
closedmoved 
WindowsWindowsWin7
CMake 2.8.12.2 
 
0014787: Unable to include a directory named after a Visual Studio macro.
I am trying to include a directory defined by a Visual Studio macro name ($(BlahBlahBlah)). Using the following CMakeLists.txt, CMake concatenates the project working dir (d:/taf/Blah) with my macro name, leading to a wrong include directory.
cmake_minimum_required(VERSION 2.8)
include_directories("c:/")
include_directories("$(BlahBlahBlah)")
include_directories("d:/")
add_executable(Blah main.cpp)

Produces:
<AdditionalIncludeDirectories>c:\;d:\Taf\Blah\$(BlahBlahBlah);d:\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

No tags attached.
related to 0015001closed Kitware Robot add_custom_command: allow quoting of VS $(VAR) placeholders 
Issue History
2014-03-05 09:12tiburNew Issue
2014-03-05 11:44Brad KingNote Added: 0035304
2014-03-05 12:41tiburNote Added: 0035308
2014-03-05 13:02Brad KingNote Added: 0035310
2014-03-05 13:15tiburNote Added: 0035311
2014-03-05 13:33Brad KingNote Added: 0035312
2014-03-05 13:33Brad KingStatusnew => backlog
2014-03-05 16:13Stephen KellyNote Added: 0035318
2014-03-05 16:16Brad KingNote Added: 0035320
2014-03-05 16:18Stephen KellyNote Added: 0035321
2014-07-02 11:15Brad KingRelationship addedrelated to 0015001
2016-06-10 14:29Kitware RobotNote Added: 0042498
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0035304)
Brad King   
2014-03-05 11:44   
From the include_directories command documentation:

 http://www.cmake.org/cmake/help/v3.0/command/include_directories.html [^]
 "Relative paths are interpreted as relative to the current source directory."

The placeholder looks like a relative path. Some placeholders are meant to be part of a path rather than a full path, and there is no way to know the difference.

What are you trying to accomplish with the placeholder approach?
(0035308)
tibur   
2014-03-05 12:41   
Due to a include conflict, I need to reset Visual Studio $(IncludePath) before any other include directory.

Say I have this CMakeLists.txt:
include_directories(c:/BrokenIncludeDir")
This will generate:
<AdditionalIncludeDirectories>c:/BrokenIncludeDir;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

While I would like the C:/BrokenIncludeDir to be after %(AdditionalIncludeDirectories).
In the IDE, I can fix that by adding $(IncludePath) before c:/BrokenIncludeDir.

I tried to set the AFTER option, but the resulting order is the same.
(0035310)
Brad King   
2014-03-05 13:02   
Re 0014787:0035308: The AFTER option is for ordering among CMake-specified directories. Compilers typically keep the system include directories to themselves and there is no way to add things after them. IIRC the %(AdditionalIncludeDirectories) placeholder does not represent the system include directories anyway so its location does not matter.

Prepending $(IncludePath) is a platform- and generator-specific hack to solve this problem. It will not work with other generators such as "NMake Makefiles" or "Ninja". Some options are:

- Fix the breakage
- Use -Ic:/ and #include <BrokenIncludeDir/header.h> to work around it. This could be packaged inside wrapper headers to avoid modifying most of the existing sources.
- Add a cache entry to let the user specify the system include directories and then add them with the BEFORE option of include_directories. This essentially prepends $(IncludePath) in its explicit form.
(0035311)
tibur   
2014-03-05 13:15   
We already have the third workaround in place.
I think that adding, say a VERBATIM option to include_directories, preventing to prepend the current directory would do the trick nicely.
But if you don't think it might get useful, I guess we can close the ticket.
(0035312)
Brad King   
2014-03-05 13:33   
Re 0014787:0035311: I think it is reasonable to assume that if a path starts in "$(" then we can just trust that it has what the user wants and not treat it as a relative path. I would be open to a change accomplishing this. Note it also will need to adjust the implementation of policy CMP0021:

 http://www.cmake.org/cmake/help/v3.0/policy/CMP0021.html [^]

to not reject such paths as relative.
(0035318)
Stephen Kelly   
2014-03-05 16:13   
You might also try this hack:

 include_directories($<1:$(BlahBlahBlah)>)
(0035320)
Brad King   
2014-03-05 16:16   
Re 0014787:0035318: CMP0021 makes that an error.
(0035321)
Stephen Kelly   
2014-03-05 16:18   
Ah, indeed. That's evaluated late now.
(0042498)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.