libigl.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. ### Find packages to populate default options ###
  20. #
  21. # COMPONENTS should match subsequent calls
  22. find_package(Matlab COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY) # --> Matlab_FOUND
  23. find_package(MOSEK) # --> MOSEK_FOUND
  24. find_package(OpenGL) # --> OPENGL_FOUND
  25. ### Available options ###
  26. option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" ON)
  27. option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
  28. option(LIBIGL_WITH_CGAL "Use CGAL" ON)
  29. option(LIBIGL_WITH_COMISO "Use CoMiso" ON)
  30. option(LIBIGL_WITH_CORK "Use Cork" OFF)
  31. option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
  32. option(LIBIGL_WITH_LIM "Use LIM" ON)
  33. option(LIBIGL_WITH_MATLAB "Use Matlab" "${Matlab_FOUND}")
  34. option(LIBIGL_WITH_MOSEK "Use MOSEK" "${MOSEK_FOUND}")
  35. option(LIBIGL_WITH_OPENGL "Use OpenGL" "${OPENGL_FOUND}")
  36. option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" "${OPENGL_FOUND}")
  37. option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
  38. option(LIBIGL_WITH_PNG "Use PNG" ON)
  39. option(LIBIGL_WITH_TETGEN "Use Tetgen" ON)
  40. option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON)
  41. option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" "${OPENGL_FOUND}")
  42. option(LIBIGL_WITH_XML "Use XML" ON)
  43. option(LIBIGL_WITH_PYTHON "Use Python" OFF)
  44. if(LIBIGL_WITH_VIEWER AND (NOT LIBIGL_WITH_OPENGL_GLFW OR NOT LIBIGL_WITH_OPENGL) )
  45. message(FATAL_ERROR "LIBIGL_WITH_VIEWER=ON requires LIBIGL_WITH_OPENGL_GLFW=ON and LIBIGL_WITH_OPENGL=ON")
  46. endif()
  47. ################################################################################
  48. ### Configuration
  49. set(LIBIGL_ROOT "${CMAKE_CURRENT_LIST_DIR}/../..")
  50. set(LIBIGL_SOURCE_DIR "${LIBIGL_ROOT}/include")
  51. set(LIBIGL_EXTERNAL "${LIBIGL_ROOT}/external")
  52. # Dependencies are linked as INTERFACE targets unless libigl is compiled as a static library
  53. if(LIBIGL_USE_STATIC_LIBRARY)
  54. set(IGL_SCOPE PUBLIC)
  55. else()
  56. set(IGL_SCOPE INTERFACE)
  57. endif()
  58. ################################################################################
  59. ### IGL Common
  60. ################################################################################
  61. add_library(igl_common INTERFACE)
  62. target_include_directories(igl_common SYSTEM INTERFACE
  63. $<BUILD_INTERFACE:${LIBIGL_SOURCE_DIR}>
  64. $<INSTALL_INTERFACE:include>
  65. )
  66. # Export igl_common as igl::common
  67. set_property(TARGET igl_common PROPERTY EXPORT_NAME igl::common)
  68. if(LIBIGL_USE_STATIC_LIBRARY)
  69. target_compile_definitions(igl_common INTERFACE -DIGL_STATIC_LIBRARY)
  70. endif()
  71. # Transitive C++11 flags
  72. include(CXXFeatures)
  73. target_compile_features(igl_common INTERFACE ${CXX11_FEATURES})
  74. # Other compilation flags
  75. if(MSVC)
  76. # Enable parallel compilation for Visual Studio
  77. target_compile_options(igl_common INTERFACE /MP /bigobj)
  78. endif()
  79. if(BUILD_SHARED_LIBS)
  80. # Generate position independent code
  81. set_target_properties(igl_common PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ON)
  82. endif()
  83. # Eigen
  84. if(TARGET Eigen3::Eigen)
  85. # If an imported target already exists, use it
  86. target_link_libraries(igl_common INTERFACE Eigen3::Eigen)
  87. else()
  88. target_include_directories(igl_common SYSTEM INTERFACE
  89. $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
  90. $<INSTALL_INTERFACE:include>
  91. )
  92. endif()
  93. # C++11 Thread library
  94. find_package(Threads REQUIRED)
  95. target_link_libraries(igl_common INTERFACE ${CMAKE_THREAD_LIBS_INIT})
  96. ################################################################################
  97. include(DownloadProject)
  98. # Shortcut function
  99. function(igl_download_project name)
  100. download_project(
  101. PROJ ${name}
  102. SOURCE_DIR ${LIBIGL_EXTERNAL}/${name}
  103. DOWNLOAD_DIR ${LIBIGL_EXTERNAL}/.cache/${name}
  104. ${ARGN}
  105. )
  106. endfunction()
  107. ################################################################################
  108. ## CGAL dependencies on Windows: GMP & MPFR
  109. function(igl_download_cgal_deps)
  110. if(WIN32)
  111. igl_download_project(gmp
  112. URL https://cgal.geometryfactory.com/CGAL/precompiled_libs/auxiliary/x64/GMP/5.0.1/gmp-all-CGAL-3.9.zip
  113. URL_MD5 508c1292319c832609329116a8234c9f
  114. )
  115. igl_download_project(mpfr
  116. URL https://cgal.geometryfactory.com/CGAL/precompiled_libs/auxiliary/x64/MPFR/3.0.0/mpfr-all-CGAL-3.9.zip
  117. URL_MD5 48840454eef0ff18730050c05028734b
  118. )
  119. set(ENV{GMP_DIR} "${LIBIGL_EXTERNAL}/gmp")
  120. set(ENV{MPFR_DIR} "${LIBIGL_EXTERNAL}/mpfr")
  121. endif()
  122. endfunction()
  123. ################################################################################
  124. function(compile_igl_module module_dir)
  125. string(REPLACE "/" "_" module_name "${module_dir}")
  126. if(module_name STREQUAL "core")
  127. set(module_libname "igl")
  128. else()
  129. set(module_libname "igl_${module_name}")
  130. endif()
  131. if(LIBIGL_USE_STATIC_LIBRARY)
  132. file(GLOB SOURCES_IGL_${module_name}
  133. "${LIBIGL_SOURCE_DIR}/igl/${module_dir}/*.cpp"
  134. "${LIBIGL_SOURCE_DIR}/igl/copyleft/${module_dir}/*.cpp")
  135. add_library(${module_libname} STATIC ${SOURCES_IGL_${module_name}} ${ARGN})
  136. if(MSVC)
  137. target_compile_options(${module_libname} PRIVATE /w) # disable all warnings (not ideal but...)
  138. else()
  139. #target_compile_options(${module_libname} PRIVATE -w) # disable all warnings (not ideal but...)
  140. endif()
  141. else()
  142. add_library(${module_libname} INTERFACE)
  143. endif()
  144. target_link_libraries(${module_libname} ${IGL_SCOPE} igl_common)
  145. if(NOT module_name STREQUAL "core")
  146. target_link_libraries(${module_libname} ${IGL_SCOPE} igl)
  147. endif()
  148. # Alias target because it looks nicer
  149. message(STATUS "Creating target: igl::${module_name} (${module_libname})")
  150. add_library(igl::${module_name} ALIAS ${module_libname})
  151. # Export as igl::${module_name}
  152. set_property(TARGET ${module_libname} PROPERTY EXPORT_NAME igl::${module_name})
  153. endfunction()
  154. ################################################################################
  155. ### IGL Core
  156. ################################################################################
  157. if(LIBIGL_USE_STATIC_LIBRARY)
  158. file(GLOB SOURCES_IGL
  159. "${LIBIGL_SOURCE_DIR}/igl/*.cpp"
  160. "${LIBIGL_SOURCE_DIR}/igl/copyleft/*.cpp")
  161. endif()
  162. compile_igl_module("core" ${SOURCES_IGL})
  163. ################################################################################
  164. ## Compile the AntTweakBar part ###
  165. if(LIBIGL_WITH_ANTTWEAKBAR)
  166. set(ANTTWEAKBAR_DIR "${LIBIGL_EXTERNAL}/AntTweakBar")
  167. if(NOT TARGET AntTweakBar)
  168. add_subdirectory("${ANTTWEAKBAR_DIR}" AntTweakBar)
  169. endif()
  170. compile_igl_module("anttweakbar")
  171. target_link_libraries(igl_anttweakbar ${IGL_SCOPE} AntTweakBar)
  172. target_include_directories(igl_anttweakbar ${IGL_SCOPE} "${ANTTWEAKBAR_DIR}/include")
  173. endif()
  174. ################################################################################
  175. ### Compile the CGAL part ###
  176. if(LIBIGL_WITH_CGAL)
  177. # Try to find the CGAL library
  178. # CGAL Core is needed for
  179. # `Exact_predicates_exact_constructions_kernel_with_sqrt`
  180. if(NOT TARGET CGAL::CGAL)
  181. set(CGAL_DIR "${LIBIGL_EXTERNAL}/cgal")
  182. igl_download_cgal_deps()
  183. if(EXISTS ${LIBIGL_EXTERNAL}/boost)
  184. set(BOOST_ROOT "${LIBIGL_EXTERNAL}/boost")
  185. endif()
  186. set(CGAL_Boost_USE_STATIC_LIBS ON CACHE BOOL "" FORCE)
  187. find_package(CGAL CONFIG COMPONENTS Core PATHS ${CGAL_DIR} NO_DEFAULT_PATH)
  188. endif()
  189. # If CGAL has been found, then build the libigl module
  190. if(TARGET CGAL::CGAL AND TARGET CGAL::CGAL_Core)
  191. compile_igl_module("cgal")
  192. target_link_libraries(igl_cgal ${IGL_SCOPE} CGAL::CGAL CGAL::CGAL_Core)
  193. else()
  194. set(LIBIGL_WITH_CGAL OFF CACHE BOOL "" FORCE)
  195. endif()
  196. endif()
  197. # Helper function for `igl_copy_cgal_dll()`
  198. function(igl_copy_imported_dll src_target dst_target)
  199. get_target_property(other_libs ${src_target} INTERFACE_LINK_LIBRARIES)
  200. set(locations)
  201. list(APPEND locations ${main_lib} ${other_libs})
  202. foreach(location ${locations})
  203. string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${location})
  204. set(location "${CMAKE_MATCH_1}.dll")
  205. if(EXISTS "${location}" AND location MATCHES "^.*\\.dll$")
  206. add_custom_command(TARGET ${dst_target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${location}" $<TARGET_FILE_DIR:${dst_target}>)
  207. endif()
  208. endforeach()
  209. endfunction()
  210. # Convenient functions to copy CGAL dlls into a target (executable) destination folder (for Windows)
  211. function(igl_copy_cgal_dll target)
  212. if(WIN32 AND LIBIGL_WITH_CGAL)
  213. igl_copy_imported_dll(CGAL::CGAL ${target})
  214. igl_copy_imported_dll(CGAL::CGAL_Core ${target})
  215. endif()
  216. endfunction()
  217. ################################################################################
  218. ### Compile the CoMISo part ###
  219. # NOTE: this cmakefile works only with the
  220. # comiso available here: https://github.com/libigl/CoMISo
  221. if(LIBIGL_WITH_COMISO)
  222. compile_igl_module("comiso")
  223. if(NOT TARGET CoMISo)
  224. add_subdirectory("${LIBIGL_EXTERNAL}/CoMISo" CoMISo)
  225. endif()
  226. target_link_libraries(igl_comiso ${IGL_SCOPE} CoMISo)
  227. endif()
  228. ################################################################################
  229. ### Compile the cork part ###
  230. if(LIBIGL_WITH_CORK)
  231. set(CORK_DIR "${LIBIGL_EXTERNAL}/cork")
  232. if(NOT TARGET cork)
  233. # call this "lib-cork" instead of "cork", otherwise cmake gets confused about
  234. # "cork" executable
  235. add_subdirectory("${CORK_DIR}" "lib-cork")
  236. endif()
  237. compile_igl_module("cork")
  238. target_include_directories(igl_cork ${IGL_SCOPE} cork)
  239. target_include_directories(igl_cork ${IGL_SCOPE} "${CORK_DIR}/src")
  240. target_link_libraries(igl_cork ${IGL_SCOPE} cork)
  241. endif()
  242. ################################################################################
  243. ### Compile the embree part ###
  244. if(LIBIGL_WITH_EMBREE)
  245. set(EMBREE_DIR "${LIBIGL_EXTERNAL}/embree")
  246. set(EMBREE_ISPC_SUPPORT OFF CACHE BOOL " " FORCE)
  247. set(EMBREE_TASKING_SYSTEM "INTERNAL" CACHE BOOL " " FORCE)
  248. set(EMBREE_TUTORIALS OFF CACHE BOOL " " FORCE)
  249. set(EMBREE_MAX_ISA NONE CACHE STRINGS " " FORCE)
  250. set(BUILD_TESTING OFF CACHE BOOL " " FORCE)
  251. # set(ENABLE_INSTALLER OFF CACHE BOOL " " FORCE)
  252. if(MSVC)
  253. # set(EMBREE_STATIC_RUNTIME OFF CACHE BOOL " " FORCE)
  254. set(EMBREE_STATIC_LIB OFF CACHE BOOL " " FORCE)
  255. else()
  256. set(EMBREE_STATIC_LIB ON CACHE BOOL " " FORCE)
  257. endif()
  258. if(NOT TARGET embree)
  259. add_subdirectory("${EMBREE_DIR}" "embree")
  260. endif()
  261. if(MSVC)
  262. add_custom_target(Copy-Embree-DLL ALL # Adds a post-build event
  263. COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E
  264. $<TARGET_FILE:embree> # <--this is in-file
  265. "${CMAKE_BINARY_DIR}" # <--this is out-file path
  266. DEPENDS embree) # Execute after embree target has been built
  267. endif()
  268. compile_igl_module("embree")
  269. target_link_libraries(igl_embree ${IGL_SCOPE} embree)
  270. target_include_directories(igl_embree ${IGL_SCOPE} ${EMBREE_DIR}/include)
  271. if(NOT MSVC)
  272. target_compile_definitions(igl_embree ${IGL_SCOPE} -DENABLE_STATIC_LIB)
  273. endif()
  274. endif()
  275. ################################################################################
  276. ### Compile the lim part ###
  277. if(LIBIGL_WITH_LIM)
  278. set(LIM_DIR "${LIBIGL_EXTERNAL}/lim")
  279. if(NOT TARGET lim)
  280. add_subdirectory("${LIM_DIR}" "lim")
  281. endif()
  282. compile_igl_module("lim")
  283. target_link_libraries(igl_lim ${IGL_SCOPE} lim)
  284. target_include_directories(igl_lim ${IGL_SCOPE} ${LIM_DIR})
  285. endif()
  286. ################################################################################
  287. ### Compile the matlab part ###
  288. if(LIBIGL_WITH_MATLAB)
  289. find_package(Matlab REQUIRED COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY)
  290. compile_igl_module("matlab")
  291. target_link_libraries(igl_matlab ${IGL_SCOPE} ${Matlab_LIBRARIES})
  292. target_include_directories(igl_matlab ${IGL_SCOPE} ${Matlab_INCLUDE_DIRS})
  293. endif()
  294. ################################################################################
  295. ### Compile the mosek part ###
  296. if(LIBIGL_WITH_MOSEK)
  297. find_package(MOSEK REQUIRED)
  298. compile_igl_module("mosek")
  299. target_link_libraries(igl_mosek ${IGL_SCOPE} ${MOSEK_LIBRARIES})
  300. target_include_directories(igl_mosek ${IGL_SCOPE} ${MOSEK_INCLUDE_DIRS})
  301. target_compile_definitions(igl_mosek ${IGL_SCOPE} -DLIBIGL_WITH_MOSEK)
  302. endif()
  303. ################################################################################
  304. ### Compile the opengl part ###
  305. if(LIBIGL_WITH_OPENGL)
  306. # OpenGL module
  307. find_package(OpenGL REQUIRED)
  308. compile_igl_module("opengl")
  309. target_link_libraries(igl_opengl ${IGL_SCOPE} ${OPENGL_gl_LIBRARY})
  310. target_include_directories(igl_opengl SYSTEM ${IGL_SCOPE} ${OPENGL_INCLUDE_DIR})
  311. # glad module
  312. if(NOT TARGET 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. add_subdirectory(${LIBIGL_EXTERNAL}/glfw glfw)
  329. endif()
  330. target_link_libraries(igl_opengl_glfw ${IGL_SCOPE} igl_opengl glfw)
  331. endif()
  332. endif()
  333. ################################################################################
  334. ### Compile the ImGui part ###
  335. if(LIBIGL_WITH_OPENGL_GLFW_IMGUI)
  336. if(TARGET igl::opengl_glfw)
  337. # ImGui module
  338. compile_igl_module("opengl/glfw/imgui")
  339. if(NOT TARGET imgui)
  340. add_subdirectory(${LIBIGL_EXTERNAL}/imgui imgui)
  341. endif()
  342. target_link_libraries(igl_opengl_glfw_imgui ${IGL_SCOPE} igl_opengl_glfw imgui)
  343. endif()
  344. endif()
  345. ################################################################################
  346. ### Compile the png part ###
  347. if(LIBIGL_WITH_PNG)
  348. # png/ module is anomalous because it also depends on opengl it really should
  349. # be moved into the opengl/ directory and namespace ...
  350. if(TARGET igl_opengl)
  351. set(STB_IMAGE_DIR "${LIBIGL_EXTERNAL}/stb_image")
  352. if(NOT TARGET stb_image)
  353. add_subdirectory("${STB_IMAGE_DIR}" "stb_image")
  354. endif()
  355. compile_igl_module("png" "")
  356. target_link_libraries(igl_png ${IGL_SCOPE} igl_stb_image igl_opengl)
  357. endif()
  358. endif()
  359. ################################################################################
  360. ### Compile the tetgen part ###
  361. if(LIBIGL_WITH_TETGEN)
  362. set(TETGEN_DIR "${LIBIGL_EXTERNAL}/tetgen")
  363. if(NOT TARGET tetgen)
  364. add_subdirectory("${TETGEN_DIR}" "tetgen")
  365. endif()
  366. compile_igl_module("tetgen")
  367. target_link_libraries(igl_tetgen ${IGL_SCOPE} tetgen)
  368. target_include_directories(igl_tetgen ${IGL_SCOPE} ${TETGEN_DIR})
  369. endif()
  370. ################################################################################
  371. ### Compile the triangle part ###
  372. if(LIBIGL_WITH_TRIANGLE)
  373. set(TRIANGLE_DIR "${LIBIGL_EXTERNAL}/triangle")
  374. if(NOT TARGET triangle)
  375. add_subdirectory("${TRIANGLE_DIR}" "triangle")
  376. endif()
  377. compile_igl_module("triangle")
  378. target_link_libraries(igl_triangle ${IGL_SCOPE} triangle)
  379. target_include_directories(igl_triangle ${IGL_SCOPE} ${TRIANGLE_DIR})
  380. endif()
  381. ################################################################################
  382. ### Compile the xml part ###
  383. if(LIBIGL_WITH_XML)
  384. set(TINYXML2_DIR "${LIBIGL_EXTERNAL}/tinyxml2")
  385. if(NOT TARGET tinyxml2)
  386. add_library(tinyxml2 STATIC ${TINYXML2_DIR}/tinyxml2.cpp ${TINYXML2_DIR}/tinyxml2.h)
  387. set_target_properties(tinyxml2 PROPERTIES
  388. COMPILE_DEFINITIONS "TINYXML2_EXPORT"
  389. VERSION "3.0.0"
  390. SOVERSION "3")
  391. endif()
  392. compile_igl_module("xml")
  393. target_link_libraries(igl_xml ${IGL_SCOPE} tinyxml2)
  394. target_include_directories(igl_xml ${IGL_SCOPE} ${TINYXML2_DIR})
  395. endif()
  396. ################################################################################
  397. ### Install and export all modules
  398. function(install_dir_files dir_name)
  399. if (dir_name STREQUAL "core")
  400. set(subpath "")
  401. else()
  402. set(subpath "/${dir_name}")
  403. endif()
  404. file(GLOB public_headers
  405. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.h
  406. )
  407. set(files_to_install ${public_headers})
  408. if(NOT LIBIGL_USE_STATIC_LIBRARY)
  409. file(GLOB public_sources
  410. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.cpp
  411. )
  412. endif()
  413. list(APPEND files_to_install ${public_sources})
  414. install(
  415. FILES ${files_to_install}
  416. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/igl${subpath}
  417. )
  418. endfunction()
  419. ################################################################################
  420. include(GNUInstallDirs)
  421. include(CMakePackageConfigHelpers)
  422. # Install and export core library
  423. install(
  424. TARGETS
  425. igl
  426. igl_common
  427. EXPORT igl-export
  428. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  429. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  430. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  431. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  432. )
  433. export(
  434. TARGETS
  435. igl
  436. igl_common
  437. FILE libigl-export.cmake
  438. )
  439. # Install headers for core library
  440. install_dir_files(core)
  441. install_dir_files(copyleft)
  442. # Write package configuration file
  443. configure_package_config_file(
  444. ${CMAKE_CURRENT_LIST_DIR}/libigl-config.cmake.in
  445. ${CMAKE_BINARY_DIR}/libigl-config.cmake
  446. INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/libigl/cmake
  447. )
  448. install(
  449. FILES
  450. ${CMAKE_BINARY_DIR}/libigl-config.cmake
  451. DESTINATION
  452. ${CMAKE_INSTALL_DATADIR}/libigl/cmake
  453. )
  454. # Write export file
  455. export(EXPORT igl-export
  456. FILE "${CMAKE_BINARY_DIR}/libigl-export.cmake"
  457. )
  458. install(EXPORT igl-export DESTINATION ${CMAKE_INSTALL_DATADIR}/libigl/cmake FILE libigl-export.cmake)
  459. export(PACKAGE libigl)