libigl.cmake 19 KB

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