如何从基于目标架构的 cmake 创建的 Visual Studio 项目中排除源文件?

发布于 2024-08-30 13:31:25 字数 1321 浏览 1 评论 0原文

我有一个 Windows Driver Kit 解决方案,可以为打印机驱动程序构建 dll。然后,我将二进制文件转换为 C 代码并将其包含到我的源代码中,以便可以在运行时提取 dll,并且我不必分发两个文件,只需分发 .exe。

但是,我必须为 i386 和 amd64 构建 dll,从而生成两个 dll,从而包含两个 c 文件。我可以在编译时检查要包含哪个文件,但我们正在使用 cmake 生成 Visual Studio 项目,并且我想在项目中包含正确的 c 文件,并排除其他文件。这将允许重建工作,将防止重复的符号等。

我们通过为“Visual Studio 9 2008”或“Visual Studio 9 2008 Win64”运行 cmake 来创建 Visual Studio 项目。似乎不可能为这两种体系结构创建 Visual Studio 项目,因此我可以简单地解析“CMAKE_GENERATOR:INTERNAL=Visual Studio 9 2008”并将适当的检查添加到我的 cmakelists.txt 文件中。

这是相关子项目的 cmakelists.txt 文件

if(WIN32)
project (StaticDriverLib)

file(GLOB DriverLib_CPP *.cpp ../MasterInstallDir/*.cpp ../MasterInstallDir/amd64/*.cpp ../MasterInstallDir/i386/*.cpp)
file(GLOB DriverLibLib_H *.hpp *.h ../MasterInstallDir/*.hpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR}/../MasterInstallDir)

# static DriverLibLib library
add_library(StaticDriverLibLib ${DriverLib_CPP} ${DriverLib_H})
add_dependencies(StaticDriverLib StaticLibCore)
target_link_libraries(StaticDriverLib StaticCore Version.lib Setupapi.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib odbc32.lib odbccp32.lib)

endif(WIN32)

如您所见,有一个 i386 和一个 amd64 目录,其中包含特定于体系结构的编码二进制文件。如何调整 cmakelists.txt 以便根据目标生成器排除其中之一?对于 64 位,我们支持 VS2008,很快就会支持 VS2010。

I have a Windows Driver Kit solution that builds the dll for a printer driver. I then convert the binary to C-code and include it into my source so that the dll can be extracted at run time and I don't have to distribute two files, just the .exe.

However, I have to build the dll for i386 and amd64 resulting in two dlls, and thus two c files to include. I can check at compile time for which file to include, but we are generating our Visual Studio projects using cmake, and I'd like to include the correct c file in the project, and exclude the other. This will allow the rebuild to work, will prevent duplicated symbols, etc.

We create the visual studio project by running cmake for either "Visual Studio 9 2008" or "Visual Studio 9 2008 Win64". It doesn't seem possible to create a Visual Studio project for both architectures, so I could simply parse "CMAKE_GENERATOR:INTERNAL=Visual Studio 9 2008" and add to my cmakelists.txt file the appropriate check.

Here is the cmakelists.txt file for the subproject in question

if(WIN32)
project (StaticDriverLib)

file(GLOB DriverLib_CPP *.cpp ../MasterInstallDir/*.cpp ../MasterInstallDir/amd64/*.cpp ../MasterInstallDir/i386/*.cpp)
file(GLOB DriverLibLib_H *.hpp *.h ../MasterInstallDir/*.hpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR}/../MasterInstallDir)

# static DriverLibLib library
add_library(StaticDriverLibLib ${DriverLib_CPP} ${DriverLib_H})
add_dependencies(StaticDriverLib StaticLibCore)
target_link_libraries(StaticDriverLib StaticCore Version.lib Setupapi.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib odbc32.lib odbccp32.lib)

endif(WIN32)

As you can see, there is an i386 and an amd64 directory containing the architecture specific encoded binaries. How do I tweak the cmakelists.txt so that one or the other is excluded based on the target generator? For 64 bit we support VS2008 and soon VS2010.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-09-06 13:31:25

您的假设是正确的,您需要检查是否使用 64 位支持进行编译,并根据该情况更改文件 glob 目录。如果您使用的是 64 位 Windows 编译器,则 CMake 变量 CMAKE_CL_64 将为 true / 设置。

Your presumption is correct you need to check if you are compiling with 64bit support, and change the file glob directory based on that. The CMake variable CMAKE_CL_64 will be true / set if you are using the 64 windows compiler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文