即使重置,CMake变量也会在运行之间保持不变

时间:2015-01-17 00:09:33

标签: build cmake cross-compiling

我尝试使用CMake从Ubuntu交叉编译到Windows。我已经配置了所有内容(安装mingw32和mingw64),我有两个相关的工具链文件。问题是我在一个工具链文件中设置的变量在使用之后,在第二次运行时仍然存在另一个工具链文件。

这些是我的工具链文件:

Windows 64位:(Toolchain-Ubuntu-mingw64.cmake)

set(CMAKE_SYSTEM_NAME Windows)

unset(PROCESSOR_ARCHITECTURE CACHE)
set(PROCESSOR_ARCHITECTURE x64)
message("===Processor architecture: " ${PROCESSOR_ARCHITECTURE})
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Windows 32位:(Toolchain-Ubuntu-mingw32.cmake)

set(CMAKE_SYSTEM_NAME Windows)

unset(PROCESSOR_ARCHITECTURE CACHE)
set(PROCESSOR_ARCHITECTURE x86)
message("===Processor architecture: " ${PROCESSOR_ARCHITECTURE})
set(TOOLCHAIN_PREFIX i686-w64-mingw32)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

这是我的CMakeLists.txt文件的顶部:

cmake_minimum_required(VERSION 2.8)

project("project")

set(SOURCE_FILE_LIST main.c)

set(ARCH_PROJECT_NAME ${PROJECT_NAME}${PROCESSOR_ARCHITECTURE})
message("Project - " ${ARCH_PROJECT_NAME})

...

当我跑步时

cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchains/Toolchain-Ubuntu-mingw64.cmake ../src/

输出以:

开头
===Processor architecture: x64
Project - projectx64

当我跑步时出现意想不到的部分:

cmake -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchains/Toolchain-Ubuntu-mingw32.cmake ../src/

并且输出仍然

开头
===Processor architecture: x64
Project - projectx64

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

CMake将缓存在设置过程中找到的许多值。令人沮丧的是,它尝试使用命令行中指定的新选项重新创建项目根本不起作用。我发现的唯一解决方案是删除整个构建目录,或删除构建目录中的特定缓存文件,我相信称为CMakeCache.txt