diff --git a/find-modules/Findeditorconfig.cmake b/find-modules/Findeditorconfig.cmake --- a/find-modules/Findeditorconfig.cmake +++ b/find-modules/Findeditorconfig.cmake @@ -0,0 +1,88 @@ +#.rst: +# Findeditorconfig +# ---------------- +# +# Try to find editorconfig-core-c on a Unix system. +# +# This will define the following variables: +# +# ``EDITORCONFIG_FOUND`` +# True if the requested version of editorconfig-core-c is available +# ``EDITORCONFIG_VERSION`` +# The version of installed editorconfig-core-c shared library +# ``EDITORCONFIG_LIBRARIES`` +# This can be passed to target_link_libraries() instead of ``editorconfig`` +# target +# ``EDITORCONFIG_INCLUDE_DIRS`` +# This should be passed to target_include_directories() if the target is not +# used for linking +# +# Since 5.32 + +#============================================================================= +# Copyright (c) 2016 João Valverde +# Copyright (c) 2017 Grzegorz Szymaszek +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +find_path(EDITORCONFIG_INCLUDE_DIR editorconfig/editorconfig.h) + +find_library(EDITORCONFIG_LIBRARY editorconfig) + +# find EditorConfig library file (not link) that has full version number in +# its name +execute_process(COMMAND find /usr/lib/ -type f -name "libeditorconfig.so.*" + OUTPUT_VARIABLE EDITORCONFIG_INSTALLED_LIBRARY +) + +# extract that version number from full file path +string(REGEX REPLACE "^.*libeditorconfig\\.so\\.([0-9]+\\.[0-9]+\\.[0-9]+).*$" "\\1" EDITORCONFIG_VERSION "${EDITORCONFIG_INSTALLED_LIBRARY}") + +unset(EDITORCONFIG_INSTALLED_LIBRARY) + +# handle the QUIETLY and REQUIRED arguments and set EDITORCONFIG_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(editorconfig + FOUND_VAR + EDITORCONFIG_FOUND + REQUIRED_VARS + EDITORCONFIG_LIBRARY + EDITORCONFIG_INCLUDE_DIR + VERSION_VAR + EDITORCONFIG_VERSION +) + +mark_as_advanced(EDITORCONFIG_INCLUDE_DIR EDITORCONFIG_LIBRARY) + +set(EDITORCONFIG_LIBRARIES ${EDITORCONFIG_LIBRARY}) +set(EDITORCONFIG_INCLUDE_DIRS ${EDITORCONFIG_INCLUDE_DIR}) + +include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake) + +include(FeatureSummary) +set_package_properties(editorconfig PROPERTIES + URL "https://github.com/editorconfig/editorconfig-core-c" + DESCRIPTION "EditorConfig core library written in C." +)