CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. # include nanogui and dependencies
  53. add_subdirectory("../external/nanogui/" "nanogui")
  54. include_directories("../external/nanogui/include")
  55. include_directories("../external/nanogui/ext/nanovg/src")
  56. list(APPEND SHARED_LIBRARIES "nanogui" "glfw")
  57. add_library(igl SHARED
  58. python.cpp
  59. py_vector.cpp
  60. py_igl.cpp
  61. py_doc.cpp
  62. py_igl_viewer.cpp
  63. )
  64. # if(NOT APPLE)
  65. # find_package(GLEW REQUIRED)
  66. # endif(NOT APPLE)
  67. if(APPLE)
  68. set(CMAKE_SHARED_LINKER_FLAGS "-framework OpenGL -framework Cocoa")
  69. endif (APPLE) #APPLE
  70. #
  71. # if(UNIX AND NOT APPLE)
  72. # set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lGL -lGLU -lrt -lX11 -lXxf86vm -lXrandr -lpthread -lXi -lXcursor -lXinerama ")
  73. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
  74. # endif(UNIX AND NOT APPLE)
  75. set_target_properties(igl PROPERTIES PREFIX "")
  76. set_target_properties(igl PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
  77. target_link_libraries(igl ${SHARED_LIBRARIES})
  78. if (WIN32)
  79. if (MSVC)
  80. # Enforce size-based optimization and link time code generation on MSVC (~30% smaller binaries in experiments)
  81. set_target_properties(igl PROPERTIES COMPILE_FLAGS "/Os /GL")
  82. set_target_properties(igl PROPERTIES LINK_FLAGS "/LTCG")
  83. endif()
  84. # .PYD file extension on Windows
  85. set_target_properties(igl PROPERTIES SUFFIX ".pyd")
  86. # Link against the Python shared library
  87. target_link_libraries(igl ${PYTHON_LIBRARY})
  88. elseif (UNIX)
  89. # It's quite common to have multiple copies of the same Python version
  90. # installed on one's system. E.g.: one copy from the OS and another copy
  91. # that's statically linked into an application like Blender or Maya.
  92. # If we link our plugin library against the OS Python here and import it
  93. # into Blender or Maya later on, this will cause segfaults when multiple
  94. # conflicting Python instances are active at the same time.
  95. # Windows does not seem to be affected by this issue. The solution for Linux
  96. # and Mac OS is simple: we just don't link against the Python library. The
  97. # resulting shared library will have missing symbols, but that's perfectly
  98. # fine -- they will be resolved at import time.
  99. # .SO file extension on Linux/Mac OS
  100. set_target_properties(igl PROPERTIES SUFFIX ".so")
  101. # Strip unnecessary sections of the binary on Linux/Mac OS
  102. if(APPLE)
  103. set_target_properties(igl PROPERTIES MACOSX_RPATH ".")
  104. set_target_properties(igl PROPERTIES LINK_FLAGS "-undefined dynamic_lookup -dead_strip")
  105. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  106. add_custom_command(TARGET igl POST_BUILD COMMAND strip -u -r ${CMAKE_CURRENT_BINARY_DIR}/igl.so)
  107. endif()
  108. else()
  109. if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
  110. add_custom_command(TARGET igl POST_BUILD COMMAND strip ${CMAKE_CURRENT_BINARY_DIR}/igl.so)
  111. endif()
  112. endif()
  113. endif()