简体   繁体   English

禁用Visual Studio项目以使用cmake进行构建

[英]Disabling a Visual Studio project for building using cmake

I'm generating a VS2010 solution with a few projects (currently 4, will be up to 10-20 in the end). 我正在生成一个带有一些项目的VS2010解决方案(目前为4个,最终将达到10-20个)。 I only want one of them to build; 我只想要其中一个建造; the rest should be disabled. 其余的应该被禁用。 I can do this manually by going into the configuration manager and unchecking the boxes I don't want, but obviously this isn't a good solution. 我可以通过进入配置管理器并取消选中我不想要的方框来手动执行此操作,但显然这不是一个好的解决方案。

Is there something I can add to the CMakeLists.txt file for a project that will cause it to do this? 有什么东西我可以添加到CMakeLists.txt文件中的项目会导致它执行此操作吗? Searching through the docs, google and SO yielded nothing. 搜索文档,谷歌和SO没有产生任何结果。

只建立bam项目

Update: Here is my root CMakeLists.txt in case that helps: 更新:这是我的根CMakeLists.txt,以防有助于:

cmake_minimum_required(VERSION 2.8)

add_definitions(-DCOMPILER_MSVC)
project (PDEngine)

set(LINKER_LANGUAGE CXX)

add_subdirectory (units/platform)
add_subdirectory (units/render_api)
add_subdirectory (units/memory)
add_subdirectory (units/game)

set(custom_exe "${CMAKE_CURRENT_BINARY_DIR}/units/Platform/Debug/Platform.lib2")

add_custom_command(OUTPUT ${custom_exe}
  COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/local/msvc/bam.bat -j $ENV{NUMBER_OF_PROCESSORS}
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/local/msvc/bam.bat
)
#add_custom_command(OUTPUT ${custom_exe_clean}
  #COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/local/msvc/bam.bat -c
  #DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/local/msvc/bam.bat
#)

add_custom_target(bam ALL DEPENDS ${custom_exe})
#add_custom_target(bamclean ALL DEPENDS ${custom_exe_clean}})

(The bam.bat stuff is based off of the answer I got here: How do I configure CMake to make the VS solution use a specific build commandline? ) (bam.bat的东西是基于我在这里得到的答案: 如何配置CMake以使VS解决方案使用特定的构建命令行?

And here's the CMakeLists.txt for the "platform" project: 这里是“平台”项目的CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)
project (Platform)

set (COMPILER_MSVC 1)

include_directories(${Platform_SOURCE_DIR}/include)
file(GLOB Project_HEADERS ${Platform_SOURCE_DIR}/include/platform/*.h)
source_group("Headers" FILES ${Project_HEADERS})

add_library(Platform STATIC EXCLUDE_FROM_ALL src/*.cpp ${Project_HEADERS})

So if what you want to do is not build something by default, you can remove it from the "ALL" target (which shows up in Visual Studio as ALL_BUILD). 因此,如果您要执行的操作默认情况下不构建某些内容,则可以将其从“ALL”目标(在Visual Studio中显示为ALL_BUILD)中删除。 The way you do this is with the target property EXCLUDE_FROM_ALL , or by passing EXCLUDE_FROM_ALL to add_executable and add_library. 执行此操作的方法是使用目标属性EXCLUDE_FROM_ALL ,或将EXCLUDE_FROM_ALL传递给add_executable和add_library。 (Custom targets default to EXCLUDE_FROM_ALL, so there, to do the reverse, you add ALL to the arguments to add_custom_target). (自定义目标默认为EXCLUDE_FROM_ALL,因此,为了反过来,您将ALL添加到add_custom_target的参数中)。

Then, all your targets will show up, but when clicking "build solution", only the ones you want will build. 然后,所有目标都会显示出来,但是当点击“构建解决方案”时,只会构建您想要的目标。 Others can be built by right clicking them and choosing "Build", like the built-in INSTALL project/target. 其他人可以通过右键单击并选择“Build”来构建,就像内置的INSTALL项目/目标一样。

There is a EXCLUDE_FROM_DEFAULT_BUILD target property for that purpose. 为此目的有一个EXCLUDE_FROM_DEFAULT_BUILD目标属性。

See https://stackoverflow.com/a/14911387/594456 . 请参阅https://stackoverflow.com/a/14911387/594456

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM