CMake报错:add_subdirectory not given a binary directory but the given source directory

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CMake报错:add_subdirectory not given a binary directory but the given source directory相关的知识,希望对你有一定的参考价值。

参考技术A add_subdirectory 命令,可以将指定的文件夹加到build任务列表中。
如果你的目录结构如下:

main 是主工程的CMake目录,需要添加子目录模块 sub1 ,那么语法如下:
默认情况下是添加当前目录的子目录,用法如下:

如果还需要依赖外部目录(即不是主目录的子目录),就需要指定绝对路径,如下:

不指定绝对路径就会报如下错误:

Steinberg VST3 项目生成器 CMake 中的错误 - “add_subdirectory 调用的参数数量不正确”

【中文标题】Steinberg VST3 项目生成器 CMake 中的错误 - “add_subdirectory 调用的参数数量不正确”【英文标题】:Error in Steinberg VST3 Project Generator CMake - "add_subdirectory called with incorrect number of arguements" 【发布时间】:2020-12-21 04:06:29 【问题描述】:

我正在尝试使用 Steinberg VST3 项目生成器创建一个基本的新乐器插件,但出现以下错误:

CMakeLists.txt:12 (add_subdirectory) 处的 CMake 错误: add_subdirectory 调用的参数数量不正确

CMakeLists.txt:13 (smtg_enable_vst3_sdk) 处的 CMake 错误: 未知的 CMake 命令“smtg_enable_vst3_sdk”。

我该如何解决这个问题? 我附上了生成器设置的图像,并在下面粘贴了完整的脚本输出。

A link to a screenshot with the settings of the VST3 Project Generator

C:\Program Files\CMake\bin\cmake.exe C:\Users\waffl\Downloads\vst-sdk_3.7.1_build-50_2020-11-17\VST_SDK\VST3_Project_Generator\Windows\Resources\GenerateVST3Plugin.cmake -DSMTG_VST3_SDK_SOURCE_DIR_CLI="F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/VST3_SDK" -DSMTG_GENERATOR_OUTPUT_DIRECTORY_CLI="F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano" -DSMTG_PLUGIN_NAME_CLI="Grand Piano" -DSMTG_PLUGIN_CATEGORY_CLI="Instrument" -DSMTG_CMAKE_PROJECT_NAME_CLI="Grand_Piano" -DSMTG_PLUGIN_BUNDLE_NAME_CLI="Grand Piano" -DSMTG_PLUGIN_IDENTIFIER_CLI="com.jonathanvardouniotis.grandpiano" -DSMTG_VENDOR_NAME_CLI="Jonathan Vardouniotis" -DSMTG_VENDOR_HOMEPAGE_CLI="https://www.thejonathanv.com" -DSMTG_VENDOR_EMAIL_CLI="support@thejonathanv.com" -DSMTG_PREFIX_FOR_FILENAMES_CLI="GrandPiano" -DSMTG_VENDOR_NAMESPACE_CLI="GrandPiano" -DSMTG_PLUGIN_CLASS_NAME_CLI="Grand_Piano" -DSMTG_ENABLE_VSTGUI_SUPPORT_CLI=ON -P "C:\Users\waffl\Downloads\vst-sdk_3.7.1_build-50_2020-11-17\VST_SDK\VST3_Project_Generator\Windows\Resources\GenerateVST3Plugin.cmake"
==================================================

 Steinberg Media Technologies GmbH
 VST3 Project Generator

==================================================

-- Found Git: C:/Program Files/Git/cmd/git.exe (found version "2.28.0.windows.1") 
-- SMTG_CMAKE_SCRIPT_DIR           : C:/Users/waffl/Downloads/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/VST3_Project_Generator/Windows/Resources
-- SMTG_ENABLE_VSTGUI_SUPPORT      : ON
-- SMTG_GENERATOR_OUTPUT_DIRECTORY : F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano
-- SMTG_TEMPLATE_FILES_PATH        : C:/Users/waffl/Downloads/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/VST3_Project_Generator/Windows/Resources/cmake/templates
-- SMTG_VST3_SDK_SOURCE_DIR        : F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/VST3_SDK

