我有一个非常大的项目,我试图从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.
如果我能提供任何其他信息,请告知我们。