Browse Source

Support spaces in source and/or build tree path for Windows build.
Close #779.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
4ff826ddf8

+ 2 - 3
CMake/Modules/Urho3D-CMake-common.cmake

@@ -732,8 +732,7 @@ macro (enable_pch HEADER_PATHNAME)
                     endif ()
                     endif ()
                 endif ()
                 endif ()
                 string (REPLACE ";" " -D" COMPILE_DEFINITIONS "-D${COMPILE_DEFINITIONS}")
                 string (REPLACE ";" " -D" COMPILE_DEFINITIONS "-D${COMPILE_DEFINITIONS}")
-                string (REPLACE ";" "\" -I\"" INCLUDE_DIRECTORIES "-I\"${INCLUDE_DIRECTORIES}")
-                set (INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES}\")
+                string (REPLACE ";" "\" -I\"" INCLUDE_DIRECTORIES "-I\"${INCLUDE_DIRECTORIES}\"")
                 # Make sure the precompiled headers are not stale by creating custom rules to re-compile the header as necessary
                 # Make sure the precompiled headers are not stale by creating custom rules to re-compile the header as necessary
                 file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PCH_FILENAME})
                 file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PCH_FILENAME})
                 foreach (CONFIG ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})   # These two vars are mutually exclusive
                 foreach (CONFIG ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})   # These two vars are mutually exclusive
@@ -754,7 +753,7 @@ macro (enable_pch HEADER_PATHNAME)
                     endif ()
                     endif ()
                     file (STRINGS ${CMAKE_CURRENT_BINARY_DIR}/${HEADER_FILENAME}.${CONFIG}.pch.deps DEPS)
                     file (STRINGS ${CMAKE_CURRENT_BINARY_DIR}/${HEADER_FILENAME}.${CONFIG}.pch.deps DEPS)
                     string (REGEX REPLACE "^deps: *| *\\; *" ";" DEPS ${DEPS})
                     string (REGEX REPLACE "^deps: *| *\\; *" ";" DEPS ${DEPS})
-                    string (REGEX REPLACE "\\\\ " "\ " DEPS "${DEPS}")
+                    string (REGEX REPLACE "\\\\ " "\ " DEPS "${DEPS}")  # Need to stringify the second time to preserve the semicolons
                     # Create the rule that depends on the included headers
                     # Create the rule that depends on the included headers
                     add_custom_command (OUTPUT ${HEADER_FILENAME}.${CONFIG}.pch.trigger
                     add_custom_command (OUTPUT ${HEADER_FILENAME}.${CONFIG}.pch.trigger
                         COMMAND ${CMAKE_${LANG}_COMPILER} @${CMAKE_CURRENT_BINARY_DIR}/${HEADER_FILENAME}.${CONFIG}.pch.rsp -o ${PCH_FILENAME}/${PCH_FILENAME}.${CONFIG} ${ABS_HEADER_PATHNAME}
                         COMMAND ${CMAKE_${LANG}_COMPILER} @${CMAKE_CURRENT_BINARY_DIR}/${HEADER_FILENAME}.${CONFIG}.pch.rsp -o ${PCH_FILENAME}/${PCH_FILENAME}.${CONFIG} ${ABS_HEADER_PATHNAME}

+ 0 - 2
Docs/GettingStarted.dox

@@ -62,8 +62,6 @@ Naturally you have to specify a fully qualified path to the build script for thi
 
 
 Our CMakeLists.txt files are designed to work with most of the generators supported by CMake: Makefile, Xcode, VS, and even Ninja. Which build script to use is determined by which CMake generator (and toolchain) you intend to use in your build tree. For native build, you can just use cmake_generic.sh or cmake_generic.bat to let CMake to detect and decide which generator to use automatically. CMake should default to use "Unix Makefiles" generator on Linux and Mac host systems and it should default to use 32-bit "Visual Studio" generator on Windows host system when it is installed.
 Our CMakeLists.txt files are designed to work with most of the generators supported by CMake: Makefile, Xcode, VS, and even Ninja. Which build script to use is determined by which CMake generator (and toolchain) you intend to use in your build tree. For native build, you can just use cmake_generic.sh or cmake_generic.bat to let CMake to detect and decide which generator to use automatically. CMake should default to use "Unix Makefiles" generator on Linux and Mac host systems and it should default to use 32-bit "Visual Studio" generator on Windows host system when it is installed.
 
 
-For Windows & Visual Studio, the path to Urho3D project or build tree should not contain spaces. Otherwise the build can be expected to fail.
-
 \section Build_Options Build options
 \section Build_Options Build options
 
 
 A number of build options can be defined when invoking the build scripts or when configurating the project interactively using cmake-gui. To use one of these build options on the command line interface, pass it in this format "-DOPTION=VALUE" without the quotes. Most of the build options are boolean variables where setting their values to 0 means disabling a feature or setting an option to false, while 1 means enabling a feature or setting an option to true. The table below shows all the available build options and their default values. Non-boolean build options generally do not have any default values and are marked with '-' in the table. However, a few build options marked with '*' have their default values set differently based on the value of other variables or external factors.
 A number of build options can be defined when invoking the build scripts or when configurating the project interactively using cmake-gui. To use one of these build options on the command line interface, pass it in this format "-DOPTION=VALUE" without the quotes. Most of the build options are boolean variables where setting their values to 0 means disabling a feature or setting an option to false, while 1 means enabling a feature or setting an option to true. The table below shows all the available build options and their default values. Non-boolean build options generally do not have any default values and are marked with '-' in the table. However, a few build options marked with '*' have their default values set differently based on the value of other variables or external factors.

+ 3 - 2
Source/Urho3D/CMakeLists.txt

@@ -260,10 +260,11 @@ if (NOT XCODE AND NOT MSVC)
         elseif (EMSCRIPTEN OR CMAKE_BINARY_DIR MATCHES " ")
         elseif (EMSCRIPTEN OR CMAKE_BINARY_DIR MATCHES " ")
             # Emscripten emar (llvm-ar) neither takes archives directly as input nor supports MRI-style script, so do it the hard way by first extracting the object (bitcode) files and appending them to final archive
             # Emscripten emar (llvm-ar) neither takes archives directly as input nor supports MRI-style script, so do it the hard way by first extracting the object (bitcode) files and appending them to final archive
             # Also do that when the build tree path contains spaces because MRI script does not support it (even with proper escape)
             # Also do that when the build tree path contains spaces because MRI script does not support it (even with proper escape)
+            get_filename_component (AR ${CMAKE_AR} NAME_WE)
             if (CMAKE_HOST_WIN32)
             if (CMAKE_HOST_WIN32)
                 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
                 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E remove_directory archives
                     COMMAND ${CMAKE_COMMAND} -E remove_directory archives
-                    COMMAND ${CMAKE_COMMAND} -E echo "Merging all archives into a single static library using emar.bat")
+                    COMMAND ${CMAKE_COMMAND} -E echo "Merging all archives into a single static library using ${AR}")
                 foreach (ARCHIVE ${ARCHIVES})
                 foreach (ARCHIVE ${ARCHIVES})
                     # Merge per library because Window cmd shell does not handle long argument list
                     # Merge per library because Window cmd shell does not handle long argument list
                     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory archives)
                     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory archives)
