CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Detects whether this is a top-level project
  2. get_directory_property(LIBIGL_PARENT_DIR PARENT_DIRECTORY)
  3. if(NOT LIBIGL_PARENT_DIR)
  4. set(LIBIGL_TOPLEVEL_PROJECT ON)
  5. else()
  6. set(LIBIGL_TOPLEVEL_PROJECT OFF)
  7. endif()
  8. # Check required CMake version
  9. set(REQUIRED_CMAKE_VERSION "3.16.0")
  10. if(LIBIGL_TOPLEVEL_PROJECT)
  11. cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
  12. else()
  13. # Don't use cmake_minimum_required here to avoid implicitly overriding parent policies
  14. if(${CMAKE_VERSION} VERSION_LESS ${REQUIRED_CMAKE_VERSION})
  15. message(FATAL_ERROR "CMake required version to build Libigl is ${REQUIRED_CMAKE_VERSION}")
  16. endif()
  17. endif()
  18. # Include user-provided default options if available. We do that before the main
  19. # `project()` so that we can define the C/C++ compilers from the option file.
  20. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/LibiglOptions.cmake)
  21. message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/LibiglOptions.cmake")
  22. include(${CMAKE_CURRENT_SOURCE_DIR}/LibiglOptions.cmake)
  23. endif()
  24. # If this option is enabled, this will setup the Hunter package manager.
  25. option(HUNTER_ENABLED "Enable Hunter package manager support" OFF)
  26. if(HUNTER_ENABLED)
  27. include("cmake/misc/HunterGate.cmake")
  28. HunterGate(
  29. URL "https://github.com/cpp-pm/hunter/archive/v0.24.8.tar.gz"
  30. SHA1 "ca7838dded9a1811b04ffd56175f629e0af82d3d"
  31. )
  32. endif()
  33. ################################################################################
  34. project(libigl VERSION 2.4.0)
  35. # CMake module path
  36. list(PREPEND CMAKE_MODULE_PATH
  37. ${CMAKE_CURRENT_LIST_DIR}/cmake/
  38. ${CMAKE_CURRENT_LIST_DIR}/cmake/igl
  39. ${CMAKE_CURRENT_LIST_DIR}/cmake/find
  40. ${CMAKE_CURRENT_LIST_DIR}/cmake/recipes/external
  41. )
  42. if(HUNTER_ENABLED)
  43. list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/recipes/hunter)
  44. else()
  45. list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/recipes/external)
  46. endif()
  47. set_property(GLOBAL PROPERTY __igl_module_path ${CMAKE_MODULE_PATH})
  48. set(LIBIGL_DEFAULT_CGAL ${LIBIGL_TOPLEVEL_PROJECT})
  49. set(MATLAB_ADDITIONAL_VERSIONS
  50. "R2022b=10.3"
  51. "R2022a=10.2"
  52. "R2021b=10.1"
  53. "R2021a=10.0"
  54. )
  55. set(LIBIGL_DEFAULT_MATLAB ${LIBIGL_TOPLEVEL_PROJECT})
  56. set(LIBIGL_DEFAULT_MOSEK ${LIBIGL_TOPLEVEL_PROJECT})
  57. if(LIBIGL_TOPLEVEL_PROJECT)
  58. find_package(Matlab QUIET)
  59. if(NOT Matlab_FOUND)
  60. set(LIBIGL_DEFAULT_MATLAB OFF)
  61. message(WARNING "Matlab not found, disabling igl_restricted::matlab module.")
  62. endif()
  63. find_package(MOSEK QUIET)
  64. if(NOT MOSEK_FOUND)
  65. set(LIBIGL_DEFAULT_MOSEK OFF)
  66. message(WARNING "Mosek not found, disabling igl_restricted::mosek module.")
  67. endif()
  68. endif()
  69. # Build tests and tutorials
  70. option(LIBIGL_BUILD_TESTS "Build libigl unit test" ${LIBIGL_TOPLEVEL_PROJECT})
  71. option(LIBIGL_BUILD_TUTORIALS "Build libigl tutorial" ${LIBIGL_TOPLEVEL_PROJECT})
  72. option(LIBIGL_INSTALL "Enable installation of libigl targets" ${LIBIGL_TOPLEVEL_PROJECT})
  73. # USE_STATIC_LIBRARY speeds up the generation of multiple binaries,
  74. # at the cost of a longer initial compilation time
  75. # (by default, static build is off since libigl is a header-only library)
  76. option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" ${LIBIGL_TOPLEVEL_PROJECT})
  77. # Permissive modules. These modules are available under MPL2 license, and their dependencies are available
  78. # under a permissive or public domain license.
  79. option(LIBIGL_EMBREE "Build target igl::embree" ${LIBIGL_TOPLEVEL_PROJECT})
  80. option(LIBIGL_GLFW "Build target igl::glfw" ${LIBIGL_TOPLEVEL_PROJECT})
  81. option(LIBIGL_IMGUI "Build target igl::imgui" ${LIBIGL_TOPLEVEL_PROJECT})
  82. option(LIBIGL_OPENGL "Build target igl::opengl" ${LIBIGL_TOPLEVEL_PROJECT})
  83. option(LIBIGL_PNG "Build target igl::png" ${LIBIGL_TOPLEVEL_PROJECT})
  84. option(LIBIGL_PREDICATES "Build target igl::predicates" ${LIBIGL_TOPLEVEL_PROJECT})
  85. option(LIBIGL_SPECTRA "Build target igl::spectra" ${LIBIGL_TOPLEVEL_PROJECT})
  86. option(LIBIGL_XML "Build target igl::xml" ${LIBIGL_TOPLEVEL_PROJECT})
  87. # Copyleft modules. These modules are available under GPL license, and their dependencies are
  88. # available under a copyleft license.
  89. option(LIBIGL_COPYLEFT_CORE "Build target igl_copyleft::core" ${LIBIGL_TOPLEVEL_PROJECT})
  90. option(LIBIGL_COPYLEFT_CGAL "Build target igl_copyleft::cgal" ${LIBIGL_DEFAULT_CGAL})
  91. option(LIBIGL_COPYLEFT_COMISO "Build target igl_copyleft::comiso" ${LIBIGL_TOPLEVEL_PROJECT})
  92. option(LIBIGL_COPYLEFT_TETGEN "Build target igl_copyleft::tetgen" ${LIBIGL_TOPLEVEL_PROJECT})
  93. # Restricted modules. These modules are available under MPL2 license, but their dependencies are
  94. # only available under a non-commercial or proprietary license.
  95. option(LIBIGL_RESTRICTED_MATLAB "Build target igl_restricted::matlab" ${LIBIGL_DEFAULT_MATLAB})
  96. option(LIBIGL_RESTRICTED_MOSEK "Build target igl_restricted::mosek" ${LIBIGL_DEFAULT_MOSEK})
  97. option(LIBIGL_RESTRICTED_TRIANGLE "Build target igl_restricted::triangle" ${LIBIGL_TOPLEVEL_PROJECT})
  98. # Option to immediately delete tutorials as their built (an attempt to make the
  99. # Windows build on github actions run out of memory less often/quickly).
  100. option(LIBIGL_DELETE_TUTORIALS_IMMEDIATELY "Delete tutorials as they are built" OFF)
  101. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  102. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  103. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  104. # Include CMake helper functions
  105. include(igl_add_library)
  106. include(igl_add_test)
  107. include(igl_add_tutorial)
  108. include(igl_copy_dll)
  109. include(igl_include)
  110. include(igl_install)
  111. include(igl_target_sources)
  112. # Enable unit testing at the root level
  113. if(LIBIGL_BUILD_TESTS)
  114. include(CTest)
  115. endif()
  116. # Defines CMake targets for selected libigl modules
  117. include(libigl)
  118. if(LIBIGL_BUILD_TUTORIALS)
  119. add_subdirectory(tutorial)
  120. endif()
  121. ################################################################################
  122. # Install CMake config files
  123. ################################################################################
  124. if(LIBIGL_INSTALL)
  125. include(GNUInstallDirs)
  126. set(project_config_in "${PROJECT_SOURCE_DIR}/cmake/igl/libigl-config.cmake.in")
  127. set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/libigl-config.cmake")
  128. set(config_targets_base "LibiglConfigTargets")
  129. set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/LibiglConfigVersion.cmake")
  130. set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/igl")
  131. foreach(suffix IN ITEMS "") #"_restricted" "_copyleft")
  132. install(EXPORT LibiglTargets${suffix}
  133. DESTINATION ${export_dest_dir}
  134. NAMESPACE igl${suffix}::
  135. FILE ${config_targets_base}${suffix}.cmake
  136. COMPONENT LibiglDevelopment
  137. )
  138. endforeach()
  139. include(CMakePackageConfigHelpers)
  140. configure_package_config_file(
  141. "${project_config_in}"
  142. "${project_config_out}"
  143. INSTALL_DESTINATION
  144. ${CMAKE_INSTALL_DATAROOTDIR}/libigl/cmake
  145. )
  146. write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
  147. install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${export_dest_dir}")
  148. endif()