CMake include directories and enviroment variables in C++ project

时间:2016-07-11 19:37:25

标签: c++ cmake

First timer on CMake. I am currently trying to create a visual studio 2013 solution (project) with CMake.

So i am facing 2 problems.

First one is that i use include_directories in my root cMakeLists.txt but instead of the directories to be included under the VC++ Directories tab they are included under C/C++ -> General -> Additional include directories .

The second problem is that i use an enviroment variable to include those directories , but instead of printing then in the Additional include directories as such : $(myVar)/lib/inc it prints it as a full path (e.g. C:/../lib/inc) and the end user won't have of course the same path as mine.

Thanks in advance for any responses.

1 个答案:

答案 0 :(得分:1)

我会尝试回答您的问题,以帮助您更好地了解CMake的工作原理。

  

首先,我在我的root cMakeLists.txt中使用include_directories,但不是要包含在VC ++目录选项卡下的目录,它们包含在C / C ++中 - >一般 - >其他包括目录。

这就是CMake生成Visual Studio项目的方式。我不知道有什么方法可以改变它。

  

第二个问题是我使用环境变量来包含那些目录,而不是打印然后在附加包含目录中:$(myVar)/ lib / inc它将它打印为完整路径(例如C: /../lib/inc)并且最终用户当然不会有与我相同的路径。

为了避免生成的项目中存在歧义,CMake倾向于解析完全限定路径的所有路径。这(除其他外)意味着 CMake项目不可重定位。这意味着CMake生成的项目不会在生成后移动,并且绝对不会发送给其他用户在其他计算机上使用。

这对您意味着:如果您使用CMake,您的所有最终用户也必须安装并使用CMake。如果这对您的最终用户来说不可行或不实用,那么CMake不是此特定项目的解决方案。