libigl.cmake 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. cmake_minimum_required(VERSION 3.1)
  2. # https://github.com/libigl/libigl/issues/751
  3. # http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160425/351643.html
  4. if(APPLE)
  5. if(NOT CMAKE_LIBTOOL)
  6. find_program(CMAKE_LIBTOOL NAMES libtool)
  7. endif()
  8. if(CMAKE_LIBTOOL)
  9. set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
  10. message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
  11. get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
  12. foreach(lang ${languages})
  13. # Added -c
  14. set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
  15. "${CMAKE_LIBTOOL} -c -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
  16. endforeach()
  17. endif()
  18. endif()
  19. ### Available options ###
  20. option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
  21. option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
  22. option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
  23. option(LIBIGL_WITH_CORK "Use Cork" OFF)
  24. option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
  25. option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
  26. option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
  27. option(LIBIGL_WITH_OPENGL "Use OpenGL" OFF)
  28. option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" OFF)
  29. option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" OFF)
  30. option(LIBIGL_WITH_PNG "Use PNG" OFF)
  31. option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
  32. option(LIBIGL_WITH_TRIANGLE "Use Triangle" OFF)
  33. option(LIBIGL_WITH_PREDICATES "Use exact predicates" OFF)
  34. option(LIBIGL_WITH_XML "Use XML" OFF)
  35. option(LIBIGL_WITHOUT_COPYLEFT "Disable Copyleft libraries" OFF)
  36. option(LIBIGL_EXPORT_TARGETS "Export libigl CMake targets" OFF)
  37. if(LIBIGL_BUILD_PYTHON)
  38. message(FATAL_ERROR "Python bindings have been removed in this version. Please use an older version of libigl, or wait for the new bindings to be released.")
  39. endif()
  40. ################################################################################
  41. ### Configuration
  42. set(LIBIGL_ROOT "${CMAKE_CURRENT_LIST_DIR}/..")
  43. set(LIBIGL_SOURCE_DIR "${LIBIGL_ROOT}/include")
  44. set(LIBIGL_EXTERNAL "${LIBIGL_ROOT}/external")
  45. # Dependencies are linked as INTERFACE targets unless libigl is compiled as a static library
  46. if(LIBIGL_USE_STATIC_LIBRARY)
  47. set(IGL_SCOPE PUBLIC)
  48. else()
  49. set(IGL_SCOPE INTERFACE)
  50. endif()
  51. # Download and update 3rdparty libraries
  52. list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
  53. include(LibiglDownloadExternal)
  54. ################################################################################
  55. ### IGL Common
  56. ################################################################################
  57. add_library(igl_common INTERFACE)
  58. target_include_directories(igl_common SYSTEM INTERFACE
  59. $<BUILD_INTERFACE:${LIBIGL_SOURCE_DIR}>
  60. $<INSTALL_INTERFACE:include>
  61. )
  62. # Export igl_common as igl::common
  63. set_property(TARGET igl_common PROPERTY EXPORT_NAME igl::common)
  64. if(LIBIGL_USE_STATIC_LIBRARY)
  65. target_compile_definitions(igl_common INTERFACE -DIGL_STATIC_LIBRARY)
  66. endif()
  67. # Transitive C++11 flags
  68. include(CXXFeatures)
  69. target_compile_features(igl_common INTERFACE ${CXX11_FEATURES})
  70. # Other compilation flags
  71. if(MSVC)
  72. # Enable parallel compilation for Visual Studio
  73. target_compile_options(igl_common INTERFACE /MP /bigobj)
  74. target_compile_definitions(igl_common INTERFACE -DNOMINMAX)
  75. endif()
  76. ### Set compiler flags for building the tests on Windows with Visual Studio
  77. include(LibiglWindows)
  78. if(BUILD_SHARED_LIBS)
  79. # Generate position independent code
  80. set_target_properties(igl_common PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ON)
  81. endif()
  82. if(UNIX AND NOT HUNTER_ENABLED)
  83. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  84. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  85. endif()
  86. if(HUNTER_ENABLED)
  87. hunter_add_package(Eigen)
  88. find_package(Eigen3 CONFIG REQUIRED)
  89. endif()
  90. # Eigen
  91. if(NOT TARGET Eigen3::Eigen)
  92. igl_download_eigen()
  93. add_library(igl_eigen INTERFACE)
  94. target_include_directories(igl_eigen SYSTEM INTERFACE
  95. $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
  96. $<INSTALL_INTERFACE:include>
  97. )
  98. set_property(TARGET igl_eigen PROPERTY EXPORT_NAME Eigen3::Eigen)
  99. add_library(Eigen3::Eigen ALIAS igl_eigen)
  100. endif()
  101. target_link_libraries(igl_common INTERFACE Eigen3::Eigen)
  102. # C++11 Thread library
  103. find_package(Threads REQUIRED)
  104. target_link_libraries(igl_common INTERFACE ${CMAKE_THREAD_LIBS_INIT})
  105. ################################################################################
  106. ## CGAL dependencies on Windows: GMP & MPFR
  107. function(igl_download_cgal_deps)
  108. if(WIN32)
  109. igl_download_project(gmp
  110. URL https://cgal.geometryfactory.com/CGAL/precompiled_libs/auxiliary/x64/GMP/5.0.1/gmp-all-CGAL-3.9.zip
  111. URL_MD5 508c1292319c832609329116a8234c9f
  112. )
  113. igl_download_project(mpfr
  114. URL https://cgal.geometryfactory.com/CGAL/precompiled_libs/auxiliary/x64/MPFR/3.0.0/mpfr-all-CGAL-3.9.zip
  115. URL_MD5 48840454eef0ff18730050c05028734b
  116. )
  117. set(ENV{GMP_DIR} "${LIBIGL_EXTERNAL}/gmp")
  118. set(ENV{MPFR_DIR} "${LIBIGL_EXTERNAL}/mpfr")
  119. endif()
  120. endfunction()
  121. ################################################################################
  122. function(compile_igl_module module_dir)
  123. string(REPLACE "/" "_" module_name "${module_dir}")
  124. if(module_name STREQUAL "core")
  125. set(module_libname "igl")
  126. else()
  127. set(module_libname "igl_${module_name}")
  128. endif()
  129. if(LIBIGL_USE_STATIC_LIBRARY)
  130. file(GLOB SOURCES_IGL_${module_name}
  131. "${LIBIGL_SOURCE_DIR}/igl/${module_dir}/*.cpp")
  132. if(NOT LIBIGL_WITHOUT_COPYLEFT)
  133. file(GLOB COPYLEFT_SOURCES_IGL_${module_name}
  134. "${LIBIGL_SOURCE_DIR}/igl/copyleft/${module_dir}/*.cpp")
  135. list(APPEND SOURCES_IGL_${module_name} ${COPYLEFT_SOURCES_IGL_${module_name}})
  136. endif()
  137. add_library(${module_libname} STATIC ${SOURCES_IGL_${module_name}} ${ARGN})
  138. if(MSVC)
  139. # Silencing some compile warnings
  140. target_compile_options(${module_libname} PRIVATE
  141. # Type conversion warnings. These can be fixed with some effort and possibly more verbose code.
  142. /wd4267 # conversion from 'size_t' to 'type', possible loss of data
  143. /wd4244 # conversion from 'type1' to 'type2', possible loss of data
  144. /wd4018 # signed/unsigned mismatch
  145. /wd4305 # truncation from 'double' to 'float'
  146. # This one is from template instantiations generated by autoexplicit.sh:
  147. /wd4667 # no function template defined that matches forced instantiation ()
  148. # This one is easy to fix, just need to switch to safe version of C functions
  149. /wd4996 # this function or variable may be unsafe
  150. # This one is when using bools in adjacency matrices
  151. /wd4804 #'+=': unsafe use of type 'bool' in operation
  152. )
  153. else()
  154. #target_compile_options(${module_libname} PRIVATE -w) # disable all warnings (not ideal but...)
  155. endif()
  156. else()
  157. add_library(${module_libname} INTERFACE)
  158. endif()
  159. target_link_libraries(${module_libname} ${IGL_SCOPE} igl_common)
  160. if(NOT module_name STREQUAL "core")
  161. target_link_libraries(${module_libname} ${IGL_SCOPE} igl)
  162. endif()
  163. # Alias target because it looks nicer
  164. message(STATUS "Creating target: igl::${module_name} (${module_libname})")
  165. add_library(igl::${module_name} ALIAS ${module_libname})
  166. # Export as igl::${module_name}
  167. set_property(TARGET ${module_libname} PROPERTY EXPORT_NAME igl::${module_name})
  168. endfunction()
  169. ################################################################################
  170. ### IGL Core
  171. ################################################################################
  172. if(LIBIGL_USE_STATIC_LIBRARY)
  173. file(GLOB SOURCES_IGL
  174. "${LIBIGL_SOURCE_DIR}/igl/*.cpp"
  175. "${LIBIGL_SOURCE_DIR}/igl/copyleft/*.cpp")
  176. endif()
  177. compile_igl_module("core" ${SOURCES_IGL})
  178. ################################################################################
  179. ### Download the python part ###
  180. if(LIBIGL_WITH_PYTHON)
  181. endif()
  182. ################################################################################
  183. ### Compile the CGAL part ###
  184. if(LIBIGL_WITH_CGAL)
  185. # Try to find the CGAL library
  186. # CGAL Core is needed for
  187. # `Exact_predicates_exact_constructions_kernel_with_sqrt`
  188. if(NOT TARGET CGAL::CGAL)
  189. set(CGAL_DIR "${LIBIGL_EXTERNAL}/cgal")
  190. igl_download_cgal()
  191. igl_download_cgal_deps()
  192. if(EXISTS ${LIBIGL_EXTERNAL}/boost)
  193. set(BOOST_ROOT "${LIBIGL_EXTERNAL}/boost")
  194. endif()
  195. option(CGAL_Boost_USE_STATIC_LIBS "Use static Boost libs with CGAL" ON)
  196. find_package(CGAL CONFIG COMPONENTS Core PATHS ${CGAL_DIR} NO_DEFAULT_PATH)
  197. endif()
  198. # If CGAL has been found, then build the libigl module
  199. if(TARGET CGAL::CGAL AND TARGET CGAL::CGAL_Core)
  200. compile_igl_module("cgal")
  201. target_link_libraries(igl_cgal ${IGL_SCOPE} CGAL::CGAL CGAL::CGAL_Core)
  202. else()
  203. set(LIBIGL_WITH_CGAL OFF CACHE BOOL "" FORCE)
  204. endif()
  205. endif()
  206. # Helper function for `igl_copy_cgal_dll()`
  207. function(igl_copy_imported_dll src_target dst_target)
  208. get_target_property(other_libs ${src_target} INTERFACE_LINK_LIBRARIES)
  209. set(locations)
  210. list(APPEND locations ${main_lib} ${other_libs})
  211. foreach(location ${locations})
  212. string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${location})
  213. set(location "${CMAKE_MATCH_1}.dll")
  214. if(EXISTS "${location}" AND location MATCHES "^.*\\.dll$")
  215. add_custom_command(TARGET ${dst_target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${location}" $<TARGET_FILE_DIR:${dst_target}>)
  216. endif()
  217. endforeach()
  218. endfunction()
  219. # Convenient functions to copy CGAL dlls into a target (executable) destination folder (for Windows)
  220. function(igl_copy_cgal_dll target)
  221. if(WIN32 AND LIBIGL_WITH_CGAL)
  222. igl_copy_imported_dll(CGAL::CGAL ${target})
  223. igl_copy_imported_dll(CGAL::CGAL_Core ${target})
  224. endif()
  225. endfunction()
  226. ################################################################################
  227. ### Compile the CoMISo part ###
  228. # NOTE: this cmakefile works only with the
  229. # comiso available here: https://github.com/libigl/CoMISo
  230. if(LIBIGL_WITH_COMISO)
  231. compile_igl_module("comiso")
  232. if(NOT TARGET CoMISo)
  233. igl_download_comiso()
  234. add_subdirectory("${LIBIGL_EXTERNAL}/CoMISo" CoMISo)
  235. endif()
  236. target_link_libraries(igl_comiso ${IGL_SCOPE} CoMISo)
  237. endif()
  238. ################################################################################
  239. ### Compile the cork part ###
  240. if(LIBIGL_WITH_CORK)
  241. set(CORK_DIR "${LIBIGL_EXTERNAL}/cork")
  242. if(NOT TARGET cork)
  243. # call this "lib-cork" instead of "cork", otherwise cmake gets confused about
  244. # "cork" executable
  245. igl_download_cork()
  246. add_subdirectory("${CORK_DIR}" "lib-cork")
  247. endif()
  248. compile_igl_module("cork")
  249. target_include_directories(igl_cork ${IGL_SCOPE} cork)
  250. target_include_directories(igl_cork ${IGL_SCOPE} "${CORK_DIR}/src")
  251. target_link_libraries(igl_cork ${IGL_SCOPE} cork)
  252. endif()
  253. ################################################################################
  254. ### Compile the embree part ###
  255. if(LIBIGL_WITH_EMBREE)
  256. set(EMBREE_DIR "${LIBIGL_EXTERNAL}/embree")
  257. set(EMBREE_TESTING_INTENSITY 0 CACHE STRING "" FORCE)
  258. set(EMBREE_ISPC_SUPPORT OFF CACHE BOOL " " FORCE)
  259. set(EMBREE_TASKING_SYSTEM "INTERNAL" CACHE BOOL " " FORCE)
  260. set(EMBREE_TUTORIALS OFF CACHE BOOL " " FORCE)
  261. set(EMBREE_MAX_ISA "SSE2" CACHE STRING " " FORCE)
  262. set(EMBREE_STATIC_LIB ON CACHE BOOL " " FORCE)
  263. if(MSVC)
  264. set(EMBREE_STATIC_RUNTIME ON CACHE BOOL " " FORCE)
  265. endif()
  266. if(NOT TARGET embree)
  267. # TODO: Should probably save/restore the CMAKE_CXX_FLAGS_*, since embree seems to be
  268. # overriding them on Windows. But well... it works for now.
  269. igl_download_embree()
  270. add_subdirectory("${EMBREE_DIR}" "embree" EXCLUDE_FROM_ALL)
  271. endif()
  272. compile_igl_module("embree")
  273. target_link_libraries(igl_embree ${IGL_SCOPE} embree)
  274. target_include_directories(igl_embree ${IGL_SCOPE} ${EMBREE_DIR}/include)
  275. target_compile_definitions(igl_embree ${IGL_SCOPE} -DEMBREE_STATIC_LIB)
  276. endif()
  277. ################################################################################
  278. ### Compile the matlab part ###
  279. if(LIBIGL_WITH_MATLAB)
  280. find_package(Matlab REQUIRED COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY MAT_LIBRARY)
  281. compile_igl_module("matlab")
  282. target_link_libraries(igl_matlab ${IGL_SCOPE} ${Matlab_LIBRARIES})
  283. target_include_directories(igl_matlab ${IGL_SCOPE} ${Matlab_INCLUDE_DIRS})
  284. endif()
  285. ################################################################################
  286. ### Compile the mosek part ###
  287. if(LIBIGL_WITH_MOSEK)
  288. find_package(MOSEK REQUIRED)
  289. compile_igl_module("mosek")
  290. target_link_libraries(igl_mosek ${IGL_SCOPE} ${MOSEK_LIBRARIES})
  291. target_include_directories(igl_mosek ${IGL_SCOPE} ${MOSEK_INCLUDE_DIRS})
  292. target_compile_definitions(igl_mosek ${IGL_SCOPE} -DLIBIGL_WITH_MOSEK)
  293. endif()
  294. ################################################################################
  295. ### Compile the opengl part ###
  296. if(LIBIGL_WITH_OPENGL)
  297. # OpenGL module
  298. compile_igl_module("opengl")
  299. # OpenGL library
  300. if (NOT CMAKE_VERSION VERSION_LESS "3.11")
  301. cmake_policy(SET CMP0072 NEW)
  302. endif()
  303. find_package(OpenGL REQUIRED)
  304. if(TARGET OpenGL::GL)
  305. target_link_libraries(igl_opengl ${IGL_SCOPE} OpenGL::GL)
  306. else()
  307. target_link_libraries(igl_opengl ${IGL_SCOPE} ${OPENGL_gl_LIBRARY})
  308. target_include_directories(igl_opengl SYSTEM ${IGL_SCOPE} ${OPENGL_INCLUDE_DIR})
  309. endif()
  310. # glad module
  311. if(NOT TARGET glad)
  312. igl_download_glad()
  313. add_subdirectory(${LIBIGL_EXTERNAL}/glad glad)
  314. endif()
  315. target_link_libraries(igl_opengl ${IGL_SCOPE} glad)
  316. endif()
  317. ################################################################################
  318. ### Compile the GLFW part ###
  319. if(LIBIGL_WITH_OPENGL_GLFW)
  320. if(TARGET igl::opengl)
  321. # GLFW module
  322. compile_igl_module("opengl/glfw")
  323. if(NOT TARGET glfw)
  324. set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)
  325. set(GLFW_BUILD_TESTS OFF CACHE BOOL " " FORCE)
  326. set(GLFW_BUILD_DOCS OFF CACHE BOOL " " FORCE)
  327. set(GLFW_INSTALL OFF CACHE BOOL " " FORCE)
  328. igl_download_glfw()
  329. add_subdirectory(${LIBIGL_EXTERNAL}/glfw glfw)
  330. endif()
  331. target_link_libraries(igl_opengl_glfw ${IGL_SCOPE} igl_opengl glfw)
  332. endif()
  333. endif()
  334. ################################################################################
  335. ### Compile the ImGui part ###
  336. if(LIBIGL_WITH_OPENGL_GLFW_IMGUI)
  337. if(TARGET igl::opengl_glfw)
  338. # ImGui module
  339. compile_igl_module("opengl/glfw/imgui")
  340. if(NOT TARGET imgui)
  341. igl_download_imgui()
  342. add_subdirectory(${LIBIGL_EXTERNAL}/libigl-imgui imgui)
  343. endif()
  344. target_link_libraries(igl_opengl_glfw_imgui ${IGL_SCOPE} igl_opengl_glfw imgui)
  345. endif()
  346. endif()
  347. ################################################################################
  348. ### Compile the png part ###
  349. if(LIBIGL_WITH_PNG)
  350. # png/ module is anomalous because it also depends on opengl it really should
  351. # be moved into the opengl/ directory and namespace ...
  352. if(TARGET igl_opengl)
  353. if(NOT TARGET stb_image)
  354. igl_download_stb()
  355. add_subdirectory(${LIBIGL_EXTERNAL}/stb stb_image)
  356. endif()
  357. compile_igl_module("png" "")
  358. target_link_libraries(igl_png ${IGL_SCOPE} igl_stb_image igl_opengl)
  359. endif()
  360. endif()
  361. ################################################################################
  362. ### Compile the tetgen part ###
  363. if(LIBIGL_WITH_TETGEN)
  364. set(TETGEN_DIR "${LIBIGL_EXTERNAL}/tetgen")
  365. if(NOT TARGET tetgen)
  366. igl_download_tetgen()
  367. add_subdirectory("${TETGEN_DIR}" "tetgen")
  368. endif()
  369. compile_igl_module("tetgen")
  370. target_link_libraries(igl_tetgen ${IGL_SCOPE} tetgen)
  371. target_include_directories(igl_tetgen ${IGL_SCOPE} ${TETGEN_DIR})
  372. endif()
  373. ################################################################################
  374. ### Compile the triangle part ###
  375. if(LIBIGL_WITH_TRIANGLE)
  376. set(TRIANGLE_DIR "${LIBIGL_EXTERNAL}/triangle")
  377. if(NOT TARGET triangle)
  378. igl_download_triangle()
  379. add_subdirectory("${TRIANGLE_DIR}" "triangle")
  380. endif()
  381. compile_igl_module("triangle")
  382. target_link_libraries(igl_triangle ${IGL_SCOPE} triangle)
  383. target_include_directories(igl_triangle ${IGL_SCOPE} ${TRIANGLE_DIR})
  384. endif()
  385. ################################################################################
  386. ### Compile the predicates part ###
  387. if(LIBIGL_WITH_PREDICATES)
  388. set(PREDICATES_DIR "${LIBIGL_EXTERNAL}/predicates")
  389. if(NOT TARGET predicates)
  390. igl_download_predicates()
  391. add_subdirectory("${PREDICATES_DIR}" "predicates")
  392. endif()
  393. compile_igl_module("predicates")
  394. target_link_libraries(igl_predicates ${IGL_SCOPE} predicates)
  395. target_include_directories(igl_predicates ${IGL_SCOPE} ${PREDICATES_DIR})
  396. target_compile_definitions(igl_predicates ${IGL_SCOPE} -DLIBIGL_WITH_PREDICATES)
  397. endif()
  398. ################################################################################
  399. ### Compile the xml part ###
  400. if(LIBIGL_WITH_XML)
  401. set(TINYXML2_DIR "${LIBIGL_EXTERNAL}/tinyxml2")
  402. if(NOT TARGET tinyxml2)
  403. igl_download_tinyxml2()
  404. add_library(tinyxml2 STATIC ${TINYXML2_DIR}/tinyxml2.cpp ${TINYXML2_DIR}/tinyxml2.h)
  405. target_include_directories(tinyxml2 PUBLIC ${TINYXML2_DIR})
  406. set_target_properties(tinyxml2 PROPERTIES
  407. COMPILE_DEFINITIONS "TINYXML2_EXPORT"
  408. VERSION "3.0.0"
  409. SOVERSION "3")
  410. endif()
  411. compile_igl_module("xml")
  412. target_link_libraries(igl_xml ${IGL_SCOPE} tinyxml2)
  413. target_include_directories(igl_xml ${IGL_SCOPE} ${TINYXML2_DIR})
  414. endif()
  415. ################################################################################
  416. ### Install and export all modules
  417. if(NOT LIBIGL_EXPORT_TARGETS)
  418. return()
  419. endif()
  420. function(install_dir_files dir_name)
  421. if (dir_name STREQUAL "core")
  422. set(subpath "")
  423. else()
  424. set(subpath "/${dir_name}")
  425. endif()
  426. file(GLOB public_headers
  427. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.h
  428. )
  429. set(files_to_install ${public_headers})
  430. if(NOT LIBIGL_USE_STATIC_LIBRARY)
  431. file(GLOB public_sources
  432. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.cpp
  433. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.c
  434. )
  435. endif()
  436. list(APPEND files_to_install ${public_sources})
  437. install(
  438. FILES ${files_to_install}
  439. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/igl${subpath}
  440. )
  441. endfunction()
  442. ################################################################################
  443. include(GNUInstallDirs)
  444. include(CMakePackageConfigHelpers)
  445. if(TARGET igl_eigen)
  446. set(IGL_EIGEN igl_eigen)
  447. else()
  448. set(IGL_EIGEN)
  449. message(WARNING "Trying to export igl targets while using an imported target for Eigen.")
  450. endif()
  451. # Install and export core library
  452. install(
  453. TARGETS
  454. igl
  455. igl_common
  456. ${IGL_EIGEN}
  457. EXPORT igl-export
  458. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  459. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  460. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  461. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  462. )
  463. export(
  464. TARGETS
  465. igl
  466. igl_common
  467. ${IGL_EIGEN}
  468. FILE libigl-export.cmake
  469. )
  470. # Install headers for core library
  471. install_dir_files(core)
  472. install_dir_files(copyleft)
  473. # Write package configuration file
  474. configure_package_config_file(
  475. ${CMAKE_CURRENT_LIST_DIR}/libigl-config.cmake.in
  476. ${CMAKE_BINARY_DIR}/libigl-config.cmake
  477. INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/libigl/cmake
  478. )
  479. install(
  480. FILES
  481. ${CMAKE_BINARY_DIR}/libigl-config.cmake
  482. DESTINATION
  483. ${CMAKE_INSTALL_DATADIR}/libigl/cmake
  484. )
  485. # Write export file
  486. export(EXPORT igl-export
  487. FILE "${CMAKE_BINARY_DIR}/libigl-export.cmake"
  488. )
  489. install(EXPORT igl-export DESTINATION ${CMAKE_INSTALL_DATADIR}/libigl/cmake FILE libigl-export.cmake)
  490. export(PACKAGE libigl)