如何告诉 CMake 使用 Windows 路径,而不是 Cygwin 路径?
How to tell CMake to use Windows paths, not Cygwin ones?
我在 Cygwin 上,我想调用安装在 Windows 上的编译器。我对路径格式有疑问。
有了这个就很简单了CMakeLists.txt
:
cmake_minimum_required(VERSION 3.6)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR Cortex-M4)
set(CMAKE_C_COMPILER iccarm.exe)
set(CMAKE_CXX_COMPILER iccarm.exe)
set(CMAKE_ASM_COMPILER iasmarm.exe)
project("test" C)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
if(NOT EXISTS main.c)
file(WRITE main.c "int main(void){return 0;}\n")
endif()
add_executable(
test
main.c
)
我在 CMake 检查编译器时遇到问题:
-- The C compiler identification is IAR
-- Check for working C compiler: /cygdrive/c/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: /cygdrive/c/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- broken
CMake Error at /usr/share/cmake-3.6.2/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/cygdrive/c/Program Files (x86)/IAR Systems/Embedded
Workbench 8.0/arm/bin/iccarm.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/nobody/home/sandbox/cmakeiar/CMakeFiles/CMakeTmp
这是因为 CMake 不知道,或者它应该知道,iccarm.exe
是一个需要 windows 路径的 Windows 程序。
是否有解决方案可以为 CMake 提供此信息?
我成像是这样的:
if(PLATFORM_IS_CYGWIN)
set(CMAKE_IS_WINDOWS_EXECUTABLE iccarm.exe)
endif()
将我的评论变成答案
请注意,Cygwin 的 CMake 会提供 /cygdrive
前缀,但 Windows 安装的 CMake 版本不会。
我已经 运行 在我的 PATH
环境中使用您的 CMakeLists.txt
IAR ARM 编译器进行了测试,并且可以从 Cygwin bash 中成功 运行 ] shell:
$ /cygdrive/c/Program\ Files/CMake/bin/cmake -G "Unix Makefiles" ..
-- The C compiler identification is IAR
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ...
如果我只调用 cmake ..
(Cygwin 版本),我会得到和你一样的错误。
我在 Cygwin 上,我想调用安装在 Windows 上的编译器。我对路径格式有疑问。
有了这个就很简单了CMakeLists.txt
:
cmake_minimum_required(VERSION 3.6)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR Cortex-M4)
set(CMAKE_C_COMPILER iccarm.exe)
set(CMAKE_CXX_COMPILER iccarm.exe)
set(CMAKE_ASM_COMPILER iasmarm.exe)
project("test" C)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
if(NOT EXISTS main.c)
file(WRITE main.c "int main(void){return 0;}\n")
endif()
add_executable(
test
main.c
)
我在 CMake 检查编译器时遇到问题:
-- The C compiler identification is IAR
-- Check for working C compiler: /cygdrive/c/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: /cygdrive/c/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- broken
CMake Error at /usr/share/cmake-3.6.2/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/cygdrive/c/Program Files (x86)/IAR Systems/Embedded
Workbench 8.0/arm/bin/iccarm.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/nobody/home/sandbox/cmakeiar/CMakeFiles/CMakeTmp
这是因为 CMake 不知道,或者它应该知道,iccarm.exe
是一个需要 windows 路径的 Windows 程序。
是否有解决方案可以为 CMake 提供此信息?
我成像是这样的:
if(PLATFORM_IS_CYGWIN)
set(CMAKE_IS_WINDOWS_EXECUTABLE iccarm.exe)
endif()
将我的评论变成答案
请注意,Cygwin 的 CMake 会提供 /cygdrive
前缀,但 Windows 安装的 CMake 版本不会。
我已经 运行 在我的 PATH
环境中使用您的 CMakeLists.txt
IAR ARM 编译器进行了测试,并且可以从 Cygwin bash 中成功 运行 ] shell:
$ /cygdrive/c/Program\ Files/CMake/bin/cmake -G "Unix Makefiles" ..
-- The C compiler identification is IAR
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ...
如果我只调用 cmake ..
(Cygwin 版本),我会得到和你一样的错误。