CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # This file has been adapted from dynarmic
  2. cmake_minimum_required(VERSION 3.8)
  3. project(sirit CXX)
  4. # Determine if we're built as a subproject (using add_subdirectory)
  5. # or if this is the master project.
  6. set(MASTER_PROJECT OFF)
  7. if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  8. set(MASTER_PROJECT ON)
  9. endif()
  10. # Sirit project options
  11. option(SIRIT_TESTS "Build tests" OFF)
  12. option(SIRIT_USE_SYSTEM_SPIRV_HEADERS "Use system SPIR-V headers" OFF)
  13. # Default to a Release build
  14. if (NOT CMAKE_BUILD_TYPE)
  15. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
  16. message(STATUS "Defaulting to a Release build")
  17. endif()
  18. # Set hard requirements for C++
  19. set(CMAKE_CXX_STANDARD 20)
  20. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  21. set(CMAKE_CXX_EXTENSIONS OFF)
  22. # Warn on CMake API deprecations
  23. set(CMAKE_WARN_DEPRECATED ON)
  24. # Disable in-source builds
  25. set(CMAKE_DISABLE_SOURCE_CHANGES ON)
  26. set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
  27. if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
  28. message(SEND_ERROR "In-source builds are not allowed.")
  29. endif()
  30. # Add the module directory to the list of paths
  31. list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules")
  32. # Compiler flags
  33. if (MSVC)
  34. set(SIRIT_CXX_FLAGS
  35. /std:c++latest # CMAKE_CXX_STANDARD as no effect on MSVC until CMake 3.10.
  36. /W4
  37. /w34263 # Non-virtual member function hides base class virtual function
  38. /w44265 # Class has virtual functions, but destructor is not virtual
  39. /w34456 # Declaration of 'var' hides previous local declaration
  40. /w34457 # Declaration of 'var' hides function parameter
  41. /w34458 # Declaration of 'var' hides class member
  42. /w34459 # Declaration of 'var' hides global definition
  43. /w34946 # Reinterpret-cast between related types
  44. /wd4592 # Symbol will be dynamically initialized (implementation limitation)
  45. /permissive- # Stricter C++ standards conformance
  46. /MP
  47. /Zi
  48. /Zo
  49. /EHsc
  50. /Zc:throwingNew # Assumes new never returns null
  51. /Zc:inline # Omits inline functions from object-file output
  52. /DNOMINMAX
  53. /WX)
  54. if (CMAKE_VS_PLATFORM_TOOLSET MATCHES "LLVM-vs[0-9]+")
  55. list(APPEND SIRIT_CXX_FLAGS
  56. -Qunused-arguments
  57. -Wno-missing-braces)
  58. endif()
  59. else()
  60. set(SIRIT_CXX_FLAGS
  61. -Wall
  62. -Wextra
  63. -Wcast-qual
  64. -pedantic
  65. -pedantic-errors
  66. -Wfatal-errors
  67. -Wno-missing-braces
  68. -Wconversion
  69. -Wsign-conversion
  70. -Wshadow
  71. -Werror)
  72. endif()
  73. # Enable unit-testing.
  74. enable_testing(true)
  75. # SPIR-V headers
  76. if (SIRIT_USE_SYSTEM_SPIRV_HEADERS)
  77. find_package(SPIRV-Headers REQUIRED)
  78. else()
  79. add_subdirectory(${CMAKE_SOURCE_DIR}/externals/SPIRV-Headers externals/SPIRV-Headers EXCLUDE_FROM_ALL)
  80. add_library(SPIRV-Headers::SPIRV-Headers ALIAS SPIRV-Headers)
  81. endif()
  82. # Sirit project files
  83. add_subdirectory(src)
  84. if (SIRIT_TESTS)
  85. add_subdirectory(tests)
  86. endif()