CMake 变量在运行之间持续存在,即使它已被重置
CMake variable persisting between runs even though it was reset
我正在尝试使用 CMake 从 Ubuntu 交叉编译到 Windows。我已配置所有内容(同时安装了 mingw32 和 mingw64),并且我有两者的相关工具链文件。问题是我在一个工具链文件中设置的变量在使用后会在第二个 运行 中与另一个工具链文件一起存在。
这些是我的工具链文件:
Windows 64 位:(工具链-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 位:(工具链-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/
并且输出 still 以
开头
===Processor architecture: x64
Project - projectx64
我该怎么做才能解决此问题?
CMake 将缓存它在设置过程中找到的许多值。令人沮丧的是,它这样做到了尝试使用在命令行上指定的新选项重新创建项目根本行不通的地步。我找到的唯一解决方案是删除整个构建目录,或者删除构建目录中的特定缓存文件,我相信名为 CMakeCache.txt
。
我正在尝试使用 CMake 从 Ubuntu 交叉编译到 Windows。我已配置所有内容(同时安装了 mingw32 和 mingw64),并且我有两者的相关工具链文件。问题是我在一个工具链文件中设置的变量在使用后会在第二个 运行 中与另一个工具链文件一起存在。
这些是我的工具链文件:
Windows 64 位:(工具链-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 位:(工具链-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/
并且输出 still 以
开头===Processor architecture: x64
Project - projectx64
我该怎么做才能解决此问题?
CMake 将缓存它在设置过程中找到的许多值。令人沮丧的是,它这样做到了尝试使用在命令行上指定的新选项重新创建项目根本行不通的地步。我找到的唯一解决方案是删除整个构建目录,或者删除构建目录中的特定缓存文件,我相信名为 CMakeCache.txt
。