Findlicensecc.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Distributed under the OSI-approved BSD 3-Clause License.
  2. #[=======================================================================[.rst:
  3. Findlicensecc
  4. -------
  5. Find or build the licensecc library.
  6. Imported Targets
  7. ^^^^^^^^^^^^^^^^
  8. This module provides the following imported targets, if found:
  9. ``licensecc::licensecc_static``
  10. The licensecc static library
  11. If licensecc is not found this module will try to download it as a submodule
  12. Git must be installed.
  13. Input variables
  14. ^^^^^^^^^^^^^^^^
  15. ``LICENSECC_LOCATION``
  16. Hint for locating the licenssecc library. It may point to the installation folder or the source folder
  17. ``LCC_PROJECT_NAME``
  18. or specifying a component name in the component section will cause the script to search for a project (primary key...) named as specified.
  19. Result Variables
  20. ^^^^^^^^^^^^^^^^
  21. This will define the following variables:
  22. ``licensecc_FOUND``
  23. True if the system has the licensecc library.
  24. ``lcc_VERSION``
  25. Version of licensecc
  26. Optionally the module will search for OpenSSL (if LicenseCC was compiled with this option).
  27. Cache Variables
  28. ^^^^^^^^^^^^^^^
  29. The following cache variables will also be set:
  30. ]=======================================================================]
  31. if(LICENSECC_LOCATION)
  32. #maybe it's pointing to the build directory
  33. if(EXISTS "${LICENSECC_LOCATION}/licensecc.cmake")
  34. include("${LICENSECC_LOCATION}/licensecc.cmake")
  35. get_property(COMPILE_DEF TARGET licensecc::licensecc_static PROPERTY INTERFACE_COMPILE_DEFINITIONS)
  36. if("HAS_OPENSSL" IN_LIST COMPILE_DEF AND NOT OpenSSL_FOUND)
  37. message(VERBOSE "Trying to find openssl (required by the target)")
  38. SET ( OPENSSL_USE_STATIC_LIBS ON )
  39. find_package(OpenSSL REQUIRED COMPONENTS Crypto)
  40. endif()
  41. else()
  42. #pointing to source?
  43. if(EXISTS "${LICENSECC_LOCATION}/CMakeLists.txt")
  44. if(licensecc_FIND_COMPONENTS)
  45. set(LCC_PROJECT_NAME ${licensecc_FIND_COMPONENTS})
  46. endif(licensecc_FIND_COMPONENTS)
  47. add_subdirectory("${LICENSECC_LOCATION}" "${CMAKE_BINARY_DIR}/licensecc")
  48. else()
  49. #try find as install directory
  50. find_package(licensecc HINTS
  51. ${LICENSECC_LOCATION} ${CMAKE_CURRENT_LIST_DIR}/${LICENSECC_LOCATION} CONFIG)
  52. endif()
  53. endif()
  54. ELSE(LICENSECC_LOCATION)
  55. if(licensecc_FIND_COMPONENTS)
  56. find_package(licensecc COMPONENTS ${licensecc_FIND_COMPONENTS}
  57. PATHS ${CMAKE_BINARY_DIR} ${CMAKE_INSTALL_PREFIX} QUIET NO_MODULE)
  58. else(licensecc_FIND_COMPONENTS)
  59. find_package(licensecc PATHS ${CMAKE_BINARY_DIR} ${CMAKE_INSTALL_PREFIX} QUIET NO_MODULE)
  60. endif(licensecc_FIND_COMPONENTS)
  61. IF(NOT licensecc_FOUND)
  62. find_package(Git QUIET)
  63. if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
  64. # Update submodules as needed
  65. option(GIT_SUBMODULE "Check submodules during build" ON)
  66. if(GIT_SUBMODULE)
  67. message(STATUS "Submodule update")
  68. execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --checkout --remote
  69. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  70. RESULT_VARIABLE GIT_SUBMOD_RESULT)
  71. if(NOT GIT_SUBMOD_RESULT EQUAL "0")
  72. set(failure_messge "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
  73. endif()
  74. endif()
  75. endif()
  76. if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/licensecc/CMakeLists.txt")
  77. set(failure_messge "All the options to find licensecc library failed. And i can't compile one from source GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
  78. else()
  79. if(licensecc_FIND_COMPONENTS)
  80. set(LCC_PROJECT_NAME ${licensecc_FIND_COMPONENTS})
  81. endif(licensecc_FIND_COMPONENTS)
  82. add_subdirectory("${PROJECT_SOURCE_DIR}/extern/licensecc")
  83. set(licensecc_FOUND TRUE)
  84. endif()
  85. ENDIF(NOT licensecc_FOUND)
  86. ENDIF(LICENSECC_LOCATION)
  87. if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  88. set(licensecc_LIB "${LICENSECC_LOCATION}")
  89. get_filename_component(licensecc_LIB "${licensecc_LIB}" PATH)
  90. get_filename_component(licensecc_LIB "${licensecc_LIB}" PATH)
  91. set(licensecc_LIB "${licensecc_LIB}/licensecc/GJDM/licensecc_static.lib")
  92. endif()