CMakeLists.txt 3.8 KB

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