我使用的是 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 版本),我会得到与您相同的错误。
关于cmake - 如何告诉 CMake 使用 Windows 路径,而不是 Cygwin 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45934985/