使用柯南和cmake选择文件
File selection with conan and cmake
我有一个包含 2 个变体的软件包,具有以下目录结构
pkg
pkg_main.h
CMakeLists.txt
var1
pkg_main.cpp
var2
pkg_main.cpp
conanfile.py
对于柯南,我正在尝试定义一个选项fileSelection
,其中包含可能的值var1
和var2
。 使用 cmake,我尝试按如下方式进行选择:如果fileSelection
设置为var1
,则应调用var1/pkg_main.cpp
,否则var2/pkg_main.cpp
。
到目前为止,我已经在conanfile.py
中定义了选项fileSelection
class PkgConan(ConanFile):
name = "pkg"
...
options = {"fileSelection : ['var1', 'var2']"}
default_options = "fileSelection=var1"
generators = "cmake"
def build(self):
cmake = CMake(self)
cmake.configure(source_folder="pkg")
cmake.build()
def package(self):
self.copy("*.h", dst="include", src="pkg")
self.copy("*pkg.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.libs = ["pkg"]
现在我正在努力更新CMakeLists.txt
文件以根据fileSelection
的值进行选择。像这样的东西:
[这是逻辑,不是可运行的代码]
if("${fileSelection}" STREQUAL "var1")
add_library(pkg var1/pkg_main.cpp)
else
add_library(pkg var2/pkg_main.cpp)
endif
??如何将fileSelection
选项传递给 cmake;我在哪里以及如何实现var1
和var2
之间的切换(我是否通过尝试在 CMakeLists.txt 中定义开关而朝着正确的方向前进(?
您可以将变量传递给由 cmake 帮助程序驱动的 cmake 命令行调用。像这样:
options = {"fileSelection": ["var1", "var2"]}
...
def build(self):
cmake = CMake(self)
cmake.definitions["fileSelection"] = self.options.fileSelection
cmake.configure(source_folder="pkg")
cmake.build()
这假设您具有您描述的 CMakeLists.txt 逻辑。
相关文章:
- 选择文件对话框错误
- 如果在VC6中使用打开功能,如何选择文件夹?
- 在 Win32 应用中,如果未选择文件夹并且用户单击"确定",则文件夹选择对话框将关闭
- 使用柯南和cmake选择文件
- 如何选择文件保存到的位置?
- 使用dialog_fselect选择文件
- 如何判断 QFileDialog 是否已关闭而不选择文件
- C++选择文件夹,包括文件
- 生成文件 :从变量中按扩展名选择文件
- 在MFC VS2010中选择“文件”或“文件夹”
- 无法从OSX dylib显示OSX Finder选择文件对话框(QFileDialog::getOpenFileName
- 只选择文件夹,但也看到文件
- 如何在c++中编写一个选择文件夹对话框
- 使用CFileDialog选择文件时出现画图问题
- 预编译头-选择文件
- QFileDialog在关闭/析构时冻结(选择文件或取消)
- QSignalMapper在选择文件后不更新参数
- QT:在选择文件的目录上启动默认的资源管理器
- 如何根据要写入的数据类型动态选择文件句柄
- 正确选择文件流对象