Skip to content
Snippets Groups Projects
Select Git revision
  • 924a62a63a8206bd3acfd17586b7be5c0470cbfe
  • main default protected
  • f-sss4grpc
  • dev
  • 108-implement-rpc-call-for-server-side-scripting
  • f-windows-conan-create
  • f-to-string
  • f-update-requirements
  • f-related-projects
  • f-role
  • f-remote-path
  • f-rel-path
  • f-consol-message
  • v0.3.0
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.2
  • v0.1.1
  • v0.1
  • v0.0.19
  • v0.0.18
  • v0.0.16
  • v0.0.15
  • v0.0.10
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
33 results

CMakeLists.txt

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CMakeLists.txt 8.49 KiB
    #
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
    # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <https://www.gnu.org/licenses/>.
    #
    
    cmake_minimum_required(VERSION 3.14)
    
    set(libcaosdb_VERSION 0.0.1)
    
    project(libcaosdb
        VERSION ${libcaosdb_VERSION}
        DESCRIPTION "C++ client libraries for CaosDB"
        LANGUAGES CXX)
    
    # override options with variables (globally)
    # needed for turning off unused code from grpc
    cmake_policy(SET CMP0077 NEW) 
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
    set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
    
    find_program(iwyu NAMES include-what-you-use iwyu PATHS ${CMAKE_SOURCE_DIR}/tools/include-what-you-use/${iwyu_os}/bin)
    if(NOT iwyu)
        message(STATUS "include-what-you-use: Not found")
    else()
        message(STATUS "include-what-you-use: ${iwyu}")
        set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu})
    endif()
    
    find_program(clang_tidy NAMES clang-tidy clang-tidy-11)
    if(NOT clang_tidy)
        message(STATUS "clang-tidy: Not found")
    else()
        message(STATUS "clang-tidy: ${clang_tidy}")
        set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" "--header-filter=connection.h"
            "--checks=*,-fuchsia-*,-llvm-include-order,-llvmlibc-*"
            "--warnings-as-errors=*")
    endif()
    
    add_subdirectory(src)
    add_subdirectory(include)
    add_subdirectory(doc)
    
    add_library(caosdb STATIC ${libcaosdb_INCL} ${libcaosdb_SRC})
    set_target_properties(caosdb PROPERTIES
        CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}"
        CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_CLANG_TIDY}"
        )
    add_executable(caosdbcli src/caosdbcli.cpp)
    set_target_properties(caosdbcli PROPERTIES
        CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}"
        CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_CLANG_TIDY}"
        )
    target_link_libraries(caosdbcli caosdb)
    
    if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
        # supress warnings during build of gtest
        cmake_policy(SET CMP0054 NEW)
        target_link_libraries(caosdb gcov)
        enable_testing()
        add_subdirectory(test)
        set_target_properties(caosdb PROPERTIES
            COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
    
    endif()
    
    
    # These variables slightly modify the install location to allow for version
    # specific installations.
    set(libcaosdb_INCLUDE_DEST "include/libcaosdb-${libcaosdb_VERSION}")
    set(libcaosdb_LIB_DEST "lib/libcaosdb-${libcaosdb_VERSION}")
    
    
    # generator expressions are needed for the include directories, since
    # installing headers changes the include path specify that libcaosdb requires
    # the files located in the include/ directory at compile time. This would
    # normally look like
    #   target_include_directories(caosdb PUBLIC include/)
    # PUBLIC means that other libraries including caosdb should also include
    # the directory include/.
    # However, there is a catch. If we are installing the project in
    # CMAKE_INSTALL_PREFIX, we can't specify include/ in the build directory: we
    # have copied the contents of include to CMAKE_INSTALL_PREFIX/include and we
    # would like  other projects to include this directory instead of include/.
    # The following CMake command handles this. $<BUILD_INTERFACE:...> and
    # $<INSTALL_INTERFACE:...> are macros whose values change depending on if we
    # are simply building the code or if we are installing it.
    target_include_directories(caosdb PUBLIC
       # headers to include when building from source
       $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
       $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
    
       # headers to include when installing  (implicitly prefixes with ${CMAKE_INSTALL_PREFIX}).
       $<INSTALL_INTERFACE:include> 
       )
    
    
    set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/libcaosdb/")
    # Install libcaosdb in CMAKE_INSTALL_PREFIX (defaults to /usr/local on linux).
    # To change the install location, run
    #   cmake -DCMAKE_INSTALL_PREFIX=<desired-install-path> ..
    
    # install(...) specifies installation rules for the project. It can specify
    # location of installed files on the system, user permissions, build
    # configurations, etc. Here, we are only copying files.
    # install(TARGETS ...) specifies rules for installing targets.
    # Here, we are taking a target or list of targets (libcosdb) and telling
    # CMake the following:
    #   - put shared libraries associated with libcaosdb in ${libcaosdb_LIB_DEST}
    #   - put static libraries associated with libcaosdb in ${libcaosdb_LIB_DEST}
    #   - put include files associated with libcaosdb in ${libcaosdb_INCLUDE_DEST}
    # We also need to specify the export that is associated with libcaosdb; an
    # export is just a list of targets to be installed. So we are associating
    # libcaosdb with libcaosdbTargets.
    install(
        # targets to install
        TARGETS caosdb
        # name of the CMake "export group" containing the targets we want to install
        #EXPORT libcaosdbTargets
        # Dynamic, static library and include destination locations after running
        # "make install"
        LIBRARY DESTINATION ${libcaosdb_LIB_DEST}
        ARCHIVE DESTINATION ${libcaosdb_LIB_DEST}
        #INCLUDES DESTINATION ${libcaosdb_INCLUDE_DEST}
        )
    
    
    # We now need to install the export libcaosdbTargets that we defined above.
    # This is needed in order for another project to import libcaosdb using
    #   find_package(caosdb)
    # find_package(caosdb) will look for caosdb-config.cmake to provide
    # information about the targets contained in the project libcaosdb.
    # Fortunately, this is specified in the export libcaosdbTargets, so we will
    # install this too.
    # install(EXPORT ...) will install the information about an export. Here, we
    # save it to a file {$libcaosdb_LIB_DEST}/libcaosdbTargets.cmake and prepend
    # everything inside libcaosdbTargets  with the namespace libcaosdb::.
    #install(
        ## The export we want to save (matches name defined above containing the
        ## install targets)
        #EXPORT libcaosdbTargets
        ## CMake file in which to store the export's information
        #FILE  libcaosdbTargets.cmake
        ## Namespace prepends all targets in the export (when we import later, we
        ## will use caosdb::caosdb)
        #NAMESPACE caosdb::
        ## where to place the resulting file (here, we're putting it with the library)
        #DESTINATION ${libcaosdb_LIB_DEST}
        #)
    
    ## install(FILES ...) simply puts files in a certain place with certain
    ## properties. We're just copying them to the desired place here.
    install(FILES ${libcaosdb_INC} DESTINATION ${libcaosdb_INCLUDE_DEST})
    
    
    
    ## CODE GENERATION
    option(GRPC_FETCHCONTENT "Fetch and build GRPC from the sources" ON)
    include(FetchGRPC)
    
    #
    # Protobuf/Grpc source files
    #
    set(PROTO_FILES
        ${PROJECT_SOURCE_DIR}/proto/proto/caosdb/info/v1alpha1/main.proto
    )
    
    set(PROTO_PATH ${PROJECT_SOURCE_DIR}/proto/proto)
    
    # Generated sources
    set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.pb.cc")
    set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.pb.h")
    set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.grpc.pb.cc")
    set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.grpc.pb.h")
    add_custom_command(
          OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
          COMMAND ${_PROTOBUF_PROTOC}
          ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/include"
            --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/include"
            -I "${PROTO_PATH}"
            --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
            "${PROTO_FILES}"
          DEPENDS "${PROTO_FILES}")
    
    
    
    # Include generated *.pb.h files
    target_include_directories(caosdb PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include")
    
    # hw_grpc_proto
    add_library(caosdb_info_v1alpha1
      ${hw_grpc_srcs}
      ${hw_grpc_hdrs}
      ${hw_proto_srcs}
      ${hw_proto_hdrs})
    target_link_libraries(caosdb_info_v1alpha1
      ${_REFLECTION}
      ${_GRPC_GRPCPP}
      ${_PROTOBUF_LIBPROTOBUF})
    target_include_directories(caosdb_info_v1alpha1 PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include")
    
    target_link_libraries(caosdb
    caosdb_info_v1alpha1
    ${_REFLECTION}
    ${_GRPC_GRPCPP}
    ${_PROTOBUF_LIBPROTOBUF})