加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 如果环境变量有空格,则find_path不起作用

发布时间:2020-12-14 01:50:42 所属栏目:Windows 来源:网络整理
导读:我正在尝试让我的cmake项目自动编译,但是当我的路径包含空格时我遇到了一些困难. 这是我的命令行(windows命令提示符) C:Codecodetrainerplugins-buildtype %CODETRAINER_PATH%includecommonexportapi.h#pragma once... the file is found ... 这是我的C
我正在尝试让我的cmake项目自动编译,但是当我的路径包含空格时我遇到了一些困难.

这是我的命令行(windows命令提示符)

C:Codecodetrainerplugins-build>type %CODETRAINER_PATH%includecommonexportapi.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_PATH变量包含空格时的输出(请参阅路径中的空格):

C:Codecodetrainerplugins-build>echo %CODETRAINER_PATH%
"C:Code Trainer"
C:Codecodetrainerplugins-build>
C:Codecodetrainerplugins-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:Codecodetrainerplugins-build>

但是当使用的路径没有空格时,一切正常(见下文):

C:Codecodetrainerplugins-build>echo %CODETRAINER_PATH%
C:CodeTrainer

C:Codecodetrainerplugins-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:Codecodetrainerplugins-build>

您对如何解决此问题有任何解决方案吗?

我正在使用cmake 2.8.12 for Windows.

谢谢,
尤利安

我必须承认,我本来期望这也“正常工作”,但它看起来实际上是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}
          )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读