CMakeLists.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. cmake_minimum_required(VERSION 3.15)
  2. project(WIL)
  3. include(GNUInstallDirs)
  4. # Set by build server to speed up build/reduce file/object size
  5. option(FAST_BUILD "Sets options to speed up build/reduce obj/executable size" OFF)
  6. option(WIL_BUILD_PACKAGING "Sets option to build the packaging, default on" ON)
  7. option(WIL_BUILD_TESTS "Sets option to build the unit tests, default on" ON)
  8. if (NOT DEFINED WIL_BUILD_VERSION)
  9. set(WIL_BUILD_VERSION "0.0.0")
  10. endif()
  11. if (NOT DEFINED CPPWINRT_VERSION)
  12. set(CPPWINRT_VERSION "2.0.221121.5")
  13. endif()
  14. # Detect the Windows SDK version. If we're using the Visual Studio generator, this will be provided for us. Otherwise
  15. # we'll need to assume that this value comes from the command line (e.g. through the VS command prompt)
  16. if (DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
  17. set(WIL_WINDOWS_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
  18. else()
  19. # This has a trailing backslash for whatever reason...
  20. string(REGEX REPLACE "\\\\$" "" WIL_WINDOWS_SDK_VERSION "$ENV{WindowsSDKVersion}")
  21. endif()
  22. if (${WIL_BUILD_PACKAGING})
  23. add_subdirectory(packaging)
  24. endif()
  25. if (${WIL_BUILD_TESTS})
  26. add_subdirectory(tests)
  27. endif()
  28. # Gather headers into an interface library.
  29. file(GLOB_RECURSE HEADER_FILES "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h")
  30. add_library(${PROJECT_NAME} INTERFACE)
  31. add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
  32. # The interface's include directory.
  33. target_include_directories(${PROJECT_NAME} INTERFACE
  34. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  35. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  36. )
  37. # Include the .natvis files
  38. if (MSVC)
  39. target_sources(${PROJECT_NAME} INTERFACE
  40. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/natvis/wil.natvis>")
  41. endif()
  42. # Install Package Configuration
  43. string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
  44. install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME_LOWER}_targets)
  45. install(EXPORT ${PROJECT_NAME_LOWER}_targets
  46. NAMESPACE ${PROJECT_NAME}::
  47. FILE ${PROJECT_NAME_LOWER}Config.cmake
  48. DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
  49. )
  50. # Install the headers at a standard cmake location.
  51. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/wil" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")