Cmake和一个包含源代码的文件夹
cmake and a folder with the source
-project
--sourсes
--CmakeList.txt
CmakeList.txt有一个重复:
add_executable(Project1 ${SOURCE_FILES}
sourсes/File1.cpp sourсes/File1.h
sourсes/File2.cpp sourсes/File2.h
...
)
所有的源代码都在" soursces "文件夹中,这个文件夹不是子项目、模块等。
如何避免重复的"源"在"add_executable"?
我希望能写:
add_executable(Project1 ${SOURCE_FILES}
File1.cpp File1.h
File2.cpp File2.h
...
)
我发现这是一个例子:
add_sources(PREFIX foo
ROOT_DIR "sources"
source_one.cpp
source_two.cpp
ROOT_DIR "other/sources"
source_three.cpp
source_four.cpp
)
add_executable(foo ${foo_SOURCES})
但是"add_sources"是未知的
可以通过自己的cmakelist.txt添加子目录。
-project
--CmakeList.txt
--sourсes
---CmakeList.txt
所以在根目录下cmakelist.txt看起来像。
add_subdirectory(source)
./source/cmakelist.txt文件看起来像
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}")
set(sources
${source_path}/File1.cpp
${source_path}/File1.h
${source_path}/File2.h
${source_path}/File2.h
...
)
add_executable(foo ${sources})
通过这种方式,您可以添加任意多的子目录,而不会污染根目录。
你可以这样做:
set(SOURCES
File1.cpp File1.h
File2.cpp File2.h
...
)
set(SOURCES_ABS "")
foreach(file IN LISTS SOURCES)
list(APPEND SOURCES_ABS sources/${file})
endforeach()
add_executable(Project1 ${SOURCES_ABS})
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 如何在源代码中包含外部库的头文件?
- 尝试使用 MSVC 从源代码构建 qt 创建器:无法打开包含文件:"stddef.h":没有这样的文件或目录
- SQLite - 从源代码构建库或将源代码直接包含在我的项目中
- 包含未定义行为的源代码使编译器崩溃是否合法?
- 如何将另一个项目中用 C 编写的源代码包含在我自己的项目中,C++在 Visual Studio 中
- 生成文件:为每个包含的标头自动编译源代码
- C++ ATIOGLXX.pdb 包含查找模块 ATIOGLXX.dll 源代码所需的调试信息
- QTCreator GUI应用程序中包含窗口基源代码并在代码中打开
- 在Haskell项目中包含C++源代码
- 如何将 .c 和 .h 文件存储在包含路径中,与当前项目的源代码分开
- 反汇编的 exe 文件包含比源代码多得多的代码
- 使用Rcpp构建一个R包,该包包含C源代码和带有限制限定符的标头
- 通过在Xcode中包含合并的源代码来集成jsoncpp
- 编辑C++/程序集调试器的源代码以包含其他程序集信息
- 如何将c++源代码生成的地图包含到应用程序中进行预编译阶段
- 在标头中定义并包含在两个源代码中的结构仅在一个源代码内定义
- Cmake和一个包含源代码的文件夹
- 在Netbeans项目中包含c++库源代码
- 有没有办法将源代码格式化为每行只包含一条语句