CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # CMakeLists.txt -- Build system for the pybind11 examples
  2. #
  3. # Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
  4. #
  5. # All rights reserved. Use of this source code is governed by a
  6. # BSD-style license that can be found in the LICENSE file.
  7. cmake_minimum_required(VERSION 2.8)
  8. project(pybind)
  9. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  10. message(STATUS "Setting build type to 'MinSizeRel' as none was specified.")
  11. set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Choose the type of build." FORCE)
  12. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
  13. "MinSizeRel" "RelWithDebInfo")
  14. endif()
  15. if (true)
  16. SET(PYTHON_LIBRARIES "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4m.dylib")
  17. SET(PYTHON_INCLUDE_DIR "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/include/python3.4m")
  18. #set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6)
  19. find_package(PythonLibs REQUIRED)
  20. find_package(PythonInterp REQUIRED)
  21. else()
  22. SET(PYTHON_LIBRARIES "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4m.dylib")
  23. SET(PYTHON_INCLUDE_DIR "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/include/python3.4m")
  24. set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6)
  25. find_package(PythonLibs 3 REQUIRED)
  26. find_package(PythonInterp 3 REQUIRED)
  27. endif()
  28. string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
  29. if (UNIX)
  30. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  31. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  32. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -flto")
  33. endif()
  34. endif()
  35. # Compile with compiler warnings turned on
  36. if(MSVC)
  37. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  38. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  39. else()
  40. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  41. endif()
  42. else()
  43. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
  44. endif()
  45. include_directories(${PYTHON_INCLUDE_DIR} include)
  46. ## include pybing
  47. include_directories(${PROJECT_SOURCE_DIR}/../external/pybind11/include)
  48. ## include eigen
  49. include_directories(${PROJECT_SOURCE_DIR}/../external/nanogui/ext/eigen)
  50. ## include libigl
  51. include_directories(${PROJECT_SOURCE_DIR}/../include)
  52. add_library(igl SHARED
  53. python.cpp
  54. py_vector.cpp
  55. py_igl.cpp
  56. py_doc.cpp
  57. )
  58. set_target_properties(igl PROPERTIES PREFIX "")
  59. set_target_properties(igl PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
  60. if (WIN32)
  61. if (MSVC)
  62. # Enforce size-based optimization and link time code generation on MSVC (~30% smaller binaries in experiments)
  63. set_target_properties(igl PROPERTIES COMPILE_FLAGS "/Os /GL")
  64. set_target_properties(igl PROPERTIES LINK_FLAGS "/LTCG")
  65. endif()
  66. # .PYD file extension on Windows
  67. set_target_properties(igl PROPERTIES SUFFIX ".pyd")
  68. # Link against the Python shared library
  69. target_link_libraries(igl ${PYTHON_LIBRARY})
  70. elseif (UNIX)
  71. # It's quite common to have multiple copies of the same Python version
  72. # installed on one's system. E.g.: one copy from the OS and another copy
  73. # that's statically linked into an application like Blender or Maya.
  74. # If we link our plugin library against the OS Python here and import it
  75. # into Blender or Maya later on, this will cause segfaults when multiple
  76. # conflicting Python instances are active at the same time.
  77. # Windows does not seem to be affected by this issue. The solution for Linux
  78. # and Mac OS is simple: we just don't link against the Python library. The
  79. # resulting shared library will have missing symbols, but that's perfectly
  80. # fine -- they will be resolved at import time.
  81. # .SO file extension on Linux/Mac OS
  82. set_target_properties(igl PROPERTIES SUFFIX ".so")
  83. # Strip unnecessary sections of the binary on Linux/Mac OS
  84. if(APPLE)
  85. set_target_properties(igl PROPERTIES MACOSX_RPATH ".")
  86. set_target_properties(igl PROPERTIES LINK_FLAGS "-undefined dynamic_lookup -dead_strip")
  87. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  88. add_custom_command(TARGET igl POST_BUILD COMMAND strip -u -r ${CMAKE_CURRENT_BINARY_DIR}/igl.so)
  89. endif()
  90. else()
  91. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  92. add_custom_command(TARGET igl POST_BUILD COMMAND strip ${CMAKE_CURRENT_BINARY_DIR}/igl.so)
  93. endif()
  94. endif()
  95. endif()