【发布时间】:2017-01-18 12:03:23
【问题描述】:
在 Linux 系统上:
执行以下命令:
mkdir test
cd test
mkdir mingw linux files
touch files/blah
添加以下 CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
PROJECT(TEST LANGUAGES CXX)
find_path(BLAH_DIR
blah
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/files
)
message(STATUS "BLAH_DIR=${BLAH_DIR}")
在“mingw”文件夹中,使用 mingw 工具链文件运行 cmake,如下所示:
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 )
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
在“linux”文件夹中,只需运行 cmake。
对于 MingW,我们得到:
BLAH_DIR=BLAH_DIR-NOTFOUND
对于 Linux,我们得到:
BLAH_DIR=/Development/test/files
正如预期的那样。
为什么 find_path 不适用于 MingW? 我应该提交关于 CMake 的错误报告吗?
【问题讨论】: