Mise à jour de 'cmake/FindUstl.cmake'

This commit is contained in:
Sylvain PILLOT 2022-03-01 22:19:51 +01:00
parent b492b4e613
commit 841335648f
1 changed files with 6 additions and 27 deletions

View File

@ -1,50 +1,29 @@
find_package(Gint 2.1 REQUIRED)
# Find libexample.a; if we had platform-specific versions we could look for
# libexample-${FXSDK_PLATFORM}.a instead.
execute_process(
COMMAND ${CMAKE_C_COMPILER} -print-file-name=libustl.a
OUTPUT_VARIABLE EX_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
# EX_PATH is now the full path if libustl.a exists, "libustl.a" otherwise
if(NOT "${EX_PATH}" STREQUAL "libustl.a")
# Find the version.h header
execute_process(
COMMAND ${CMAKE_C_COMPILER} -print-file-name=include/ustl/config.h
COMMAND ${CMAKE_C_COMPILER} -print-file-name=include/config.h
OUTPUT_VARIABLE EX_CONFIG OUTPUT_STRIP_TRAILING_WHITESPACE)
# Extract version information from the config.h header. This command prints
# the version on the line matching the regex and deletes every other line.
execute_process(
COMMAND sed -E "s/#define.*EX_VERSION\\s+\"(\\S+)\"$/\\1/p; d" ${EX_CONFIG}
OUTPUT_VARIABLE EX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# The commands above seem common for gint libraries, so the fxSDK provides a
# helper function to get that directly. We simply provide the archive name,
# header file name, macro name, and names for output variables.
# include(FindSimpleLibrary)
# find_simple_library(libexample.a include/example/config.h "EX_VERSION"
# PATH_VAR EX_PATH VERSION_VAR EX_VERSION)
# This CMake utility will handle the version comparisons and other checks. We
# just specify:
# -> Some variables that are defined only if the library is found (so if
# they're undefined, CMake will conclude libexample was not found)
# -> The version, so CMake can compare with the user's requested one
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibUstl
REQUIRED_VARS EX_CONFIG EX_VERSION
VERSION_VAR EX_VERSION)
# We now have a LibExample_FOUND variable, let's create the target that users
# can link against with target_link_libraries()
if(LibUstl_FOUND)
# This is an imported target, we don't build it, we just claim it's here
add_library(LibUstl::LibUstl UNKNOWN IMPORTED)
# Here we declare the compiler and linker flags that every user of LibExample
# needs to use.
set_target_properties(LibUstl::LibUstl PROPERTIES
# If we specify where the library comes from, CMake will watch that file
# and relink any user application when the library is updated!
IMPORTED_LOCATION "${EX_PATH}"
INTERFACE_COMPILE_OPTIONS -std=c++11 -fno-rtti -fno-use-cxa-atexit
# Linking options
INTERFACE_LINK_OPTIONS -lustl
# Dependencies (for order on the command-line)
IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint)
endif()