CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. include(${PROJECT_SOURCE_DIR}/cmake/common_build_flags.cmake)
  2. # All projects need to reference the WIL headers
  3. include_directories(${PROJECT_SOURCE_DIR}/include)
  4. # TODO: Might be worth trying to conditionally do this on SDK version, assuming there's a semi-easy way to detect that
  5. include_directories(BEFORE SYSTEM ./workarounds/wrl)
  6. # Because we don't always use msbuild, we need to run nuget manually
  7. find_program(NUGET nuget)
  8. if (NOT NUGET)
  9. message(FATAL_ERROR "Unable to find the nuget CLI tool. Please install it from https://www.nuget.org/downloads and ensure it has been added to the PATH")
  10. endif()
  11. execute_process(COMMAND
  12. ${NUGET} install Microsoft.Windows.CppWinRT -Version ${CPPWINRT_VERSION} -OutputDirectory packages
  13. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  14. RESULT_VARIABLE ret)
  15. if (NOT ret EQUAL 0)
  16. message(FATAL_ERROR "Failed to install nuget package Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}")
  17. endif()
  18. set(CPPWINRT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}/bin/cppwinrt.exe)
  19. execute_process(COMMAND
  20. ${CPPWINRT} -input sdk -output include
  21. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  22. RESULT_VARIABLE ret)
  23. if (NOT ret EQUAL 0)
  24. message(FATAL_ERROR "Failed to run cppwinrt.exe")
  25. endif()
  26. include_directories(BEFORE SYSTEM ${CMAKE_BINARY_DIR}/include)
  27. # The build pipelines have limitations that local development environments do not, so turn a few knobs
  28. if (${FAST_BUILD})
  29. replace_cxx_flag("/GR" "/GR-") # Disables RTTI
  30. add_definitions(-DCATCH_CONFIG_FAST_COMPILE -DWIL_FAST_BUILD)
  31. endif()
  32. # For some unknown reason, 'RelWithDebInfo' compiles with '/Ob1' as opposed to '/Ob2' which prevents inlining of
  33. # functions not marked 'inline'. The reason we prefer 'RelWithDebInfo' over 'Release' is to get debug info, so manually
  34. # revert to the desired (and default) inlining behavior as that exercises more interesting code paths
  35. if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
  36. # TODO: This is currently blocked by an apparent Clang bug: https://github.com/llvm/llvm-project/issues/59690
  37. # replace_cxx_flag("/Ob1" "/Ob2")
  38. endif()
  39. set(COMMON_SOURCES
  40. ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
  41. ${CMAKE_CURRENT_SOURCE_DIR}/CommonTests.cpp
  42. ${CMAKE_CURRENT_SOURCE_DIR}/ComTests.cpp
  43. ${CMAKE_CURRENT_SOURCE_DIR}/FileSystemTests.cpp
  44. ${CMAKE_CURRENT_SOURCE_DIR}/NTResultTests.cpp
  45. ${CMAKE_CURRENT_SOURCE_DIR}/ResourceTests.cpp
  46. ${CMAKE_CURRENT_SOURCE_DIR}/ResultTests.cpp
  47. ${CMAKE_CURRENT_SOURCE_DIR}/Rpc.cpp
  48. ${CMAKE_CURRENT_SOURCE_DIR}/SafeCastTests.cpp
  49. ${CMAKE_CURRENT_SOURCE_DIR}/TraceLoggingTests.cpp
  50. ${CMAKE_CURRENT_SOURCE_DIR}/WistdTests.cpp
  51. ${CMAKE_CURRENT_SOURCE_DIR}/wiTest.cpp
  52. ${CMAKE_CURRENT_SOURCE_DIR}/../natvis/wil.natvis
  53. )
  54. add_subdirectory(app)
  55. add_subdirectory(cpplatest)
  56. add_subdirectory(noexcept)
  57. add_subdirectory(normal)
  58. add_subdirectory(win7)
  59. set(DEBUG_BUILD FALSE)
  60. set(HAS_DEBUG_INFO FALSE)
  61. if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
  62. set(DEBUG_BUILD TRUE)
  63. set(HAS_DEBUG_INFO TRUE)
  64. elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
  65. set(HAS_DEBUG_INFO TRUE)
  66. endif()
  67. set(ASAN_AVAILABLE FALSE)
  68. set(UBSAN_AVAILABLE FALSE)
  69. if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  70. # Address Sanitizer is available for all architectures and build types, but warns/errors if debug info is not enabled
  71. set(ASAN_AVAILABLE ${HAS_DEBUG_INFO})
  72. elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  73. # Address Sanitizer is not available with debug libraries
  74. set(ASAN_AVAILABLE NOT ${DEBUG_BUILD})
  75. set(UBSAN_AVAILABLE NOT ${DEBUG_BUILD})
  76. endif()
  77. if (${ASAN_AVAILABLE})
  78. add_subdirectory(sanitize-address)
  79. endif()
  80. if (${UBSAN_AVAILABLE})
  81. add_subdirectory(sanitize-undefined-behavior)
  82. endif()