libigl.cmake 18 KB

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