我试图让我的cmake项目自动编译,但我有一些困难,当我的path包含空格。
这里是我的命令行(Windows命令提示符)
C:\Code\codetrainerplugins-build>type %CODETRAINER_PATH%\include\common\exportapi.h #pragma once ... the file is found ...
这是我的CMakeLists.txt文件:
CMAKE_MINIMUM_REQUIRED (VERSION 2.6) PROJECT (CodeTrainerPlugins) MESSAGE("$ENV{CODETRAINER_PATH}") FIND_PATH (CODETRAINER_FRAMEWORK_PATH NAMES include/common/ExportApi.h PATHS ENV CODETRAINER_PATH ) if (CODETRAINER_FRAMEWORK_PATH) MESSAGE(STATUS "CodeTrainer Framework found at: ${CODETRAINER_FRAMEWORK_PATH}") else() MESSAGE(FATAL_ERROR "CodeTrainer Framework not found") endif() ADD_SUBDIRECTORY(function) ADD_SUBDIRECTORY(test)
这是CODETRAINER_PATHvariables包含空格时的输出(请参阅path中的空格):
C:\Code\codetrainerplugins-build>echo %CODETRAINER_PATH% "C:\Code Trainer" C:\Code\codetrainerplugins-build> C:\Code\codetrainerplugins-build>cmake ..\codetrainerplugins -- Building for: Visual Studio 10 "C:\Code Trainer" CMake Error at CMakeLists.txt:16 (MESSAGE): CodeTrainer Framework not found -- Configuring incomplete, errors occurred! See also "C:/Code/codetrainerplugins-build/CMakeFiles/CMakeOutput.log". C:\Code\codetrainerplugins-build>
但是当使用的path没有空格时,一切正常(见下文):
C:\Code\codetrainerplugins-build>echo %CODETRAINER_PATH% C:\CodeTrainer C:\Code\codetrainerplugins-build>cmake ..\codetrainerplugins C:\CodeTrainer -- CodeTrainer Framework found at: C:/CodeTrainer -- Configuring done -- Generating done -- Build files have been written to: C:/Code/codetrainerplugins-build C:\Code\codetrainerplugins-build>
你有解决这个问题的方法吗?
我使用Windows的cmake 2.8.12。
谢谢,尤利安
我必须承认,我也曾预料过这种方法也会“正常工作”,但是看起来它实际上是CODETRAINER_PATH
的引号,当它有引起问题的空间时。
在定义环境变量CODETRAINER_PATH
时不要加引号,或者修改你的CMake代码,如下所示:
STRING(REPLACE "\"" "" CODETRAINER_PATH_WITHOUT_QUOTES $ENV{CODETRAINER_PATH}) FIND_PATH(CODETRAINER_FRAMEWORK_PATH NAMES include/common/ExportApi.h PATHS ${CODETRAINER_PATH_WITHOUT_QUOTES} )