CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. cmake_minimum_required(VERSION 2.8)
  2. project(pybind)
  3. ### Compilation flags: adapt to your needs ###
  4. if(MSVC)
  5. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj /w") ### Enable parallel compilation
  6. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} )
  7. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} )
  8. else()
  9. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") #### Libigl requires a modern C++ compiler that supports c++11
  10. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../" )
  11. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-unused-parameter -Wno-deprecated-register -Wno-return-type-c-linkage")
  12. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations -Wno-unused-parameter -Wno-deprecated-register -Wno-return-type-c-linkage")
  13. endif()
  14. # Force a specific python version
  15. # SET(PYTHON_LIBRARIES "D:/Python34/libs/python34.lib")
  16. # SET(PYTHON_INCLUDE_DIR "D:/Python34/include")
  17. # Force a specific python version
  18. # SET(PYTHON_LIBRARIES "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5m.dylib")
  19. # SET(PYTHON_INCLUDE_DIR "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/include/python3.5m")
  20. set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6)
  21. find_package(PythonLibs REQUIRED)
  22. find_package(PythonInterp REQUIRED)
  23. string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
  24. if (UNIX)
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
  26. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  27. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  28. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -flto")
  29. endif()
  30. endif()
  31. # Compile with compiler warnings turned on
  32. # if(MSVC)
  33. # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  34. # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  35. # else()
  36. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  37. # endif()
  38. # else()
  39. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  40. # endif()
  41. include_directories(${PYTHON_INCLUDE_DIR} include)
  42. ## include pybing
  43. include_directories(${PROJECT_SOURCE_DIR}/../external/pybind11/include)
  44. ## include libigl
  45. option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" OFF)
  46. option(LIBIGL_WITH_GLFW "Use GLFW" ON)
  47. option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
  48. option(LIBIGL_WITH_NANOGUI "Use Nanogui menu" OFF)
  49. option(LIBIGL_WITH_BBW "Use BBW" ON)
  50. option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
  51. option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
  52. option(LIBIGL_WITH_PNG "Use PNG" ON)
  53. option(LIBIGL_WITH_TETGEN "Use Tetgen" ON)
  54. option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON)
  55. option(LIBIGL_WITH_XML "Use XML" ON)
  56. option(LIBIGL_WITH_LIM "Use LIM" ON)
  57. option(LIBIGL_WITH_COMISO "Use CoMiso" ON)
  58. option(LIBIGL_WITH_BOOLEAN "Use Cork boolean" OFF)
  59. option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
  60. option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
  61. option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
  62. if(LIBIGL_WITH_CGAL) # Do not remove or move this block, cgal strange build system fails without it
  63. find_package(CGAL REQUIRED)
  64. set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "CGAL's CMAKE Setup is super annoying ")
  65. include(${CGAL_USE_FILE})
  66. endif()
  67. add_subdirectory("${PROJECT_SOURCE_DIR}/../shared/cmake" "libigl")
  68. ### Prepare the build environment
  69. include_directories(${LIBIGL_INCLUDE_DIRS})
  70. add_definitions(${LIBIGL_DEFINITIONS})
  71. ## Optional modules
  72. if (LIBIGL_WITH_OPENGL)
  73. add_definitions(-DPY_VIEWER)
  74. list(APPEND SHARED_SOURCES "py_igl_viewer.cpp")
  75. endif ()
  76. if (LIBIGL_WITH_COMISO)
  77. add_definitions(-DPY_COMISO)
  78. list(APPEND SHARED_SOURCES "copyleft/py_igl_comiso.cpp")
  79. endif ()
  80. ## Prepare the python library
  81. add_library(pyigl SHARED
  82. python_shared.cpp
  83. py_vector.cpp
  84. py_igl.cpp
  85. py_doc.cpp
  86. ${SHARED_SOURCES}
  87. )
  88. set_target_properties(pyigl PROPERTIES PREFIX "")
  89. set_target_properties(pyigl PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
  90. target_link_libraries(pyigl ${LIBIGL_LIBRARIES} ${LIBIGL_EXTRA_LIBRARIES})
  91. if (WIN32)
  92. if (MSVC)
  93. # Enforce size-based optimization and link time code generation on MSVC (~30% smaller binaries in experiments)
  94. set_target_properties(pyigl PROPERTIES COMPILE_FLAGS "/Os /GL")
  95. set_target_properties(pyigl PROPERTIES LINK_FLAGS "/LTCG")
  96. endif()
  97. # .PYD file extension on Windows
  98. set_target_properties(pyigl PROPERTIES SUFFIX ".pyd")
  99. # Link against the Python shared library
  100. # message(FATAL_ERROR ${PYTHON_LIBRARY})
  101. # target_link_libraries(igl ${PYTHON_LIBRARY})
  102. target_link_libraries(pyigl ${PYTHON_LIBRARIES})
  103. elseif (UNIX)
  104. # It's quite common to have multiple copies of the same Python version
  105. # installed on one's system. E.g.: one copy from the OS and another copy
  106. # that's statically linked into an application like Blender or Maya.
  107. # If we link our plugin library against the OS Python here and import it
  108. # into Blender or Maya later on, this will cause segfaults when multiple
  109. # conflicting Python instances are active at the same time.
  110. # Windows does not seem to be affected by this issue. The solution for Linux
  111. # and Mac OS is simple: we just don't link against the Python library. The
  112. # resulting shared library will have missing symbols, but that's perfectly
  113. # fine -- they will be resolved at import time.
  114. # .SO file extension on Linux/Mac OS
  115. set_target_properties(pyigl PROPERTIES SUFFIX ".so")
  116. # Strip unnecessary sections of the binary on Linux/Mac OS
  117. if(APPLE)
  118. set_target_properties(pyigl PROPERTIES MACOSX_RPATH ".")
  119. set_target_properties(pyigl PROPERTIES LINK_FLAGS "-undefined dynamic_lookup -dead_strip")
  120. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  121. add_custom_command(TARGET pyigl POST_BUILD COMMAND strip -u -r ${CMAKE_CURRENT_BINARY_DIR}/../pyigl.so)
  122. endif()
  123. else()
  124. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  125. add_custom_command(TARGET pyigl POST_BUILD COMMAND strip ${CMAKE_CURRENT_BINARY_DIR}/../pyigl.so)
  126. endif()
  127. endif()
  128. endif()