libigl.cmake 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. cmake_minimum_required(VERSION 3.8)
  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. # Provides igl_set_folders() to set folders for Visual Studio/Xcode
  55. include(LibiglFolders)
  56. ################################################################################
  57. ### IGL Common
  58. ################################################################################
  59. add_library(igl_common INTERFACE)
  60. target_include_directories(igl_common SYSTEM INTERFACE
  61. $<BUILD_INTERFACE:${LIBIGL_SOURCE_DIR}>
  62. $<INSTALL_INTERFACE:include>
  63. )
  64. # Export igl_common as igl::common
  65. set_property(TARGET igl_common PROPERTY EXPORT_NAME igl::common)
  66. if(LIBIGL_USE_STATIC_LIBRARY)
  67. target_compile_definitions(igl_common INTERFACE -DIGL_STATIC_LIBRARY)
  68. endif()
  69. # Transitive C++11 flags
  70. include(CXXFeatures)
  71. target_compile_features(igl_common INTERFACE ${CXX11_FEATURES})
  72. # Other compilation flags
  73. if(MSVC)
  74. # Enable parallel compilation for Visual Studio
  75. target_compile_options(igl_common INTERFACE $<$<COMPILE_LANGUAGE:CXX>:/MP> $<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
  76. target_compile_definitions(igl_common INTERFACE -DNOMINMAX)
  77. endif()
  78. # Controls whether to use the static MSVC runtime or not
  79. include(LibiglWindows)
  80. if(BUILD_SHARED_LIBS)
  81. # Generate position independent code
  82. set_target_properties(igl_common PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ON)
  83. endif()
  84. if(UNIX AND NOT HUNTER_ENABLED)
  85. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
  86. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  87. endif()
  88. if(HUNTER_ENABLED)
  89. hunter_add_package(Eigen)
  90. find_package(Eigen3 CONFIG REQUIRED)
  91. endif()
  92. # Eigen
  93. if(NOT TARGET Eigen3::Eigen)
  94. igl_download_eigen()
  95. add_library(igl_eigen INTERFACE)
  96. target_include_directories(igl_eigen SYSTEM INTERFACE
  97. $<BUILD_INTERFACE:${LIBIGL_EXTERNAL}/eigen>
  98. $<INSTALL_INTERFACE:include>
  99. )
  100. set_property(TARGET igl_eigen PROPERTY EXPORT_NAME Eigen3::Eigen)
  101. add_library(Eigen3::Eigen ALIAS igl_eigen)
  102. endif()
  103. target_link_libraries(igl_common INTERFACE Eigen3::Eigen)
  104. # C++11 Thread library
  105. find_package(Threads REQUIRED)
  106. target_link_libraries(igl_common INTERFACE ${CMAKE_THREAD_LIBS_INIT})
  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/${module_dir}/*.h*"
  135. )
  136. if(NOT LIBIGL_WITHOUT_COPYLEFT)
  137. file(GLOB COPYLEFT_SOURCES_IGL_${module_name}
  138. "${LIBIGL_SOURCE_DIR}/igl/copyleft/${module_dir}/*.cpp"
  139. "${LIBIGL_SOURCE_DIR}/igl/copyleft/${module_dir}/*.h*"
  140. )
  141. list(APPEND SOURCES_IGL_${module_name} ${COPYLEFT_SOURCES_IGL_${module_name}})
  142. endif()
  143. add_library(${module_libname} STATIC ${SOURCES_IGL_${module_name}} ${ARGN})
  144. if(MSVC)
  145. # Silencing some compile warnings
  146. target_compile_options(${module_libname} PRIVATE
  147. # Type conversion warnings. These can be fixed with some effort and possibly more verbose code.
  148. /wd4267 # conversion from 'size_t' to 'type', possible loss of data
  149. /wd4244 # conversion from 'type1' to 'type2', possible loss of data
  150. /wd4018 # signed/unsigned mismatch
  151. /wd4305 # truncation from 'double' to 'float'
  152. # This one is from template instantiations generated by autoexplicit.sh:
  153. /wd4667 # no function template defined that matches forced instantiation ()
  154. # This one is easy to fix, just need to switch to safe version of C functions
  155. /wd4996 # this function or variable may be unsafe
  156. # This one is when using bools in adjacency matrices
  157. /wd4804 #'+=': unsafe use of type 'bool' in operation
  158. )
  159. endif()
  160. else()
  161. add_library(${module_libname} INTERFACE)
  162. endif()
  163. target_link_libraries(${module_libname} ${IGL_SCOPE} igl_common)
  164. if(NOT module_name STREQUAL "core")
  165. target_link_libraries(${module_libname} ${IGL_SCOPE} igl)
  166. endif()
  167. # Alias target because it looks nicer
  168. message(STATUS "Creating target: igl::${module_name} (${module_libname})")
  169. add_library(igl::${module_name} ALIAS ${module_libname})
  170. # Export as igl::${module_name}
  171. set_property(TARGET ${module_libname} PROPERTY EXPORT_NAME igl::${module_name})
  172. endfunction()
  173. ################################################################################
  174. ### IGL Core
  175. ################################################################################
  176. if(LIBIGL_USE_STATIC_LIBRARY)
  177. file(GLOB SOURCES_IGL
  178. "${LIBIGL_SOURCE_DIR}/igl/*.cpp"
  179. "${LIBIGL_SOURCE_DIR}/igl/*.h*"
  180. "${LIBIGL_SOURCE_DIR}/igl/copyleft/*.cpp"
  181. "${LIBIGL_SOURCE_DIR}/igl/copyleft/*.h*"
  182. )
  183. endif()
  184. compile_igl_module("core" ${SOURCES_IGL})
  185. ################################################################################
  186. ### Download the python part ###
  187. if(LIBIGL_WITH_PYTHON)
  188. endif()
  189. ################################################################################
  190. ### Compile the CGAL part ###
  191. if(LIBIGL_WITH_CGAL)
  192. # Try to find the CGAL library
  193. # CGAL Core is needed for
  194. # `Exact_predicates_exact_constructions_kernel_with_sqrt`
  195. if(NOT TARGET CGAL::CGAL)
  196. set(CGAL_DIR "${LIBIGL_EXTERNAL}/cgal")
  197. igl_download_cgal()
  198. igl_download_cgal_deps()
  199. message("BOOST_ROOT: ${BOOST_ROOT}")
  200. if(EXISTS ${LIBIGL_EXTERNAL}/boost)
  201. set(BOOST_ROOT "${LIBIGL_EXTERNAL}/boost")
  202. endif()
  203. option(CGAL_Boost_USE_STATIC_LIBS "Use static Boost libs with CGAL" ON)
  204. find_package(CGAL CONFIG COMPONENTS Core PATHS ${CGAL_DIR} NO_DEFAULT_PATH)
  205. endif()
  206. # If CGAL has been found, then build the libigl module
  207. if(TARGET CGAL::CGAL AND TARGET CGAL::CGAL_Core)
  208. compile_igl_module("cgal")
  209. target_link_libraries(igl_cgal ${IGL_SCOPE} CGAL::CGAL CGAL::CGAL_Core)
  210. else()
  211. message(FATAL_ERROR "Could not define CGAL::CGAL and CGAL::CGAL_Core.")
  212. endif()
  213. endif()
  214. # Helper function for `igl_copy_cgal_dll()`
  215. function(igl_copy_imported_dll src_target dst_target)
  216. get_target_property(other_libs ${src_target} INTERFACE_LINK_LIBRARIES)
  217. set(locations)
  218. list(APPEND locations ${main_lib} ${other_libs})
  219. foreach(location ${locations})
  220. string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${location})
  221. set(location "${CMAKE_MATCH_1}.dll")
  222. if(EXISTS "${location}" AND location MATCHES "^.*\\.dll$")
  223. add_custom_command(TARGET ${dst_target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${location}" $<TARGET_FILE_DIR:${dst_target}>)
  224. endif()
  225. endforeach()
  226. endfunction()
  227. # Convenient functions to copy CGAL dlls into a target (executable) destination folder (for Windows)
  228. function(igl_copy_cgal_dll target)
  229. if(WIN32 AND LIBIGL_WITH_CGAL)
  230. igl_copy_imported_dll(CGAL::CGAL ${target})
  231. igl_copy_imported_dll(CGAL::CGAL_Core ${target})
  232. endif()
  233. endfunction()
  234. ################################################################################
  235. ### Compile the CoMISo part ###
  236. # NOTE: this cmakefile works only with the
  237. # comiso available here: https://github.com/libigl/CoMISo
  238. if(LIBIGL_WITH_COMISO)
  239. compile_igl_module("comiso")
  240. if(NOT TARGET CoMISo)
  241. igl_download_comiso()
  242. add_subdirectory("${LIBIGL_EXTERNAL}/CoMISo" CoMISo)
  243. endif()
  244. target_link_libraries(igl_comiso ${IGL_SCOPE} CoMISo)
  245. endif()
  246. ################################################################################
  247. ### Compile the cork part ###
  248. if(LIBIGL_WITH_CORK)
  249. set(CORK_DIR "${LIBIGL_EXTERNAL}/cork")
  250. if(NOT TARGET cork)
  251. # call this "lib-cork" instead of "cork", otherwise cmake gets confused about
  252. # "cork" executable
  253. igl_download_cork()
  254. add_subdirectory("${CORK_DIR}" "lib-cork")
  255. endif()
  256. compile_igl_module("cork")
  257. target_include_directories(igl_cork ${IGL_SCOPE} cork)
  258. target_include_directories(igl_cork ${IGL_SCOPE} "${CORK_DIR}/src")
  259. target_link_libraries(igl_cork ${IGL_SCOPE} cork)
  260. endif()
  261. ################################################################################
  262. ### Compile the embree part ###
  263. if(LIBIGL_WITH_EMBREE)
  264. set(EMBREE_DIR "${LIBIGL_EXTERNAL}/embree")
  265. if(NOT TARGET embree)
  266. igl_download_embree()
  267. # Note: On macOS, building embree as a static lib can only be done with a single ISA target.
  268. set(EMBREE_MAX_ISA "DEFAULT" CACHE STRING "Selects highest ISA to support.")
  269. set(EMBREE_TESTING_INTENSITY 0 CACHE STRING "")
  270. set(EMBREE_ISPC_SUPPORT OFF CACHE BOOL " ")
  271. set(EMBREE_TASKING_SYSTEM "INTERNAL" CACHE BOOL " ")
  272. set(EMBREE_TUTORIALS OFF CACHE BOOL " ")
  273. set(EMBREE_STATIC_LIB ON CACHE BOOL " ")
  274. if(MSVC)
  275. set(EMBREE_STATIC_RUNTIME ${IGL_STATIC_RUNTIME} CACHE BOOL "Use the static version of the C/C++ runtime library.")
  276. endif()
  277. add_subdirectory("${EMBREE_DIR}" "embree" EXCLUDE_FROM_ALL)
  278. endif()
  279. compile_igl_module("embree")
  280. target_link_libraries(igl_embree ${IGL_SCOPE} embree)
  281. target_include_directories(igl_embree ${IGL_SCOPE} ${EMBREE_DIR}/include)
  282. target_compile_definitions(igl_embree ${IGL_SCOPE} -DEMBREE_STATIC_LIB)
  283. endif()
  284. ################################################################################
  285. ### Compile the matlab part ###
  286. if(LIBIGL_WITH_MATLAB)
  287. find_package(Matlab REQUIRED COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY MAT_LIBRARY)
  288. compile_igl_module("matlab")
  289. target_link_libraries(igl_matlab ${IGL_SCOPE} ${Matlab_LIBRARIES})
  290. target_include_directories(igl_matlab ${IGL_SCOPE} ${Matlab_INCLUDE_DIRS})
  291. endif()
  292. ################################################################################
  293. ### Compile the mosek part ###
  294. if(LIBIGL_WITH_MOSEK)
  295. find_package(MOSEK REQUIRED)
  296. compile_igl_module("mosek")
  297. target_link_libraries(igl_mosek ${IGL_SCOPE} ${MOSEK_LIBRARIES})
  298. target_include_directories(igl_mosek ${IGL_SCOPE} ${MOSEK_INCLUDE_DIRS})
  299. target_compile_definitions(igl_mosek ${IGL_SCOPE} -DLIBIGL_WITH_MOSEK)
  300. endif()
  301. ################################################################################
  302. ### Compile the opengl part ###
  303. if(LIBIGL_WITH_OPENGL)
  304. # OpenGL module
  305. compile_igl_module("opengl")
  306. # OpenGL library
  307. if (NOT CMAKE_VERSION VERSION_LESS "3.11")
  308. cmake_policy(SET CMP0072 NEW)
  309. endif()
  310. find_package(OpenGL REQUIRED OPTIONAL_COMPONENTS OpenGL)
  311. if(TARGET OpenGL::OpenGL)
  312. target_link_libraries(igl_opengl ${IGL_SCOPE} OpenGL::OpenGL)
  313. else()
  314. target_link_libraries(igl_opengl ${IGL_SCOPE} OpenGL::GL)
  315. endif()
  316. # glad module
  317. if(NOT TARGET glad)
  318. igl_download_glad()
  319. add_subdirectory(${LIBIGL_EXTERNAL}/glad glad)
  320. endif()
  321. target_link_libraries(igl_opengl ${IGL_SCOPE} glad)
  322. endif()
  323. ################################################################################
  324. ### Compile the GLFW part ###
  325. if(LIBIGL_WITH_OPENGL_GLFW)
  326. if(TARGET igl::opengl)
  327. # GLFW module
  328. compile_igl_module("opengl/glfw")
  329. if(NOT TARGET glfw)
  330. igl_download_glfw()
  331. option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
  332. option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
  333. option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF)
  334. option(GLFW_INSTALL "Generate installation target" OFF)
  335. if(IGL_STATIC_RUNTIME)
  336. set(USE_MSVC_RUNTIME_LIBRARY_DLL OFF CACHE BOOL "Use MSVC runtime library DLL" FORCE)
  337. else()
  338. set(USE_MSVC_RUNTIME_LIBRARY_DLL ON CACHE BOOL "Use MSVC runtime library DLL" FORCE)
  339. endif()
  340. add_subdirectory(${LIBIGL_EXTERNAL}/glfw glfw)
  341. endif()
  342. target_link_libraries(igl_opengl_glfw ${IGL_SCOPE} igl_opengl glfw)
  343. endif()
  344. endif()
  345. ################################################################################
  346. ### Compile the ImGui part ###
  347. if(LIBIGL_WITH_OPENGL_GLFW_IMGUI)
  348. if(TARGET igl::opengl_glfw)
  349. # ImGui module
  350. compile_igl_module("opengl/glfw/imgui")
  351. if(NOT TARGET imgui)
  352. igl_download_imgui()
  353. add_subdirectory(${LIBIGL_EXTERNAL}/libigl-imgui imgui)
  354. endif()
  355. if(NOT TARGET imguizmo)
  356. igl_download_imguizmo()
  357. add_library(imguizmo ${LIBIGL_EXTERNAL}/imguizmo/ImGuizmo.cpp ${LIBIGL_EXTERNAL}/imguizmo/ImGuizmo.h)
  358. target_compile_features(imguizmo PUBLIC cxx_std_11)
  359. target_link_libraries(imguizmo PUBLIC imgui)
  360. endif()
  361. target_link_libraries(igl_opengl_glfw_imgui ${IGL_SCOPE} igl_opengl_glfw imgui imguizmo)
  362. endif()
  363. endif()
  364. ################################################################################
  365. ### Compile the png part ###
  366. if(LIBIGL_WITH_PNG)
  367. # png/ module is anomalous because it also depends on opengl it really should
  368. # be moved into the opengl/ directory and namespace ...
  369. if(TARGET igl_opengl)
  370. if(NOT TARGET stb_image)
  371. igl_download_stb()
  372. add_subdirectory(${LIBIGL_EXTERNAL}/stb stb_image)
  373. endif()
  374. compile_igl_module("png" "")
  375. target_link_libraries(igl_png ${IGL_SCOPE} igl_stb_image igl_opengl)
  376. endif()
  377. endif()
  378. ################################################################################
  379. ### Compile the tetgen part ###
  380. if(LIBIGL_WITH_TETGEN)
  381. set(TETGEN_DIR "${LIBIGL_EXTERNAL}/tetgen")
  382. if(NOT TARGET tetgen)
  383. igl_download_tetgen()
  384. add_subdirectory("${TETGEN_DIR}" "tetgen")
  385. endif()
  386. compile_igl_module("tetgen")
  387. target_link_libraries(igl_tetgen ${IGL_SCOPE} tetgen)
  388. target_include_directories(igl_tetgen ${IGL_SCOPE} ${TETGEN_DIR})
  389. endif()
  390. ################################################################################
  391. ### Compile the triangle part ###
  392. if(LIBIGL_WITH_TRIANGLE)
  393. set(TRIANGLE_DIR "${LIBIGL_EXTERNAL}/triangle")
  394. if(NOT TARGET triangle)
  395. igl_download_triangle()
  396. add_subdirectory("${TRIANGLE_DIR}" "triangle")
  397. endif()
  398. compile_igl_module("triangle")
  399. target_link_libraries(igl_triangle ${IGL_SCOPE} triangle)
  400. target_include_directories(igl_triangle ${IGL_SCOPE} ${TRIANGLE_DIR})
  401. endif()
  402. ################################################################################
  403. ### Compile the predicates part ###
  404. if(LIBIGL_WITH_PREDICATES)
  405. set(PREDICATES_DIR "${LIBIGL_EXTERNAL}/predicates")
  406. if(NOT TARGET predicates)
  407. igl_download_predicates()
  408. add_subdirectory("${PREDICATES_DIR}" "predicates")
  409. endif()
  410. compile_igl_module("predicates")
  411. target_link_libraries(igl_predicates ${IGL_SCOPE} predicates)
  412. target_include_directories(igl_predicates ${IGL_SCOPE} ${PREDICATES_DIR})
  413. target_compile_definitions(igl_predicates ${IGL_SCOPE} -DLIBIGL_WITH_PREDICATES)
  414. endif()
  415. ################################################################################
  416. ### Compile the xml part ###
  417. if(LIBIGL_WITH_XML)
  418. set(TINYXML2_DIR "${LIBIGL_EXTERNAL}/tinyxml2")
  419. if(NOT TARGET tinyxml2)
  420. igl_download_tinyxml2()
  421. add_library(tinyxml2 STATIC ${TINYXML2_DIR}/tinyxml2.cpp ${TINYXML2_DIR}/tinyxml2.h)
  422. target_include_directories(tinyxml2 PUBLIC ${TINYXML2_DIR})
  423. set_target_properties(tinyxml2 PROPERTIES
  424. COMPILE_DEFINITIONS "TINYXML2_EXPORT"
  425. VERSION "3.0.0"
  426. SOVERSION "3")
  427. endif()
  428. compile_igl_module("xml")
  429. target_link_libraries(igl_xml ${IGL_SCOPE} tinyxml2)
  430. target_include_directories(igl_xml ${IGL_SCOPE} ${TINYXML2_DIR})
  431. endif()
  432. ################################################################################
  433. ### Install and export all modules
  434. if(NOT LIBIGL_EXPORT_TARGETS)
  435. return()
  436. endif()
  437. function(install_dir_files dir_name)
  438. if (dir_name STREQUAL "core")
  439. set(subpath "")
  440. else()
  441. set(subpath "/${dir_name}")
  442. endif()
  443. file(GLOB public_headers
  444. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.h
  445. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.hpp
  446. )
  447. set(files_to_install ${public_headers})
  448. if(NOT LIBIGL_USE_STATIC_LIBRARY)
  449. file(GLOB public_sources
  450. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.cpp
  451. ${CMAKE_CURRENT_SOURCE_DIR}/include/igl${subpath}/*.c
  452. )
  453. endif()
  454. list(APPEND files_to_install ${public_sources})
  455. install(
  456. FILES ${files_to_install}
  457. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/igl${subpath}
  458. )
  459. endfunction()
  460. ################################################################################
  461. include(GNUInstallDirs)
  462. include(CMakePackageConfigHelpers)
  463. if(TARGET igl_eigen)
  464. set(IGL_EIGEN igl_eigen)
  465. else()
  466. set(IGL_EIGEN)
  467. message(WARNING "Trying to export igl targets while using an imported target for Eigen.")
  468. endif()
  469. # Install and export core library
  470. install(
  471. TARGETS
  472. igl
  473. igl_common
  474. ${IGL_EIGEN}
  475. EXPORT igl-export
  476. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  477. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  478. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  479. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  480. )
  481. export(
  482. TARGETS
  483. igl
  484. igl_common
  485. ${IGL_EIGEN}
  486. FILE libigl-export.cmake
  487. )
  488. # Install headers for core library
  489. install_dir_files(core)
  490. install_dir_files(copyleft)
  491. # Write package configuration file
  492. configure_package_config_file(
  493. ${CMAKE_CURRENT_LIST_DIR}/libigl-config.cmake.in
  494. ${CMAKE_BINARY_DIR}/libigl-config.cmake
  495. INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/libigl/cmake
  496. )
  497. install(
  498. FILES
  499. ${CMAKE_BINARY_DIR}/libigl-config.cmake
  500. DESTINATION
  501. ${CMAKE_INSTALL_DATADIR}/libigl/cmake
  502. )
  503. # Write export file
  504. export(EXPORT igl-export
  505. FILE "${CMAKE_BINARY_DIR}/libigl-export.cmake"
  506. )
  507. install(EXPORT igl-export DESTINATION ${CMAKE_INSTALL_DATADIR}/libigl/cmake FILE libigl-export.cmake)
  508. export(PACKAGE libigl)