CMakeLists.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. cmake_minimum_required(VERSION 2.8.12)
  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 pybind
  43. include_directories(${PROJECT_SOURCE_DIR}/../external/nanogui/ext/pybind11/include)
  44. ## include libigl
  45. option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" OFF)
  46. option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
  47. option(LIBIGL_WITH_NANOGUI "Use Nanogui menu" OFF)
  48. option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
  49. option(LIBIGL_WITH_BOOLEAN "Use Cork boolean" OFF)
  50. option(LIBIGL_WITH_COMISO "Use CoMiso" ON)
  51. option(LIBIGL_WITH_EMBREE "Use Embree" ON)
  52. option(LIBIGL_WITH_LIM "Use LIM" ON)
  53. option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
  54. option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
  55. option(LIBIGL_WITH_BBW "Use BBW" ON)
  56. option(LIBIGL_WITH_PNG "Use PNG" ON)
  57. option(LIBIGL_WITH_TETGEN "Use Tetgen" ON)
  58. option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON)
  59. option(LIBIGL_WITH_XML "Use XML" ON)
  60. option(LIBIGL_WITH_PYTHON "Use Python" ON)
  61. if(LIBIGL_WITH_CGAL) # Do not remove or move this block, cgal strange build system fails without it
  62. find_package(CGAL REQUIRED)
  63. set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "CGAL's CMAKE Setup is super annoying ")
  64. include(${CGAL_USE_FILE})
  65. endif()
  66. add_subdirectory("${PROJECT_SOURCE_DIR}/../shared/cmake" "libigl")
  67. ### Prepare the build environment
  68. include_directories(${LIBIGL_INCLUDE_DIRS})
  69. add_definitions(${LIBIGL_DEFINITIONS})
  70. ## Optional modules
  71. if (LIBIGL_WITH_VIEWER)
  72. add_definitions(-DPY_VIEWER)
  73. list(APPEND SHARED_SOURCES "modules/py_igl_viewer.cpp")
  74. endif ()
  75. if (LIBIGL_WITH_COMISO)
  76. add_definitions(-DPY_COMISO)
  77. list(APPEND SHARED_SOURCES "modules/copyleft/py_igl_comiso.cpp")
  78. endif ()
  79. if (LIBIGL_WITH_TETGEN)
  80. add_definitions(-DPY_TETGEN)
  81. list(APPEND SHARED_SOURCES "modules/copyleft/py_igl_tetgen.cpp")
  82. endif ()
  83. if (LIBIGL_WITH_EMBREE)
  84. add_definitions(-DPY_EMBREE)
  85. list(APPEND SHARED_SOURCES "modules/py_igl_embree.cpp")
  86. endif ()
  87. if (LIBIGL_WITH_TRIANGLE)
  88. add_definitions(-DPY_TRIANGLE)
  89. list(APPEND SHARED_SOURCES "modules/py_igl_triangle.cpp")
  90. endif ()
  91. if (LIBIGL_WITH_CGAL)
  92. add_definitions(-DPY_CGAL)
  93. list(APPEND SHARED_SOURCES "modules/copyleft/py_igl_cgal.cpp")
  94. endif ()
  95. if (LIBIGL_WITH_PNG)
  96. add_definitions(-DPY_PNG)
  97. list(APPEND SHARED_SOURCES "modules/py_igl_png.cpp")
  98. endif ()
  99. #----
  100. ## Prepare the python library
  101. add_library(pyigl SHARED
  102. python_shared.cpp
  103. modules/py_vector.cpp
  104. py_igl.cpp
  105. py_doc.cpp
  106. ${SHARED_SOURCES}
  107. )
  108. set_target_properties(pyigl PROPERTIES PREFIX "")
  109. set_target_properties(pyigl PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
  110. target_link_libraries(pyigl ${LIBIGL_LIBRARIES} ${LIBIGL_EXTRA_LIBRARIES})
  111. # Copy the nanogui bindings
  112. #get_target_property(NANOGUI_LIB nanogui_python LOCATION)
  113. #file(COPY ${NANOGUI_LIB} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../)
  114. if (WIN32)
  115. if (MSVC)
  116. # Enforce size-based optimization and link time code generation on MSVC (~30% smaller binaries in experiments)
  117. set_target_properties(pyigl PROPERTIES COMPILE_FLAGS "/Os /GL")
  118. set_target_properties(pyigl PROPERTIES LINK_FLAGS "/LTCG")
  119. endif()
  120. # .PYD file extension on Windows
  121. set_target_properties(pyigl PROPERTIES SUFFIX ".pyd")
  122. # Link against the Python shared library
  123. # message(FATAL_ERROR ${PYTHON_LIBRARY})
  124. # target_link_libraries(igl ${PYTHON_LIBRARY})
  125. target_link_libraries(pyigl ${PYTHON_LIBRARIES})
  126. elseif (UNIX)
  127. # It's quite common to have multiple copies of the same Python version
  128. # installed on one's system. E.g.: one copy from the OS and another copy
  129. # that's statically linked into an application like Blender or Maya.
  130. # If we link our plugin library against the OS Python here and import it
  131. # into Blender or Maya later on, this will cause segfaults when multiple
  132. # conflicting Python instances are active at the same time.
  133. # Windows does not seem to be affected by this issue. The solution for Linux
  134. # and Mac OS is simple: we just don't link against the Python library. The
  135. # resulting shared library will have missing symbols, but that's perfectly
  136. # fine -- they will be resolved at import time.
  137. # .SO file extension on Linux/Mac OS
  138. set_target_properties(pyigl PROPERTIES SUFFIX ".so")
  139. #Enable flag if undefined symbols appear on pyigl module import to get notified about the missing symbols at link time
  140. option(CHECK_UNDEFINED "Check for undefined symbols" OFF)
  141. # Strip unnecessary sections of the binary on Linux/Mac OS
  142. if(APPLE)
  143. set_target_properties(pyigl PROPERTIES MACOSX_RPATH ".")
  144. if (NOT CHECK_UNDEFINED)
  145. set_target_properties(pyigl PROPERTIES LINK_FLAGS "-undefined dynamic_lookup -dead_strip")
  146. endif()
  147. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  148. add_custom_command(TARGET pyigl POST_BUILD COMMAND strip -u -r ${CMAKE_CURRENT_BINARY_DIR}/../pyigl.so)
  149. endif()
  150. else()
  151. if (CHECK_UNDEFINED)
  152. target_link_libraries(pyigl ${PYTHON_LIBRARIES})
  153. set_target_properties(pyigl PROPERTIES LINK_FLAGS "-Wl,--no-undefined")
  154. endif()
  155. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  156. add_custom_command(TARGET pyigl POST_BUILD COMMAND strip ${CMAKE_CURRENT_BINARY_DIR}/../pyigl.so)
  157. endif()
  158. endif()
  159. endif()
  160. if (LIBIGL_WITH_PYTHON)
  161. # Copy the nanogui python lib after compilation
  162. get_target_property(NANOGUI_LIB nanogui_python LOCATION)
  163. add_custom_target(copy ALL)
  164. add_custom_command(
  165. TARGET copy
  166. COMMAND ${CMAKE_COMMAND} -E copy ${NANOGUI_LIB} ${CMAKE_CURRENT_BINARY_DIR}/../
  167. )
  168. add_dependencies(copy pyigl)
  169. endif()