76 lines
2.3 KiB
CMake
76 lines
2.3 KiB
CMake
# ==============================================================================
|
|
# Find toml11
|
|
# ==============================================================================
|
|
# This module fetches the toml11 TOML parser library.
|
|
#
|
|
# Targets provided:
|
|
# toml11::toml11 - The toml11 library target
|
|
#
|
|
# Variables set:
|
|
# toml11_FOUND - TRUE if toml11 is available
|
|
# toml11_LIBRARIES - The toml11 library target (toml11::toml11)
|
|
# toml11_INCLUDE_DIR - Include directories for toml11
|
|
# toml11_VERSION - Version of toml11 (if available)
|
|
# ==============================================================================
|
|
|
|
if (DEFINED _FINDTOML11_INCLUDED)
|
|
return()
|
|
endif()
|
|
set(_FINDTOML11_INCLUDED TRUE)
|
|
|
|
# Use the version passed to find_package(), or default to 4.4.0
|
|
if (DEFINED toml11_FIND_VERSION AND NOT toml11_FIND_VERSION STREQUAL "")
|
|
set(TOML11_VERSION "${toml11_FIND_VERSION}")
|
|
else()
|
|
set(TOML11_VERSION "4.4.0")
|
|
endif()
|
|
|
|
message(STATUS "Fetching toml11 ${TOML11_VERSION}")
|
|
|
|
include(FetchContent)
|
|
|
|
find_program(GIT_EXECUTABLE git)
|
|
if (GIT_EXECUTABLE)
|
|
set(TOML11_FETCH_METHOD "GIT")
|
|
else()
|
|
set(TOML11_FETCH_METHOD "ZIP")
|
|
endif()
|
|
|
|
if (TOML11_FETCH_METHOD STREQUAL "GIT")
|
|
FetchContent_Declare(
|
|
toml11
|
|
GIT_REPOSITORY https://github.com/ToruNiina/toml11.git
|
|
GIT_TAG v${TOML11_VERSION}
|
|
)
|
|
else()
|
|
FetchContent_Declare(
|
|
toml11
|
|
URL https://github.com/ToruNiina/toml11/archive/refs/tags/v${TOML11_VERSION}.zip
|
|
)
|
|
endif()
|
|
|
|
FetchContent_MakeAvailable(toml11)
|
|
|
|
if (NOT TARGET toml11::toml11)
|
|
if (TARGET toml11)
|
|
add_library(toml11::toml11 ALIAS toml11)
|
|
else()
|
|
message(FATAL_ERROR "Could not fetch toml11; no target toml11 or toml11::toml11 available")
|
|
endif()
|
|
endif()
|
|
|
|
set(toml11_FOUND TRUE)
|
|
set(toml11_LIBRARIES toml11::toml11)
|
|
set(toml11_VERSION "${TOML11_VERSION}")
|
|
get_target_property(_toml11_inc toml11::toml11 INTERFACE_INCLUDE_DIRECTORIES)
|
|
set(toml11_INCLUDE_DIR "${_toml11_inc}")
|
|
|
|
# Mark toml11 includes as SYSTEM to suppress warnings from its headers
|
|
if (_toml11_inc AND TARGET toml11)
|
|
set_target_properties(toml11 PROPERTIES
|
|
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_toml11_inc}"
|
|
)
|
|
endif()
|
|
|
|
set(TOML11_LICENSE_FILE "${toml11_SOURCE_DIR}/LICENSE" CACHE FILEPATH "Path to toml11 license file")
|