I'm trying to make my cmake project automatically compile but I have some difficulties when my path contains spaces.
Here is my command line (windows command prompt)
C:\Code\codetrainerplugins-build>type %CODETRAINER_PATH%\include\common\exportapi.h
#pragma once
... the file is found ...
Here is my CMakeLists.txt file:
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)
Here is the output when CODETRAINER_PATH variable contains spaces (see the space in the 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>
But when the path used has no spaces everything works ok (see below):
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>
Do you have any solution on how to solve this issue?
I am using cmake 2.8.12 for Windows.
Thanks, Iulian
I must admit, I would have expected this to "just work" too, however it looks like it's actually the quotation marks in CODETRAINER_PATH when it has spaces that are the cause of the problem.
Either don't add quotes when defining the environment variable CODETRAINER_PATH, or modify your CMake code something like this:
STRING(REPLACE "\"" "" CODETRAINER_PATH_WITHOUT_QUOTES $ENV{CODETRAINER_PATH})
FIND_PATH(CODETRAINER_FRAMEWORK_PATH 
          NAMES include/common/ExportApi.h
          PATHS ${CODETRAINER_PATH_WITHOUT_QUOTES}
          )
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With