CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #
  52. #include_directories(${Python_INCLUDE_DIRS})
  53. #
  54. #message("Python_EXECUTABLE: ${Python_EXECUTABLE}")
  55. #message("Python_FOUND: ${Python_FOUND}")
  56. #message("Python_VERSION: ${Python_VERSION}")
  57. #message("Python_Development_FOUND: ${Python_Development_FOUND}")
  58. #message("Python_LIBRARIES: ${Python_LIBRARIES}")
  59. #message("Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
  60. #
  61. ## Ensure that numpy is installed and read its include dir
  62. #exec_program(${Python_EXECUTABLE}
  63. # ARGS "-c \"import numpy; print(numpy.get_include())\""
  64. # OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
  65. # RETURN_VALUE NUMPY_NOT_FOUND
  66. # )
  67. #if (NUMPY_NOT_FOUND)
  68. # message(FATAL_ERROR "NumPy headers not found")
  69. #endif ()
  70. #
  71. ## Ensure that pybind11 is installed and read its include dir
  72. #exec_program(${Python_EXECUTABLE}
  73. # ARGS "-c \"import pybind11; print(pybind11.get_include())\""
  74. # OUTPUT_VARIABLE PYBIND11_INCLUDE_DIR
  75. # RETURN_VALUE PYBIND11_NOT_FOUND
  76. # )
  77. #if (PYBIND11_NOT_FOUND)
  78. # message(FATAL_ERROR "PyBind11 headers not found")
  79. #endif ()
  80. #
  81. ## Determine correct extension suffix
  82. #exec_program(${Python_EXECUTABLE}
  83. # ARGS "-c \"import distutils.sysconfig; print(distutils.sysconfig.get_config_var('EXT_SUFFIX'))\""
  84. # OUTPUT_VARIABLE EXT_SUFFIX
  85. # RETURN_VALUE SUFFIX_NOT_FOUND
  86. # )
  87. #if (SUFFIX_NOT_FOUND)
  88. # message(FATAL_ERROR "Extension suffix not found")
  89. #endif ()
  90. #include_directories(src)
  91. add_subdirectory(src)
  92. add_subdirectory(examples)
  93. #
  94. # Copy all python scripts to the build directory.
  95. #
  96. set(Python_SCRIPTS scattnlay/__init__.py scattnlay/main.py)
  97. foreach (_script ${Python_SCRIPTS})
  98. configure_file(
  99. ${PROJECT_SOURCE_DIR}/${_script}
  100. ${PROJECT_BINARY_DIR}/${_script}
  101. COPYONLY
  102. )
  103. endforeach ()
  104. enable_testing()
  105. add_subdirectory(tests)
  106. # add_test(NAME BuildExtWithPythonSetupPy
  107. # COMMAND ${Python_EXECUTABLE} setup.py build_ext
  108. # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  109. add_test(NAME tox
  110. COMMAND tox)