CMakeLists.txt 2.7 KB

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