From 118a0baf279f841fed3b45666bb56e816ba3d858 Mon Sep 17 00:00:00 2001
From: Joscha Schmiedt <joscha@schmiedt.dev>
Date: Tue, 4 Jun 2024 21:39:52 +0200
Subject: [PATCH] Re-enabling install in CMakeLists.txt

- Was temporarily disabled for conan 2
---
 CMakeLists.txt | 301 ++++++++++++++++++++++++-------------------------
 1 file changed, 145 insertions(+), 156 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 829ce5c..24bef4e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -162,97 +162,86 @@ find_package(protobuf)
 find_package(Boost)
 find_package(GTest)
 
-add_library(caosdb
-         SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED})
-set(LIBCAOSDB caosdb)
-
-target_link_libraries(caosdb grpc::grpc protobuf::protobuf boost::boost gtest::gtest)
-target_link_libraries(caosdb grpc::grpc protobuf::protobuf)
+# libcaosdb
+if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
+  add_library(caosdb_grpc SHARED ${GRPC_GENERATED})
+  add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC})
+    target_link_libraries(caosdb caosdb_grpc 
+        grpc::grpc protobuf::protobuf boost::boost gtest::gtest)
+    set(LIBCAOSDB caosdb caosdb_grpc)
+
+    target_include_directories(caosdb_grpc PUBLIC
+        $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
+        $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
+
+        $<INSTALL_INTERFACE:include>
+    )
+    target_include_directories(caosdb_grpc SYSTEM PUBLIC
+        ${CONAN_INCLUDE_DIRS}
+    )
+else()
+    add_library(caosdb
+        SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED})
+    set(LIBCAOSDB caosdb)
+endif()
+target_link_libraries(caosdb
+    grpc::grpc protobuf::protobuf boost::boost gtest::gtest
+    stdc++fs
+)
 target_include_directories(caosdb PUBLIC
-     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
-     $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
-     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/src>
-     $<INSTALL_INTERFACE:include>
- )
-# if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
-#   add_library(caosdb_grpc SHARED ${GRPC_GENERATED})
-#   add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC})
-#     target_link_libraries(caosdb caosdb_grpc)
-#     set(LIBCAOSDB caosdb caosdb_grpc)
-
-#     target_include_directories(caosdb_grpc PUBLIC
-#         $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
-#         $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
-
-#         $<INSTALL_INTERFACE:include>
-#     )
-#     target_include_directories(caosdb_grpc SYSTEM PUBLIC
-#         ${CONAN_INCLUDE_DIRS}
-#     )
-# else()
-#     add_library(caosdb
-#         SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED})
-#     set(LIBCAOSDB caosdb)
-# endif()
-# target_link_libraries(caosdb
-#     ${CONAN_LIBS}
-#     stdc++fs
-# )
-# target_include_directories(caosdb PUBLIC
-#     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
-#     $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
-#     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/src>
-#     $<INSTALL_INTERFACE:include>
-# )
-# target_include_directories(caosdb SYSTEM PUBLIC
-#     ${CONAN_INCLUDE_DIRS}
-# )
-
-# add_library(ccaosdb SHARED src/ccaosdb.cpp)
-# target_link_libraries(ccaosdb
-#     ${CONAN_LIBS}
-#     ${LIBCAOSDB}
-#     stdc++fs
-# )
-# target_include_directories(ccaosdb PUBLIC
-#     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
-#     $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
-#     $<INSTALL_INTERFACE:include>
-# )
-# target_include_directories(ccaosdb SYSTEM PUBLIC
-#     ${CONAN_INCLUDE_DIRS}
-# )
-
-
-# add_executable(ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c)
-# target_include_directories(ccaosdbcli PUBLIC
-#     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
-#     $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
-#     $<INSTALL_INTERFACE:include>
-# )
-# target_include_directories(ccaosdbcli SYSTEM PUBLIC
-#     ${CONAN_INCLUDE_DIRS}
-# )
-
-# target_link_libraries(ccaosdbcli
-#     ${CONAN_LIBS}
-#     ${LIBCAOSDB}
-#     ccaosdb
-# )
-
-# add_executable(cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp)
-# target_include_directories(cxxcaosdbcli PUBLIC
-#     $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
-#     $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
-#     $<INSTALL_INTERFACE:include>
-# )
-# target_include_directories(cxxcaosdbcli SYSTEM PUBLIC
-#     ${CONAN_INCLUDE_DIRS}
-# )
-# target_link_libraries(cxxcaosdbcli
-#     ${LIBCAOSDB}
-#     ${CONAN_LIBS}
-# )
+    $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
+    $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
+    $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/src>
+    $<INSTALL_INTERFACE:include>
+)
+target_include_directories(caosdb SYSTEM PUBLIC
+    ${CONAN_INCLUDE_DIRS}
+)
+
+# libccaosdb
+add_library(ccaosdb SHARED src/ccaosdb.cpp)
+target_link_libraries(ccaosdb
+    grpc::grpc protobuf::protobuf boost::boost gtest::gtest
+    ${LIBCAOSDB}
+    stdc++fs
+)
+target_include_directories(ccaosdb PUBLIC
+    $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
+    $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
+    $<INSTALL_INTERFACE:include>
+)
+
+
+# ccaosdbcli
+add_executable(ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c)
+target_include_directories(ccaosdbcli PUBLIC
+    $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
+    $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
+    $<INSTALL_INTERFACE:include>
+)
+target_include_directories(ccaosdbcli SYSTEM PUBLIC
+    ${CONAN_INCLUDE_DIRS}
+)
+
+target_link_libraries(ccaosdbcli
+    grpc::grpc protobuf::protobuf boost::boost gtest::gtest
+    ${LIBCAOSDB}
+    ccaosdb
+)
+
+add_executable(cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp)
+target_include_directories(cxxcaosdbcli PUBLIC
+    $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
+    $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
+    $<INSTALL_INTERFACE:include>
+)
+target_include_directories(cxxcaosdbcli SYSTEM PUBLIC
+    ${CONAN_INCLUDE_DIRS}
+)
+target_link_libraries(cxxcaosdbcli
+    ${LIBCAOSDB}
+    grpc::grpc protobuf::protobuf boost::boost gtest::gtest
+)
 
 
 