@@ -278,7 +279,7 @@ if (NOT XCODE AND NOT MSVC)
             else ()
             else ()
                 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
                 add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E remove_directory archives
                     COMMAND ${CMAKE_COMMAND} -E remove_directory archives
-                    COMMAND ${CMAKE_COMMAND} -E make_directory archives COMMENT "Merging all archives into a single static library using emar")
+                    COMMAND ${CMAKE_COMMAND} -E make_directory archives COMMENT "Merging all archives into a single static library using ${AR}")
                 foreach (ARCHIVE ${ARCHIVES})
                 foreach (ARCHIVE ${ARCHIVES})
                     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_AR} x ${ARCHIVE} WORKING_DIRECTORY archives)
                     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_AR} x ${ARCHIVE} WORKING_DIRECTORY archives)
                 endforeach ()
                 endforeach ()

+ 1 - 1
cmake_android.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -DANDROID=1
+@"%~dp0cmake_generic.bat" %* -DANDROID=1

+ 1 - 1
cmake_codeblocks.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -G "CodeBlocks - MinGW Makefiles"
+@"%~dp0cmake_generic.bat" %* -G "CodeBlocks - MinGW Makefiles"

+ 1 - 1
cmake_emscripten.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -DEMSCRIPTEN=1
+@"%~dp0cmake_generic.bat" %* -DEMSCRIPTEN=1

+ 14 - 6
cmake_generic.bat

@@ -24,6 +24,7 @@
 
 
 :: Determine source tree and build tree
 :: Determine source tree and build tree
 set "SOURCE=%~dp0"
 set "SOURCE=%~dp0"
+set "SOURCE=%SOURCE:~0,-1%"
 set "BUILD="
 set "BUILD="
 if "%~1" == "" goto :continue
 if "%~1" == "" goto :continue
 set "ARG1=%~1"
 set "ARG1=%~1"
@@ -34,28 +35,35 @@ shift
 if "%BUILD%" == "" if exist "%cd%\CMakeCache.txt" (set "BUILD=%cd%") else (goto :error)
 if "%BUILD%" == "" if exist "%cd%\CMakeCache.txt" (set "BUILD=%cd%") else (goto :error)
 
 
 :: Detect CMake toolchains directory if it is not provided explicitly
 :: Detect CMake toolchains directory if it is not provided explicitly
