From 04e25bd4a5e744c47af5ae6661d839a5e01d5307 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Fri, 26 Apr 2024 14:07:48 +0000
Subject: [PATCH] cmake: Fixes for online standalone build.

---
 algo/CMakeLists.txt           | 13 +++++++------
 external/InstallFlesnet.cmake |  2 +-
 external/InstallYamlCpp.cmake | 19 ++++++++++---------
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt
index 60d0bd9993..def6ea41ef 100644
--- a/algo/CMakeLists.txt
+++ b/algo/CMakeLists.txt
@@ -1,11 +1,13 @@
 cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
 cmake_policy(VERSION 3.14...3.23)
 
-if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
-  set(CBM_ONLINE_STANDALONE ON)
-  project(CbmOnline)
-else()
-  set(CBM_ONLINE_STANDALONE OFF)
+if (NOT DEFINED CBM_ONLINE_STANDALONE)
+  if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
+    set(CBM_ONLINE_STANDALONE ON)
+    project(CbmOnline)
+  else()
+    set(CBM_ONLINE_STANDALONE OFF)
+  endif()
 endif()
 
 if (CBM_ONLINE_STANDALONE)
@@ -46,7 +48,6 @@ if (CBM_ONLINE_STANDALONE)
   set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
   list(PREPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
   include(CbmMacros) # for 'download_project_if_needed', 'Gen_Exe_Script' macro
-  include(../external/InstallGtest.cmake)
 
   add_subdirectory(../external external)
 endif()
diff --git a/external/InstallFlesnet.cmake b/external/InstallFlesnet.cmake
index 56470c49d7..9b01cafdb3 100644
--- a/external/InstallFlesnet.cmake
+++ b/external/InstallFlesnet.cmake
@@ -7,7 +7,7 @@ set(FLESNET_VERSION cdc7893481aa10d51070d965ae9fc6eebfe91ac2) # 2024-01-23
 
 set(FLESNET_SRC_URL "https://github.com/cbm-fles/flesnet")
 
-set(FLESNET_DESTDIR "${PROJECT_BINARY_DIR}/external/flesnet-prefix")
+set(FLESNET_DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/flesnet-prefix")
 set(FLESNET_BIN_PREFIX "${FLESNET_DESTDIR}/src/flesnet-build")
 
 download_project_if_needed(
diff --git a/external/InstallYamlCpp.cmake b/external/InstallYamlCpp.cmake
index 5666fc175b..fb11163906 100644
--- a/external/InstallYamlCpp.cmake
+++ b/external/InstallYamlCpp.cmake
@@ -1,14 +1,15 @@
 set(YAMLCPP_VERSION 0579ae3d976091d7d664aa9d2527e0d0cff25763) # version 0.7.0
 
 set(YAMLCPP_SRC_URL "https://github.com/jbeder/yaml-cpp")
-set(YAMLCPP_DESTDIR "${CMAKE_BINARY_DIR}/external/YAMLCPP-prefix")
-
-#set(YAMLCPP_BYPRODUCT "${PROJECT_BINARY_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_SHARED_LIBRARY_SUFFIX}")
+set(YAMLCPP_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp")
+set(YAMLCPP_INCLUDE_DIR "${YAMLCPP_SRC_DIR}/include")
+set(YAMLCPP_DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/yaml-cpp-prefix")
+set(YAMLCPP_BYPRODUCT "${YAMLCPP_DESTDIR}/src/yaml-cpp-build/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}")
 
 download_project_if_needed(PROJECT  yaml-cpp
         GIT_REPOSITORY  ${YAMLCPP_SRC_URL}
         GIT_TAG         ${YAMLCPP_VERSION}
-        SOURCE_DIR      ${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp
+        SOURCE_DIR      ${YAMLCPP_SRC_DIR}
         TEST_FILE       CMakeLists.txt
         )
 
@@ -25,7 +26,7 @@ endif()
 
 ExternalProject_Add(
   yaml-cpp
-  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp
+  SOURCE_DIR ${YAMLCPP_SRC_DIR}
   GIT_CONFIG advice.detachedHead=false
   BUILD_IN_SOURCE 0
   LOG_DOWNLOAD 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1
@@ -35,16 +36,16 @@ ExternalProject_Add(
              -DYAML_BUILD_SHARED_LIBS=OFF
              -DCMAKE_POSITION_INDEPENDENT_CODE=ON
   BUILD_COMMAND ${YAMLCPP_BUILD_COMMAND} yaml-cpp
-  BUILD_BYPRODUCTS ${PROJECT_BINARY_DIR}/external/yaml-cpp-prefix/src/yaml-cpp-build/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}
+  BUILD_BYPRODUCTS ${YAMLCPP_BYPRODUCT}
   INSTALL_COMMAND ""
 )
 
 # pre-create empty directory to make INTERFACE_INCLUDE_DIRECTORIES happy
-file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/external/yaml-cpp/include)
+file(MAKE_DIRECTORY ${YAMLCPP_INCLUDE_DIR})
 
 add_library(external::yaml-cpp STATIC IMPORTED GLOBAL)
 add_dependencies(external::yaml-cpp yaml-cpp)
 set_target_properties(external::yaml-cpp PROPERTIES
-  IMPORTED_LOCATION ${PROJECT_BINARY_DIR}/external/yaml-cpp-prefix/src/yaml-cpp-build/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}
-  INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/external/yaml-cpp/include
+  IMPORTED_LOCATION ${YAMLCPP_BYPRODUCT}
+  INTERFACE_INCLUDE_DIRECTORIES ${YAMLCPP_INCLUDE_DIR}
 )
-- 
GitLab