Skip to content
Snippets Groups Projects
Select Git revision
  • 4c414e665d89409a1dd539ed232d40b3da361dd1
  • 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 4.79 KiB
    cmake_minimum_required(VERSION 3.13)
    
    set(libcaosdb_VERSION 0.0.1)
    
    project(libcaosdb
        VERSION ${libcaosdb_VERSION}
        DESCRIPTION "Plain C client libraries for CaosDB"
        LANGUAGES C)
    
    set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
    set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
    
    add_subdirectory(src)
    add_subdirectory(include)
    add_subdirectory(doc)
    
    add_library(libcaosdb STATIC ${libcaosdb_INCL} ${libcaosdb_SRC})
    add_executable(caosdbcli src/caosdbcli.c)
    target_link_libraries(caosdbcli libcaosdb)
    
    if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
        target_link_libraries(libcaosdb gcov)
        enable_testing()
        add_subdirectory(test)
        append_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(libcaosdb PUBLIC include/)
    # PUBLIC means that other libraries including libcaosdb 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(libcaosdb 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> 
       )
    
    
    # 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 libcaosdb
        # 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(libcaosdb)
    # find_package(libcaosdb) will look for libcaosdb-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 libcaosdb::libcaosdb)
        NAMESPACE libcaosdb::
        # 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})