我有一个非常大的项目,我正在尝试从 GNU make 迁移到 cmake。因此,我认为拥有包含各种变量的中间文件是一个好方法。
由于我刚刚开始,这就是我对 top_directory/vars/CMakeLists.txt 的内容:
cmake_minimum_required(VERSION 2.8)
set(VARIABLE "value")
这样,在另一个文件夹中,我可以将此行添加到 CMakeLists.txt 中:
add_subdirectory(top_directory/vars)
但是,当尝试在 top_directory/vars/CMakeLists.txt 上运行 cmake 时,我收到以下错误:
me@host:/tmp>cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 7.3.1
-- Check for working C compiler: /usr/bin/g++
-- Check for working C compiler: /usr/bin/g++ -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/usr/bin/g++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /tmp/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_607e9/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_607e9.dir/build.make CMakeFiles/cmTC_607e9.dir/build
gmake[1]: Entering directory '/tmp/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_607e9.dir/testCCompiler.c.o
/usr/bin/g++ -o CMakeFiles/cmTC_607e9.dir/testCCompiler.c.o -c /tmp/CMakeFiles/CMakeTmp/testCCompiler.c
/tmp/CMakeFiles/CMakeTmp/testCCompiler.c:2:3: error: #error "The CMAKE_C_COMPILER is set to a C++ compiler"
# error "The CMAKE_C_COMPILER is set to a C++ compiler"
^~~~~
gmake[1]: *** [CMakeFiles/cmTC_607e9.dir/build.make:66: CMakeFiles/cmTC_607e9.dir/testCCompiler.c.o] Error 1
gmake[1]: Leaving directory '/tmp/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:126: cmTC_607e9/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt
-- Configuring incomplete, errors occurred!
See also "/tmp/CMakeFiles/CMakeOutput.log".
See also "/tmp/CMakeFiles/CMakeError.log".
现在我可以通过添加
-DCMAKE_C_COMPILER=gcc
来强制它,但这确实破坏了可移植性方面。
所以我的问题是:这是制作“可变”CMake 文件的正确方法吗?为什么 CMake 错误地检测到我的 C 编译器?
有用信息:
cmake --version
cmake version 3.11.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
gcc --version
gcc (SUSE Linux) 7.3.1 20180323 [gcc-7-branch revision 258812]
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
如果我可以提供任何其他信息,请告诉我。
使用
cmake -DCMAKE_C_COMPILER=/..../lnx64/gcc-8.3.0/bin/gcc -DCMAKE_CXX_COMPILER=/..../lnx64/gcc-8.3.0/bin/g++ ..