【发布时间】:2018-05-12 23:14:15
【问题描述】:
我正在尝试组织一个开始有很多文件的 C++ 项目。我想创建两个使用 Cmake 共享一些源文件的可执行文件。我在这里发现了一个有趣的过程:
How to add source files in another folder
下面是我的版本
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})
但是 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
说是看CMakeOutput.log,但是文件实在是太长了,找不到有用的资料。
我检查了 CMake 文档,似乎它可以将第二个来源作为附加参数。 https://cmake.org/cmake/help/v3.0/command/add_executable.html
我想找到这个错误的来源。我觉得我在这里遗漏了一些明显的东西。
【问题讨论】:
-
检查您的来源列表。如果它们为空,则
add_executable将失败。您可以使用message ("Common ${Common_sources}")之类的东西来输出您的来源列表。