[英]I want to generate & compile Visual Studio projet with CMake I need to exclude unit testing files from the build. Is there a way to dothis?
My project contain unit testing file I want to excludes from the compilation process.我的项目包含我想从编译过程中排除的单元测试文件。 I want to modify the .vcxproj Visual Studio file with CMake.
我想用 CMake 修改 .vcxproj Visual Studio 文件。 What could be the possible solutions of my issue ?
我的问题有哪些可能的解决方案?
set_source_files_properties(BankTestCase_1.h PROPERTIES VS_DEPLOYEMENT_CONTENT 0)
set_source_files_properties(BankTestCase_1.h PROPERTIES EXCLUDE_FROM_BUILD 1)
First off, you don't modify a .vcxproj
file.首先,您不要修改
.vcxproj
文件。 CMake generates one. CMake 生成一个。 Each time you invoke cmake, a new project file is generated.
每次调用 cmake 时,都会生成一个新的项目文件。 You have to generate it correctly.
您必须正确生成它。
CMake has already a function defined just to add tests. CMake 已经定义了一个函数来添加测试。 It's called
add_test
它叫做
add_test
It work by specifying a name then a command or executable target:它通过指定名称然后指定命令或可执行目标来工作:
add_executable(my_test_exe testsrc1.cpp testsrc2.cpp)
add_test(NAME MyTest COMMAND my_test_exe)
If you also want to not compile the test files in your main project, simply don't add them to your main target:如果您也不想编译主项目中的测试文件,只需不要将它们添加到您的主目标中:
add_executable(main_project
src1.cpp
src2.cpp
src3.cpp
src4.cpp
# srctest1.cpp # not added
# srctest2.cpp # not added too.
)
Also, I notice that you want to remove header files from compilation.另外,我注意到您想从编译中删除头文件。 Header files are not supposed to be compiled at all.
根本不应该编译头文件。 You should not add them to your target.
您不应该将它们添加到您的目标中。
If you used globs to add all source files, then you can always remove it from the glob list:如果您使用 globs 添加所有源文件,那么您始终可以将其从 glob 列表中删除:
list(REMOVE_ITEM globbed_files file/to/be_excluded.cpp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.