igl_include.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Helper functions to include libigl modules
  2. function(_igl_include_full prefix name force)
  3. string(TOUPPER "${prefix}" prefix_uc)
  4. string(TOUPPER "${name}" name_uc)
  5. if(prefix_uc)
  6. string(PREPEND prefix_uc _)
  7. endif()
  8. string(TOLOWER "${prefix_uc}" prefix_lc)
  9. if(TARGET igl${prefix_lc}::${name})
  10. # Target already exists, skip
  11. return()
  12. endif()
  13. if(${force} AND NOT ${name} STREQUAL "core")
  14. message(STATUS "Forcing include of libigl module: ${name}")
  15. endif()
  16. # Dependencies are linked as INTERFACE targets unless libigl is compiled as a static library
  17. if(LIBIGL_USE_STATIC_LIBRARY)
  18. set(IGL_SCOPE PUBLIC)
  19. else()
  20. set(IGL_SCOPE INTERFACE)
  21. endif()
  22. # Retrieve module path use by libigl (necessary when calling igl_include() from a subproject)
  23. get_property(igl_module_path GLOBAL PROPERTY __igl_module_path)
  24. set(CMAKE_MODULE_PATH ${igl_module_path})
  25. # Include igl target definition
  26. if(LIBIGL${prefix_uc}_${name_uc} OR ${force})
  27. include(${libigl_SOURCE_DIR}/cmake/igl/modules/${prefix}/${name}.cmake)
  28. endif()
  29. endfunction()
  30. # Include module only if CMake option is provided
  31. function(igl_include_optional name)
  32. if(ARGC GREATER_EQUAL 2)
  33. # Two args given: prefix + name
  34. _igl_include_full(${name} ${ARGV1} FALSE)
  35. else()
  36. # Only one arg given: prefix (which contains module name)
  37. _igl_include_full("" ${name} FALSE)
  38. endif()
  39. endfunction()
  40. # Include module only unconditionally (e.g. if module is a dependency of another module)
  41. function(igl_include name)
  42. if(ARGC GREATER_EQUAL 2)
  43. # Two args given: prefix + name
  44. _igl_include_full(${name} ${ARGV1} TRUE)
  45. else()
  46. # Only one arg given: prefix (which contains module name)
  47. _igl_include_full("" ${name} TRUE)
  48. endif()
  49. endfunction()