CMakeLists.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. cmake_minimum_required(VERSION 2.8.9)
  2. project(VSExcludeFromDefaultBuild)
  3. # CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD will enable the INSTALL target to be part of the default build
  4. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
  5. # First step is to clear all .exe files in output so that possible past
  6. # failures of this test do not prevent it from succeeding.
  7. add_custom_target(ClearExes ALL
  8. COMMAND "${CMAKE_COMMAND}"
  9. -Ddir=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
  10. -P ${CMAKE_CURRENT_SOURCE_DIR}/ClearExes.cmake
  11. VERBATIM)
  12. # Make sure ClearExes is executed before other targets are built
  13. function(add_test_executable target)
  14. add_executable("${target}" ${ARGN})
  15. add_dependencies("${target}" ClearExes)
  16. install(TARGETS "${target}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/install" OPTIONAL)
  17. endfunction()
  18. add_test_executable(DefaultBuilt main.c)
  19. add_test_executable(AlwaysBuilt main.c)
  20. set_target_properties(AlwaysBuilt PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD FALSE)
  21. add_test_executable(NeverBuilt main.c)
  22. set_target_properties(NeverBuilt PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
  23. foreach(config ${CMAKE_CONFIGURATION_TYPES})
  24. string(TOUPPER ${config} Config)
  25. add_test_executable(BuiltIn${config} main.c)
  26. set_target_properties(BuiltIn${config} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE EXCLUDE_FROM_DEFAULT_BUILD_${Config} FALSE)
  27. add_test_executable(ExcludedIn${config} main.c)
  28. set_target_properties(ExcludedIn${config} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_${Config} TRUE)
  29. endforeach()