CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. cmake_minimum_required(VERSION 3.15)
  2. project(scattnlay VERSION 2.3)
  3. cmake_host_system_information(RESULT HOSTNAME QUERY HOSTNAME)
  4. message("Build type is: ${CMAKE_BUILD_TYPE}")
  5. message("Host OS System: ${CMAKE_HOST_SYSTEM}")
  6. message("Hostname: ${HOSTNAME}")
  7. message("CMake version: ${CMAKE_VERSION}")
  8. # Select flags.
  9. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  10. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
  11. set(CMAKE_CXX_FLAGS_RELEASE "-O3")
  12. set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
  13. set(CMAKE_CXX_STANDARD 17)
  14. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  15. set(CMAKE_CXX_EXTENSIONS OFF)
  16. add_compile_options(-W -Wall -pedantic -Werror)
  17. add_compile_options(-funroll-loops -fstrict-aliasing)
  18. # Set options
  19. option(ENABLE_MP "Use multiple precision" OFF)
  20. if (${ENABLE_MP})
  21. add_compile_options(-DMULTI_PRECISION=100)
  22. endif ()
  23. # compiler details
  24. message(" C++ Compiler: ${CMAKE_CXX_COMPILER_ID} "
  25. "${CMAKE_CXX_COMPILER_VERSION} "
  26. "${CMAKE_CXX_COMPILER_WRAPPER}")
  27. # installation details
  28. message(" Installation prefix: ${CMAKE_INSTALL_PREFIX}")
  29. # Find Boost
  30. set(BOOSTROOT $ENV{BOOST_DIR})
  31. if (USE_STATIC_LIBRARIES)
  32. set(Boost_USE_STATIC_LIBS ON)
  33. endif ()
  34. set(Boost_USE_MULTITHREADED OFF)
  35. set(Boost_USE_STATIC_RUNTIME OFF)
  36. find_package(Boost REQUIRED)
  37. if (Boost_INCLUDE_DIRS)
  38. if (${Boost_VERSION} VERSION_LESS 1.60.0)
  39. message(FATAL_ERROR
  40. "Found Boost library is too old; required is version 1.60.0 or newer!")
  41. endif ()
  42. message("Found Boost include dir: ${Boost_INCLUDE_DIR}")
  43. message("Found Boost library dir: ${Boost_LIBRARY_DIR}")
  44. message("Found Boost libraries: ${Boost_LIBRARIES}")
  45. include_directories(${Boost_INCLUDE_DIRS})
  46. endif ()
  47. #Find Python, NumPy and PyBind11
  48. find_package(Python COMPONENTS Interpreter Development)
  49. include_directories(${Python_INCLUDE_DIRS})
  50. message("Python_EXECUTABLE: ${Python_EXECUTABLE}")
  51. message("Python_FOUND: ${Python_FOUND}")
  52. message("Python_VERSION: ${Python_VERSION}")
  53. message("Python_Development_FOUND: ${Python_Development_FOUND}")
  54. message("Python_LIBRARIES: ${Python_LIBRARIES}")
  55. message("Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
  56. # Ensure that numpy is installed and read its include dir
  57. exec_program(${Python_EXECUTABLE}
  58. ARGS "-c \"import numpy; print(numpy.get_include())\""
  59. OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
  60. RETURN_VALUE NUMPY_NOT_FOUND
  61. )
  62. if (NUMPY_NOT_FOUND)
  63. message(FATAL_ERROR "NumPy headers not found")
  64. endif ()
  65. # Ensure that pybind11 is installed and read its include dir
  66. exec_program(${Python_EXECUTABLE}
  67. ARGS "-c \"import pybind11; print(pybind11.get_include())\""
  68. OUTPUT_VARIABLE PYBIND11_INCLUDE_DIR
  69. RETURN_VALUE PYBIND11_NOT_FOUND
  70. )
  71. if (PYBIND11_NOT_FOUND)
  72. message(FATAL_ERROR "PyBind11 headers not found")
  73. endif ()
  74. # Determine correct extension suffix
  75. exec_program(${Python_EXECUTABLE}
  76. ARGS "-c \"import distutils.sysconfig; print(distutils.sysconfig.get_config_var('EXT_SUFFIX'))\""
  77. OUTPUT_VARIABLE EXT_SUFFIX
  78. RETURN_VALUE SUFFIX_NOT_FOUND
  79. )
  80. if (SUFFIX_NOT_FOUND)
  81. message(FATAL_ERROR "Extension suffix not found")
  82. endif ()
  83. #include_directories(src)
  84. add_subdirectory(src)
  85. add_subdirectory(examples)
  86. #
  87. # Copy all python scripts to the build directory.
  88. #
  89. set(Python_SCRIPTS scattnlay/__init__.py scattnlay/main.py)
  90. foreach (_script ${Python_SCRIPTS})
  91. configure_file(
  92. ${PROJECT_SOURCE_DIR}/${_script}
  93. ${PROJECT_BINARY_DIR}/${_script}
  94. COPYONLY
  95. )
  96. endforeach ()
  97. enable_testing()
  98. add_subdirectory(tests)