我有一个使用boost::program_options
的小项目。我想将此库(仅此库)作为git submodule
添加到我的项目中,并使用其源代码构建可执行文件。
我已经完成了git submodule
部分(git submodule add https://github.com/boostorg/program_options.git
),并且做了一个小型实验,在该实验中,我仅使用提到的子模块中的源代码构建了示例应用程序(仔细检查是否没有额外的依赖项) 。
现在,我想将这些源添加到我的项目中。我在CMakeLists.txt
文件中所做的是:
set(BOOST_PROGRAM_OPTIONS_SOURCES
boost/program_options/src/split.cpp
boost/program_options/src/positional_options.cpp
boost/program_options/src/parsers.cpp
boost/program_options/src/options_description.cpp
boost/program_options/src/convert.cpp
boost/program_options/src/config_file.cpp
boost/program_options/src/cmdline.cpp
boost/program_options/src/winmain.cpp
boost/program_options/src/variables_map.cpp
boost/program_options/src/value_semantic.cpp
boost/program_options/src/utf8_codecvt_facet.cpp
)
和
add_executable(
...
src/main.cpp
${BOOST_PROGRAM_OPTIONS_SOURCES}
)
但出现以下错误:
CMake Error at CMakeLists.txt:69 (add_executable):
The target name "boost/program_options/src/split.cpp" is reserved or not
valid for certain CMake features, such as generator expressions, and may
result in undefined behavior.
CMake Error at CMakeLists.txt:86 (target_link_libraries):
Cannot specify link libraries for target "..." which is not built
by this project.
做什么是我想要的正确方法>
我发现了问题。
我已将boost::program_options
(git clone https://github.com/boostorg/program_options.git
)克隆到与CMakeLists.txt
相同的文件夹中>
此后,遵循正常的FindBoost
流程
set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED OFF) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost 1.45.0 COMPONENTS program_options) if(Boost_FOUND) message(WARNING "BOOST FOUND") include_directories(${Boost_INCLUDE_DIRS}) set(BOOST_LIBS ${Boost_LIBRARIES}) else() set(BOOST_LIBS ) message(WARNING "BOOST NOT FOUND") endif() ... ... target_link_libraries(... ${BOOST_LIBS}) ... ...
[
CMake
仍然可以找到增强,即使program_options
不包含任何CMakeLists.txt
(至少我找不到)