From 1d84a44983eaf138673ecd66f4524acb066db5c6 Mon Sep 17 00:00:00 2001
From: Joscha Schmiedt <joscha@schmiedt.dev>
Date: Tue, 13 Aug 2024 21:54:33 +0200
Subject: [PATCH] Improve boost linking

- Only use required components of boost
- Link automatically to ${Boost_LIBRARIES}
---
 CMakeLists.txt | 41 ++++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 867b117..421e9f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,9 @@
 # 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>
+# Copyright (C) 2021 Joscha Schmiedt <joscha@schmiedt.dev>
+# Copyright (C) 2021-2024 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
@@ -51,24 +53,8 @@ IF (BUILD_ACM)
     add_compile_definitions("BUILD_ACM")
 ENDIF()
 
-###########################################
-### DEPENDENCY MANAGEMENT with CONAN
-###########################################
 message(STATUS "Build directory ${CMAKE_BINARY_DIR}")
 
-# TODO: Is this still necessary?
-# # fix grpc - remove unsecure (no-op ssl implementations)
-# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS_GRPC
-#     "${CONAN_LIBS_GRPC}")
-# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS_GRPC
-#     "${CONAN_PKG_LIBS_GRPC}")
-# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS
-#     "${CONAN_LIBS}")
-# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS
-#     "${CONAN_PKG_LIBS}")
-
-# message(STATUS "CONAN_LIBS: ${CONAN_LIBS}")
-
 ###########################################
 ### GENERAL SETUP of SOURCES
 ###########################################
@@ -81,7 +67,7 @@ add_subdirectory(doc)
 ### CODE GENERATION (WITH GRPC)
 ####################################################################
 
-find_package(Protobuf CONFIG REQUIRED)
+find_package(protobuf CONFIG REQUIRED)
 
 # Protobuf/Grpc source files
 set(PROTO_FILES
@@ -161,7 +147,12 @@ message(DEBUG "GRPC_GENERATED: ${GRPC_GENERATED}")
 ###############################################################################
 
 find_package(gRPC CONFIG REQUIRED)
-find_package(Boost REQUIRED)
+find_package(Boost COMPONENTS json REQUIRED)
+find_package(Boost COMPONENTS filesystem REQUIRED)
+find_package(Boost COMPONENTS log REQUIRED)
+find_package(Boost COMPONENTS thread REQUIRED)
+find_package(Boost COMPONENTS system REQUIRED)
+find_package(Boost COMPONENTS beast REQUIRED)
 find_package(GTest REQUIRED)
 
 # print include directories for debugging
@@ -178,7 +169,7 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
 
     add_library(caosdb_grpc SHARED ${GRPC_GENERATED})
     target_link_libraries(caosdb_grpc 
-        grpc::grpc protobuf::protobuf boost::boost
+        gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES}
     )
     target_include_directories(caosdb_grpc PUBLIC
         $<BUILD_INTERFACE:${PROJECT_INCLUDE_DIR}>
@@ -189,7 +180,7 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
    add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC})
 
    target_link_libraries(caosdb 
-        caosdb_grpc grpc::grpc protobuf::protobuf boost::boost
+        caosdb_grpc gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES}
     )
 
     set(LIBCAOSDB caosdb caosdb_grpc)
@@ -197,7 +188,7 @@ else()
     add_library(caosdb
         SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED})
      target_link_libraries(caosdb
-        grpc::grpc protobuf::protobuf boost::boost
+        gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES}
         stdc++fs
     )
      set(LIBCAOSDB caosdb)
@@ -218,7 +209,7 @@ target_include_directories(caosdb PUBLIC
 # ----------
 add_library(ccaosdb SHARED src/ccaosdb.cpp)
 target_link_libraries(ccaosdb
-    grpc::grpc protobuf::protobuf boost::boost
+    gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES}
     ${LIBCAOSDB}
     stdc++fs
 )
@@ -242,7 +233,7 @@ target_include_directories(ccaosdbcli SYSTEM PUBLIC
 )
 
 target_link_libraries(ccaosdbcli
-    grpc::grpc protobuf::protobuf boost::boost
+    gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES}
     ${LIBCAOSDB}
     ccaosdb
 )
@@ -260,7 +251,7 @@ target_include_directories(cxxcaosdbcli SYSTEM PUBLIC
 )
 target_link_libraries(cxxcaosdbcli
     ${LIBCAOSDB}
-    grpc::grpc protobuf::protobuf boost::boost
+    gRPC::grpc protobuf::libprotobuf ${Boost_LIBRARIES}
 )
 
 
-- 
GitLab