CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 -DNDEBUG")
  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. # compiler details
  19. message(" C++ Compiler: ${CMAKE_CXX_COMPILER_ID} "
  20. "${CMAKE_CXX_COMPILER_VERSION} "
  21. "${CMAKE_CXX_COMPILER_WRAPPER}")
  22. # installation details
  23. message(" Installation prefix: ${CMAKE_INSTALL_PREFIX}")
  24. # Find Boost
  25. set(BOOSTROOT $ENV{BOOST_DIR})
  26. if (USE_STATIC_LIBRARIES)
  27. set(Boost_USE_STATIC_LIBS ON)
  28. endif ()
  29. set(Boost_USE_MULTITHREADED OFF)
  30. set(Boost_USE_STATIC_RUNTIME OFF)
  31. find_package(Boost)
  32. # Set options
  33. option(ENABLE_MP "Use multiple precision" OFF)
  34. if (Boost_FOUND)
  35. if (${ENABLE_MP})
  36. add_compile_options(-DMULTI_PRECISION=100)
  37. endif ()
  38. if (Boost_INCLUDE_DIRS)
  39. if (${Boost_VERSION} VERSION_LESS 1.60.0)
  40. message(FATAL_ERROR
  41. "Found Boost library is too old; required is version 1.60.0 or newer!")
  42. endif ()
  43. message("Found Boost include dir: ${Boost_INCLUDE_DIR}")
  44. message("Found Boost library dir: ${Boost_LIBRARY_DIR}")
  45. message("Found Boost libraries: ${Boost_LIBRARIES}")
  46. include_directories(${Boost_INCLUDE_DIRS})
  47. endif ()
  48. endif()
  49. #Find Python, NumPy and PyBind11
  50. find_package(Python COMPONENTS Interpreter Development)
  51. include_directories(${Python_INCLUDE_DIRS})
  52. message("Python_EXECUTABLE: ${Python_EXECUTABLE}")
  53. message("Python_FOUND: ${Python_FOUND}")
  54. message("Python_VERSION: ${Python_VERSION}")
  55. message("Python_Development_FOUND: ${Python_Development_FOUND}")
  56. message("Python_LIBRARIES: ${Python_LIBRARIES}")
  57. message("Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
  58. # Ensure that numpy is installed and read its include dir
  59. exec_program(${Python_EXECUTABLE}
  60. ARGS "-c \"import numpy; print(numpy.get_include())\""
  61. OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
  62. RETURN_VALUE NUMPY_NOT_FOUND
  63. )
  64. if (NUMPY_NOT_FOUND)
  65. message(FATAL_ERROR "NumPy headers not found")
  66. endif ()
  67. # Ensure that pybind11 is installed and read its include dir
  68. exec_program(${Python_EXECUTABLE}
  69. ARGS "-c \"import pybind11; print(pybind11.get_include())\""
  70. OUTPUT_VARIABLE PYBIND11_INCLUDE_DIR
  71. RETURN_VALUE PYBIND11_NOT_FOUND
  72. )
  73. if (PYBIND11_NOT_FOUND)
  74. message(FATAL_ERROR "PyBind11 headers not found")
  75. endif ()
  76. # Determine correct extension suffix
  77. exec_program(${Python_EXECUTABLE}
  78. ARGS "-c \"import distutils.sysconfig; print(distutils.sysconfig.get_config_var('EXT_SUFFIX'))\""
  79. OUTPUT_VARIABLE EXT_SUFFIX
  80. RETURN_VALUE SUFFIX_NOT_FOUND
  81. )
  82. if (SUFFIX_NOT_FOUND)
  83. message(FATAL_ERROR "Extension suffix not found")
  84. endif ()
  85. #include_directories(src)
  86. add_subdirectory(src)
  87. add_subdirectory(examples)
  88. #
  89. # Copy all python scripts to the build directory.
  90. #
  91. set(Python_SCRIPTS scattnlay/__init__.py scattnlay/main.py)
  92. foreach (_script ${Python_SCRIPTS})
  93. configure_file(
  94. ${PROJECT_SOURCE_DIR}/${_script}
  95. ${PROJECT_BINARY_DIR}/${_script}
  96. COPYONLY
  97. )
  98. endforeach ()
  99. enable_testing()
  100. add_subdirectory(tests)