Warning, /libraries/libqgit2/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 #############################################################################
0002 # This file is part of the libqgit2 library
0003 # Copyright (C) 2011 Laszlo Papp
0004 #
0005 # This program is free software; you can redistribute it and/or modify
0006 # it under the terms of the GNU General Public License as published by
0007 # the Free Software Foundation; either version 2 of the License, or
0008 # (at your option) any later version.
0009 #
0010 # This program is distributed in the hope that it will be useful,
0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 # GNU General Public License for more details.
0014 #
0015 # You should have received a copy of the GNU General Public License along
0016 # with this program; if not, write to the Free Software Foundation, Inc.,
0017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0018 
0019 # CMake build script for the libqgit2 project
0020 #
0021 # Building (out of source build):
0022 # > mkdir build && cd build
0023 # > cmake .. [-DSETTINGS=VALUE]
0024 # > cmake --build .
0025 #
0026 # Testing:
0027 # > ctest -V
0028 #
0029 # Install:
0030 # > cmake --build . --target install
0031 
0032 cmake_minimum_required(VERSION 3.16)
0033 project(libqgit2)
0034 
0035 set(CMAKE_CXX_STANDARD 11)
0036 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
0037 
0038 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
0039 
0040 set(EXECUTABLE_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/bin)
0041 set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
0042 if(WIN32) # Dll's into bin
0043     set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
0044 endif()
0045 
0046 find_package(Qt5 5.14 REQUIRED Core Network)
0047 
0048 find_package(PkgConfig REQUIRED)
0049 pkg_check_modules(LIBGIT2 "libgit2>=1.0" REQUIRED IMPORTED_TARGET)
0050 
0051 file(STRINGS "qgit2.h" QGIT2_HEADER REGEX "^#define LIBQGIT2_VERSION \"[^\"]*\"$")
0052 string(REGEX REPLACE "^.*LIBQGIT2_VERSION \"([0-9]+).*$" "\\1" LIBQGIT2_VERSION_MAJOR "${QGIT2_HEADER}")
0053 string(REGEX REPLACE "^.*LIBQGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBQGIT2_VERSION_MINOR  "${QGIT2_HEADER}")
0054 string(REGEX REPLACE "^.*LIBQGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBQGIT2_VERSION_REV "${QGIT2_HEADER}")
0055 set(LIBQGIT2_VERSION_STRING "${LIBQGIT2_VERSION_MAJOR}.${LIBQGIT2_VERSION_MINOR}.${LIBQGIT2_VERSION_REV}")
0056 
0057 file(STRINGS "qgit2.h" QGIT2_HEADER_SOVERSION REGEX "^#define LIBQGIT2_SOVERSION [0-9]+$")
0058 string(REGEX REPLACE "^.*LIBQGIT2_SOVERSION ([0-9]+)$" "\\1" LIBQGIT2_SOVERSION "${QGIT2_HEADER_SOVERSION}")
0059 
0060 # Installation paths
0061 set(INSTALL_BIN bin CACHE PATH "Where to install binaries to.")
0062 set(INSTALL_LIB lib CACHE PATH "Where to install libraries to.")
0063 set(INSTALL_INC include CACHE PATH "Where to install headers to.")
0064 
0065 # Build options
0066 option(BUILD_TESTS "Build Tests" ON)
0067 
0068 # Build Release by default
0069 if(NOT CMAKE_BUILD_TYPE)
0070     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
0071 endif()
0072 
0073 option(LIBGIT2_TESTS "Build libgit2 tests" OFF)
0074 
0075 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
0076 include_directories(${CMAKE_BINARY_DIR})
0077 
0078 # Collect files
0079 file(GLOB_RECURSE SRC src/*.cpp)
0080 file(GLOB QGIT2_HEADERS src/qgit*.h src/libqgit2_config.h)
0081 file(GLOB_RECURSE QGIT2_PRIVATE_HEADERS src/*.h)
0082 list(REMOVE_ITEM QGIT2_PRIVATE_HEADERS ${QGIT2_HEADERS})
0083 
0084 message(STATUS)
0085 message(STATUS "========== LIBQGIT2 Build Information ==========")
0086 message(STATUS "Build Version: ${LIBQGIT2_VERSION_STRING}")
0087 message(STATUS "Install Prefix: ${CMAKE_INSTALL_PREFIX}")
0088 message(STATUS)
0089 message(STATUS "To change any of these options, override them using -D{OPTION_NAME} on the commandline.")
0090 message(STATUS "To build and install LIBQGIT2, run \"make\" and \"make install\"")
0091 message(STATUS)
0092 
0093 # Compile and link libqgit2
0094 add_definitions(-DMAKE_LIBQGIT2_LIB)
0095 add_library(qgit2 ${SRC} ${QGIT2_HEADERS} ${QGIT2_PRIVATE_HEADERS})
0096 target_link_libraries(qgit2 PkgConfig::LIBGIT2 Qt5::Core Qt5::Network)
0097 set_target_properties(qgit2 PROPERTIES VERSION ${LIBQGIT2_VERSION_STRING})
0098 set_target_properties(qgit2 PROPERTIES SOVERSION ${LIBQGIT2_SOVERSION})
0099 set_target_properties(qgit2 PROPERTIES AUTOMOC ON)
0100 
0101 # Install
0102 install(TARGETS qgit2
0103     RUNTIME DESTINATION ${INSTALL_BIN}
0104     LIBRARY DESTINATION ${INSTALL_LIB}
0105     ARCHIVE DESTINATION ${INSTALL_LIB}
0106 )
0107 
0108 install(FILES ${QGIT2_HEADERS} DESTINATION ${INSTALL_INC}/qgit2 COMPONENT Devel)
0109 install(FILES ${CMAKE_BINARY_DIR}/libqgit2_export.h DESTINATION ${INSTALL_INC}/qgit2 COMPONENT Devel)
0110 install(FILES qgit2.h DESTINATION ${INSTALL_INC} COMPONENT Devel)
0111 
0112 #Packaging options
0113 set(CPACK_GENERATOR "RPM;TGZ")
0114 set(CPACK_PACKAGE_NAME "LIBQGIT2")
0115 set(CPACK_PACKAGE_FILE_NAME "LIBQGIT2-${LIBQGIT2_VERSION_STRING}")
0116 set(CPACK_PACKAGE_VERSION "${LIBQGIT2_VERSION_MAJOR}.${LIBQGIT2_VERSION_MINOR}.${LIBQGIT2_VERSION_REV}")
0117 set(CPACK_PACKAGE_CONTACT "Laszlo Papp <djszapi@archlinux.us>")
0118 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "libgit2 bindings for Qt")
0119 include(InstallRequiredSystemLibraries)
0120 include(CPack)
0121 include(GenerateExportHeader)
0122 
0123 generate_export_header(qgit2 BASE_NAME LIBQGIT2)
0124 
0125 if(BUILD_TESTS)
0126     enable_testing()
0127     add_subdirectory(tests)
0128 endif()
0129 
0130 # Doxygen
0131 find_package(Doxygen)
0132 if(DOXYGEN_FOUND)
0133     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
0134     add_custom_target(doc
0135         ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
0136         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
0137         COMMENT "Generating API documentation with Doxygen" VERBATIM)
0138 endif(DOXYGEN_FOUND)