diff --git a/cmake/modules/FindLibAStyle.cmake b/cmake/modules/FindLibAStyle.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/FindLibAStyle.cmake @@ -0,0 +1,44 @@ +# - Find LibAStyle +# Find the Artistic Style library. +# +# This module defines +# LibAStyle_FOUND - whether the astyle library was found +# LibAStyle_LIBRARIES - the astyle library +# LibAStyle_INCLUDE_DIR - the include path of the astyle library + +#============================================================================= +# Copyright 2018 Pino Toscano +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + +find_library(LibAStyle_LIBRARIES + NAMES astyle +) + +find_path(LibAStyle_INCLUDE_DIR + NAMES astyle.h +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LibAStyle + FOUND_VAR LibAStyle_FOUND + REQUIRED_VARS LibAStyle_LIBRARIES LibAStyle_INCLUDE_DIR +) + +mark_as_advanced(LibAStyle_INCLUDE_DIR LibAStyle_LIBRARIES) + +if(LibAStyle_FOUND) + add_library(astylelib UNKNOWN IMPORTED) + set_target_properties(astylelib PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${LibAStyle_INCLUDE_DIR} + IMPORTED_LOCATION ${LibAStyle_LIBRARIES} + # astyle is built without RTTI + INTERFACE_COMPILE_OPTIONS "-fno-rtti" + ) +endif() diff --git a/plugins/astyle/CMakeLists.txt b/plugins/astyle/CMakeLists.txt --- a/plugins/astyle/CMakeLists.txt +++ b/plugins/astyle/CMakeLists.txt @@ -1,5 +1,12 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdevastyle\") +find_package(LibAStyle) +set_package_properties(LibAStyle PROPERTIES + DESCRIPTION "Artistic Style library" + PURPOSE "External library for the astyle plugin" + URL "http://astyle.sourceforge.net/" + TYPE RECOMMENDED) + declare_qt_logging_category(kdevastyle_LOG_SRCS TYPE PLUGIN IDENTIFIER KDEV_ASTYLE @@ -30,7 +37,9 @@ KDev::Interfaces KDev::Util) -add_subdirectory(3rdparty/libastyle) +if(NOT LibAStyle_FOUND) + add_subdirectory(3rdparty/libastyle) +endif() if(BUILD_TESTING) add_subdirectory(tests) endif()