CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. cmake_minimum_required (VERSION 3.5.1)
  2. project (OpenFHE-Python)
  3. set(OPENFHE_PYTHON_VERSION_MAJOR 1)
  4. set(OPENFHE_PYTHON_VERSION_MINOR 3)
  5. set(OPENFHE_PYTHON_VERSION_PATCH 0)
  6. set(OPENFHE_PYTHON_VERSION_TWEAK 0)
  7. set(OPENFHE_PYTHON_VERSION ${OPENFHE_PYTHON_VERSION_MAJOR}.${OPENFHE_PYTHON_VERSION_MINOR}.${OPENFHE_PYTHON_VERSION_PATCH}.${OPENFHE_PYTHON_VERSION_TWEAK})
  8. set(CMAKE_CXX_STANDARD 17)
  9. option( BUILD_STATIC "Set to ON to include static versions of the library" OFF)
  10. if(APPLE)
  11. set(CMAKE_CXX_VISIBILITY_PRESET default)
  12. endif()
  13. find_package(OpenFHE 1.3.0 REQUIRED)
  14. find_package(pybind11 REQUIRED)
  15. # "CMAKE_INTERPROCEDURAL_OPTIMIZATION ON" (ON is the default value) causes link failure. see
  16. # https://github.com/openfheorg/openfhe-python/actions/runs/11492843373/job/31987579944
  17. set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
  18. set( OpenFHE_Py_SOURCES src/lib)
  19. set( OpenFHE_Py_INCLUDES src/include)
  20. include_directories( ${OPENMP_INCLUDES} )
  21. include_directories( ${OpenFHE_INCLUDE} )
  22. include_directories( ${OpenFHE_INCLUDE}/third-party/include )
  23. include_directories( ${OpenFHE_INCLUDE}/core )
  24. include_directories( ${OpenFHE_INCLUDE}/pke )
  25. include_directories( ${OpenFHE_INCLUDE}/binfhe )
  26. # include_directories( ${OpenFHE_Py_SOURCES} )
  27. include_directories( ${OpenFHE_Py_INCLUDES}/pke )
  28. include_directories( ${OpenFHE_Py_INCLUDES}/binfhe )
  29. include_directories( ${OpenFHE_Py_INCLUDES}/docstrings )
  30. include_directories( ${OpenFHE_Py_INCLUDES} )
  31. ### add directories for other OpenFHE modules as needed for your project
  32. link_directories( ${OpenFHE_LIBDIR} )
  33. link_directories( ${OPENMP_LIBRARIES} )
  34. if(BUILD_STATIC)
  35. set( CMAKE_EXE_LINKER_FLAGS "${OpenFHE_EXE_LINKER_FLAGS} -static")
  36. link_libraries( ${OpenFHE_STATIC_LIBRARIES} )
  37. else()
  38. set( CMAKE_EXE_LINKER_FLAGS ${OpenFHE_EXE_LINKER_FLAGS} )
  39. link_libraries( ${OpenFHE_SHARED_LIBRARIES} )
  40. endif()
  41. ### ADD YOUR EXECUTABLE(s) HERE
  42. ### add_executable( EXECUTABLE-NAME SOURCES )
  43. ###
  44. ### EXAMPLE:
  45. ### add_executable( test demo-simple-example.cpp )
  46. ### Pybind Modules
  47. pybind11_add_module(openfhe
  48. src/lib/bindings.cpp
  49. src/lib/binfhe_bindings.cpp
  50. src/lib/binfhe/binfhecontext_wrapper.cpp
  51. src/lib/pke/serialization.cpp
  52. src/lib/pke/cryptocontext_wrapper.cpp
  53. )
  54. ### Python installation
  55. # Allow the user to specify the path to Python executable (if not provided, find it)
  56. option(PYTHON_EXECUTABLE_PATH "Path to Python executable" "")
  57. if(NOT PYTHON_EXECUTABLE_PATH)
  58. # Find Python and its development components
  59. find_package(Python REQUIRED COMPONENTS Interpreter Development)
  60. else()
  61. # Set Python_EXECUTABLE to the specified path
  62. set(Python_EXECUTABLE "${PYTHON_EXECUTABLE_PATH}")
  63. endif()
  64. # Find Python interpreter
  65. find_package(PythonInterp REQUIRED)
  66. # Check Python version
  67. if(${PYTHON_VERSION_MAJOR} EQUAL 3 AND ${PYTHON_VERSION_MINOR} GREATER_EQUAL 10)
  68. execute_process(
  69. COMMAND "${Python_EXECUTABLE}" -c "from sys import exec_prefix; print(exec_prefix)"
  70. OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
  71. OUTPUT_STRIP_TRAILING_WHITESPACE
  72. )
  73. else()
  74. execute_process(
  75. COMMAND "${Python_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
  76. OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
  77. OUTPUT_STRIP_TRAILING_WHITESPACE
  78. )
  79. endif()
  80. message(STATUS "Python site packages directory: ${PYTHON_SITE_PACKAGES}")
  81. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  82. set(Python_Install_Location "${PYTHON_SITE_PACKAGES}")
  83. else()
  84. set(Python_Install_Location "${CMAKE_INSTALL_PREFIX}")
  85. endif()
  86. message("***** INSTALL IS AT ${Python_Install_Location}; to change, run cmake with -DCMAKE_INSTALL_PREFIX=/your/path")
  87. install(TARGETS openfhe LIBRARY DESTINATION ${Python_Install_Location})