我问这个是下次我使用CMake的时候提醒自己的.它永远不会坚持,谷歌的结果也不是很好.
在CMake中设置和使用变量的语法是什么?
我想检查一下我是否在Mac OS X中,并且具有以下代码
cmake_minimum_required (VERSION 3.0)
project (test)
set (FOO 1)
if (${FOO} AND ${APPLE})
message ("MAC OS X")
endif ()
Run Code Online (Sandbox Code Playgroud)
它在非OSX系统上失败并显示错误消息
CMake Error at CMakeLists.txt:4 (if):
if given arguments:
"1" "AND"
Unknown arguments specified
Run Code Online (Sandbox Code Playgroud)
如果我更换${APPLE}用APPLE,错误就走开了.但我有点困惑.什么时候应该引用变量${VAR}?何时不应该?
提前致谢.
我正在尝试组织一个 C++ 项目,该项目开始有很多文件。我想创建两个使用 Cmake 共享一些源文件的可执行文件。我在这里发现了一个有趣的过程:
下面是我的版本
file(GLOB Common_sources RELATIVE "Common" "*cpp")
file(GLOB Mps_sources RELATIVE "Mps" "*.cpp")
file(GLOB Mss_sources RELATIVE "Mss" "*.cpp")
add_executable(test_mss ${Common_sources} ${Mss_sources})
add_executable(test_mps ${Common_sources} ${Mps_sources})
Run Code Online (Sandbox Code Playgroud)
但是 CMake 抱怨
CMake Error at src/CMakeLists.txt:44 (add_executable):
add_executable called with incorrect number of arguments
CMake Error at src/CMakeLists.txt:45 (add_executable):
add_executable called with incorrect number of arguments
Run Code Online (Sandbox Code Playgroud)
说要查看CMakeOutput.log,但是文件实在是太长了,找不到有用的信息。
我检查了 CMake 文档,它似乎可以将第二个源作为附加参数。https://cmake.org/cmake/help/v3.0/command/add_executable.html
我想找到这个错误的来源。我有一种感觉,我在这里遗漏了一些明显的东西。