-- SMTG_VENDOR_NAME            : Jonathan Vardouniotis
-- SMTG_VENDOR_HOMEPAGE        : https://www.thejonathanv.com
-- SMTG_VENDOR_EMAIL           : support@thejonathanv.com
-- SMTG_SOURCE_COPYRIGHT_HEADER: Copyright(c) 2020 Jonathan Vardouniotis.
-- SMTG_PLUGIN_NAME            : Grand Piano
-- SMTG_PREFIX_FOR_FILENAMES   : e.g. GrandPianocontroller.h
-- SMTG_PLUGIN_IDENTIFIER      : com.jonathanvardouniotis.grandpiano, used e.g. in Info.plist
-- SMTG_PLUGIN_BUNDLE_NAME     : Grand Piano

-- SMTG_CMAKE_PROJECT_NAME     : e.g. Grand_Piano will output Grand_Piano.vst3
-- SMTG_VENDOR_NAMESPACE       : e.g. namespace GrandPiano ...
-- SMTG_PLUGIN_CLASS_NAME      : e.g. class Grand_PianoProcessor : public AudioEffect ...
-- SMTG_PLUGIN_CATEGORY        : Instrument

-- SMTG_Processor_UUID         : 0xA9CE2568, 0xD0F95BCF, 0xA31C76FB, 0xBC6229DF
-- SMTG_Controller_UUID        : 0xF388EFE7, 0xCAD15CC8, 0x9FC50FB6, 0x86CA74B1

-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/CMakeLists.txt
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/resource/Info.plist
-- Copied    : F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/resource/A9CE2568D0F95BCFA31C76FBBC6229DF_snapshot.png
-- Copied    : F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/resource/A9CE2568D0F95BCFA31C76FBBC6229DF_snapshot_2.0x.png
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/resource/GrandPianoeditor.uidesc
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/resource/win32resource.rc
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/version.h
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/GrandPianocids.h
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/GrandPianocontroller.cpp
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/GrandPianocontroller.h
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/GrandPianoentry.cpp
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/GrandPianoprocessor.cpp
-- Configured: F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/source/GrandPianoprocessor.h

C:\Program Files\CMake\bin\cmake.exe -G "Visual Studio 16 2019" -S "F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano\Grand Piano" -B "F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano\Grand Piano\build" -DSMTG_ADD_VSTGUI=ON 
-- The C compiler identification is MSVC 19.28.29304.1
-- The CXX compiler identification is MSVC 19.28.29304.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.28.29304/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.28.29304/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:12 (add_subdirectory):
  add_subdirectory called with incorrect number of arguments


CMake Error at CMakeLists.txt:13 (smtg_enable_vst3_sdk):
  Unknown CMake command "smtg_enable_vst3_sdk".


-- Configuring incomplete, errors occurred!
See also "F:/EXTRA STORAGE/vst-sdk_3.7.1_build-50_2020-11-17/VST_SDK/my_plugins/grandpiano/Grand Piano/build/CMakeFiles/CMakeOutput.log".

【问题讨论】:

【参考方案1】:

我在尝试为 cmake Visual Studio 2019 生成的 Windows 10 上遇到了同样的错误,对我来说问题是我的 VST3 SDK 和输出目录的文件路径中的目录名称中有一个空格(它们是在同一目录中)。我删除了目录名称中的空格并且它起作用了。您的目录名称“EXTRA STORAGE”中有一个空格。删除该空间,如“EXTRA_STORAGE”或将文件移动到另一个没有空间的目录。这对我有用。

【讨论】:

以上是关于CMake报错:add_subdirectory not given a binary directory but the given source directory的主要内容,如果未能解决你的问题,请参考以下文章

CMake中add_subdirectory的使用

CMake add_subdirectory()函数

CMake如何避免递归add_subdirectory?

[cmake][转载]add_subdirectory详解

CMake 错误:“add_subdirectory 未给出二进制目录”

CMake:Include vs add_subdirectory:相对头文件路径