@@ -387,72 +376,72 @@ endif()
 # ############ INSTALLATION #####################
 # ###############################################
 
-# set(libcaosdb_INCLUDE_DEST "include/caosdb")
-# set(libcaosdb_LIB_DEST "lib")
-
-# set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/")
-# install(
-#     # targets to install
-#     TARGETS ${LIBCAOSDB} ccaosdb
-#     # name of the CMake "export group" containing the targets we want to install
-#     EXPORT caosdbTargets
-#     # 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}
-# )
-
-
-# set(libcaosdb_CMAKE_DEST "${libcaosdb_LIB_DEST}/cmake/caosdb")
-# install(
-#     # The export we want to save (matches name defined above containing the
-#     # install targets)
-#     EXPORT caosdbTargets
-#     # CMake file in which to store the export's information
-#     FILE  caosdbTargets.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_CMAKE_DEST}
-# )
-
-# install(FILES ${libcaosdb_INCL} ${PROJECT_SOURCE_DIR}/include/ccaosdb.h DESTINATION ${libcaosdb_INCLUDE_DEST})
-# foreach(i RANGE "${len_proto_files}")
-#     list(GET PROTO_FILES ${i} next_proto_file)
-
-#     # strip away the prefix path and the ".proto" suffix
-#     string(REPLACE
-#         "${PROJECT_SOURCE_DIR}/proto/proto/caosdb/"
-#         ""
-#         next_proto_module
-#         "${next_proto_file}")
-#     string(REPLACE
-#         "/main.proto"
-#         ""
-#         next_proto_module
-#         "${next_proto_module}")
-#     set(next_proto_hdr
-#         "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.pb.h")
-#     set(next_grpc_hdr
-#         "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.grpc.pb.h")
-#     install(FILES ${next_proto_hdr} ${next_grpc_hdr} DESTINATION
-#         ${libcaosdb_INCLUDE_DEST}/${next_proto_module})
-# endforeach()
-
-# install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfig.cmake
-#     DESTINATION ${libcaosdb_CMAKE_DEST})
-
-# #set_property(TARGET caosdb PROPERTY VERSION ${libcaosdb_VERSION})
-# include(CMakePackageConfigHelpers)
-# write_basic_package_version_file(
-#     "${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake"
-#   VERSION ${libcaosdb_VERSION}
-#   COMPATIBILITY AnyNewerVersion
-# )
-# install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake
-#     DESTINATION ${libcaosdb_CMAKE_DEST})
+set(libcaosdb_INCLUDE_DEST "include/caosdb")
+set(libcaosdb_LIB_DEST "lib")
+
+set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/")
+install(
+    # targets to install
+    TARGETS ${LIBCAOSDB} ccaosdb
+    # name of the CMake "export group" containing the targets we want to install
+    EXPORT caosdbTargets
+    # 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}
+)
+
+
+set(libcaosdb_CMAKE_DEST "${libcaosdb_LIB_DEST}/cmake/caosdb")
+install(
+    # The export we want to save (matches name defined above containing the
+    # install targets)
+    EXPORT caosdbTargets
+    # CMake file in which to store the export's information
+    FILE  caosdbTargets.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_CMAKE_DEST}
+)
+
+install(FILES ${libcaosdb_INCL} ${PROJECT_SOURCE_DIR}/include/ccaosdb.h DESTINATION ${libcaosdb_INCLUDE_DEST})
+foreach(i RANGE "${len_proto_files}")
+    list(GET PROTO_FILES ${i} next_proto_file)
+
+    # strip away the prefix path and the ".proto" suffix
+    string(REPLACE
+        "${PROJECT_SOURCE_DIR}/proto/proto/caosdb/"
+        ""
+        next_proto_module
+        "${next_proto_file}")
+    string(REPLACE
+        "/main.proto"
+        ""
+        next_proto_module
+        "${next_proto_module}")
+    set(next_proto_hdr
+        "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.pb.h")
+    set(next_grpc_hdr
+        "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.grpc.pb.h")
+    install(FILES ${next_proto_hdr} ${next_grpc_hdr} DESTINATION
+        ${libcaosdb_INCLUDE_DEST}/${next_proto_module})
+endforeach()
+
+install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfig.cmake
+    DESTINATION ${libcaosdb_CMAKE_DEST})
+
+#set_property(TARGET caosdb PROPERTY VERSION ${libcaosdb_VERSION})
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+    "${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake"
+  VERSION ${libcaosdb_VERSION}
+  COMPATIBILITY AnyNewerVersion
+)
+install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake
+    DESTINATION ${libcaosdb_CMAKE_DEST})
 
 #######################################################
 ### code formatting with clang-format
-- 
GitLab