From 2e1a7abfb313f874add9efa2cdd716dffd842782 Mon Sep 17 00:00:00 2001
From: Robert Falkenberg <robert.falkenberg@srs.io>
Date: Tue, 10 May 2022 09:14:25 +0200
Subject: [PATCH] cmake: fix build for cmake option BUILD_SHARED_LIBS=ON

The cmake option BUILD_SHARED_LIBS (off by default) causes all
libraries to be built as shared libraries if not unless explicitly
stated otherwise.
Since test-helper libraries do not export their symbols, linking
fails if built as shared library.
Therefore, this change explicitly configures these helpers as STATIC.
---
 srsenb/test/rrc/CMakeLists.txt           | 2 +-
 srsgnb/src/stack/mac/test/CMakeLists.txt | 4 ++--
 srsgnb/src/stack/rrc/test/CMakeLists.txt | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/srsenb/test/rrc/CMakeLists.txt b/srsenb/test/rrc/CMakeLists.txt
index ccfd7bd15f..d931a4fedb 100644
--- a/srsenb/test/rrc/CMakeLists.txt
+++ b/srsenb/test/rrc/CMakeLists.txt
@@ -18,7 +18,7 @@
 # and at http://www.gnu.org/licenses/.
 #
 
-add_library(test_helpers test_helpers.cc)
+add_library(test_helpers STATIC test_helpers.cc)
 target_link_libraries(test_helpers srsenb_rrc srsenb_common rrc_asn1 rrc_nr_asn1 s1ap_asn1 srsran_common enb_cfg_parser ${LIBCONFIGPP_LIBRARIES})
 
 add_executable(rrc_meascfg_test rrc_meascfg_test.cc)
diff --git a/srsgnb/src/stack/mac/test/CMakeLists.txt b/srsgnb/src/stack/mac/test/CMakeLists.txt
index f37165e8f5..4f38b08f09 100644
--- a/srsgnb/src/stack/mac/test/CMakeLists.txt
+++ b/srsgnb/src/stack/mac/test/CMakeLists.txt
@@ -20,7 +20,7 @@
 
 set_directory_properties(PROPERTIES LABELS "sched;nr")
 
-add_library(sched_nr_test_suite sched_nr_common_test.cc sched_nr_ue_ded_test_suite.cc sched_nr_sim_ue.cc)
+add_library(sched_nr_test_suite STATIC sched_nr_common_test.cc sched_nr_ue_ded_test_suite.cc sched_nr_sim_ue.cc)
 target_link_libraries(sched_nr_test_suite srsgnb_mac srsran_common rrc_nr_asn1)
 
 add_executable(sched_nr_parallel_test sched_nr_parallel_test.cc)
@@ -65,4 +65,4 @@ target_link_libraries(sched_nr_test
         rrc_nr_asn1
         srsran_common ${CMAKE_THREAD_LIBS_INIT}
         ${Boost_LIBRARIES})
-add_nr_test(sched_nr_test sched_nr_test)
\ No newline at end of file
+add_nr_test(sched_nr_test sched_nr_test)
diff --git a/srsgnb/src/stack/rrc/test/CMakeLists.txt b/srsgnb/src/stack/rrc/test/CMakeLists.txt
index 640e26ce47..072d1b31c7 100644
--- a/srsgnb/src/stack/rrc/test/CMakeLists.txt
+++ b/srsgnb/src/stack/rrc/test/CMakeLists.txt
@@ -18,7 +18,7 @@
 # and at http://www.gnu.org/licenses/.
 #
 
-add_library(rrc_nr_test_helpers rrc_nr_test_helpers.cc)
+add_library(rrc_nr_test_helpers STATIC rrc_nr_test_helpers.cc)
 
 add_executable(rrc_nr_test rrc_nr_test.cc)
 target_link_libraries(rrc_nr_test srsgnb_rrc srsgnb_rrc_config_utils srsran_common rrc_nr_asn1 rrc_nr_test_helpers srsgnb_mac ${ATOMIC_LIBS})