-if "%TOOLCHAINS%" == "" set "TOOLCHAINS=%SOURCE%/CMake/Toolchains"
-if not exist "%TOOLCHAINS%" if exist "%URHO3D_HOME%/share/Urho3D/CMake/Toolchains" set "TOOLCHAINS=%URHO3D_HOME%/share/Urho3D/CMake/Toolchains"
+if "%TOOLCHAINS%" == "" set "TOOLCHAINS=%SOURCE%\CMake\Toolchains"
+if not exist "%TOOLCHAINS%" if exist "%URHO3D_HOME%\share\Urho3D\CMake\Toolchains" set "TOOLCHAINS=%URHO3D_HOME%\share\Urho3D\CMake\Toolchains"
 :: BEWARE that the TOOLCHAINS variable leaks to caller's environment!
 :: BEWARE that the TOOLCHAINS variable leaks to caller's environment!
 
 
 :: Default to native generator and toolchain if none is specified explicitly
 :: Default to native generator and toolchain if none is specified explicitly
 set "OPTS="
 set "OPTS="
+set "BUILD_OPTS="
 set "arch="
 set "arch="
-if exist "%BUILD%\CMakeCache.txt" for /F "eol=/ delims=:= tokens=1-3" %%i in (%BUILD%\CMakeCache.txt) do if "%%i" == "URHO3D_64BIT" if "%%k" == "1" set "arch= Win64"
+set "cwd=%cd%"
+if exist "%BUILD%\CMakeCache.txt" cd "%BUILD%" && for /F "eol=/ delims=:= tokens=1-3" %%i in (CMakeCache.txt) do if "%%i" == "URHO3D_64BIT" if "%%k" == "1" set "arch= Win64"
+cd %cwd%
 :loop
 :loop
 if not "%~1" == "" (
 if not "%~1" == "" (
-    if "%~1" == "-DANDROID" if "%~2" == "1" set "OPTS=-G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=%TOOLCHAINS%\android.toolchain.cmake"
-    if "%~1" == "-DEMSCRIPTEN" if "%~2" == "1" set "OPTS=-G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=%TOOLCHAINS%\emscripten.toolchain.cmake"
+    if "%~1" == "-DANDROID" if "%~2" == "1" set "OPTS=-G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\android.toolchain.cmake""
+    if "%~1" == "-DEMSCRIPTEN" if "%~2" == "1" set "OPTS=-G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="%TOOLCHAINS%\emscripten.toolchain.cmake""
     if "%~1" == "-DURHO3D_64BIT" if "%~2" == "1" set "arch= Win64"
     if "%~1" == "-DURHO3D_64BIT" if "%~2" == "1" set "arch= Win64"
     if "%~1" == "-DURHO3D_64BIT" if "%~2" == "0" set "arch="
     if "%~1" == "-DURHO3D_64BIT" if "%~2" == "0" set "arch="
     if "%~1" == "-VS" set "OPTS=-G "Visual Studio %~2%arch%""
     if "%~1" == "-VS" set "OPTS=-G "Visual Studio %~2%arch%""
+    if "%~1" == "-G" set "OPTS=%OPTS% %~1 %2"
+    set "ARG1=%~1"
+    set "ARG2=%~2"
+    if "%ARG1:~0,2%" == "-D" set "BUILD_OPTS=%BUILD_OPTS% %ARG1%=%ARG2%"
     shift
     shift
     shift
     shift
     goto loop
     goto loop
 )
 )
 
 
 :: Create project with the chosen CMake generator and toolchain
 :: Create project with the chosen CMake generator and toolchain
-cmake -E make_directory %BUILD% && cmake -E chdir %BUILD% cmake %OPTS% %* %SOURCE%
+cmake -E make_directory "%BUILD%" && cmake -E chdir "%BUILD%" cmake %OPTS% %BUILD_OPTS% "%SOURCE%"
 
 
 goto :eof
 goto :eof
 :error
 :error

+ 1 - 1
cmake_mingw.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -G "MinGW Makefiles"
+@"%~dp0cmake_generic.bat" %* -G "MinGW Makefiles"

+ 1 - 1
cmake_ninja.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -G "Ninja"
+@"%~dp0cmake_generic.bat" %* -G "Ninja"

+ 1 - 1
cmake_vs2008.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -VS="9 2008"
+@"%~dp0cmake_generic.bat" %* -VS="9 2008"

+ 1 - 1
cmake_vs2010.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -VS=10
+@"%~dp0cmake_generic.bat" %* -VS=10

+ 1 - 1
cmake_vs2012.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -VS=11
+@"%~dp0cmake_generic.bat" %* -VS=11

+ 1 - 1
cmake_vs2013.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -VS=12
+@"%~dp0cmake_generic.bat" %* -VS=12

+ 1 - 1
cmake_vs2015.bat

@@ -20,4 +20,4 @@
 :: THE SOFTWARE.
 :: THE SOFTWARE.
 ::
 ::
 
 
-@%~dp0\cmake_generic.bat %* -VS=14
+@"%~dp0cmake_generic.bat" %* -VS=14