From 7c4f6ca0a7dc6f58956615f37ee6b76942fb0bb7 Mon Sep 17 00:00:00 2001
From: Carsten Patzke <carsten.patzke@desy.de>
Date: Wed, 24 Jan 2018 15:07:22 +0100
Subject: [PATCH] Common libraries defined by property

---
 common/cpp/CMakeLists.txt                     |  5 ++++
 common/cpp/src/system_io_windows.cpp          | 30 ++++++++-----------
 .../dummy-data-producer/CMakeLists.txt        |  9 ++++--
 examples/worker/process_folder/CMakeLists.txt |  7 ++++-
 receiver/CMakeLists.txt                       |  6 +++-
 tests/CMakeLists.txt                          |  2 +-
 tests/common/cpp/CMakeLists.txt               |  4 +++
 .../read_file_content/CMakeLists.txt          |  7 ++++-
 .../read_files_in_folder/CMakeLists.txt       |  7 ++++-
 .../worker/connect_multithread/CMakeLists.txt |  2 +-
 tests/worker/next_multithread/CMakeLists.txt  |  7 ++++-
 11 files changed, 59 insertions(+), 27 deletions(-)

diff --git a/common/cpp/CMakeLists.txt b/common/cpp/CMakeLists.txt
index b76ce0d2d..da4dc3aed 100644
--- a/common/cpp/CMakeLists.txt
+++ b/common/cpp/CMakeLists.txt
@@ -15,6 +15,11 @@ ENDIF(WIN32)
 ################################
 # Library
 ################################
+IF(WIN32)
+    SET_PROPERTY(GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES "Threads::Threads wsock32 ws2_32")
+ELSEIF(UNIX)
+    SET_PROPERTY(GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES "Threads::Threads")
+ENDIF(WIN32)
 add_library(${TARGET_NAME} OBJECT ${SOURCE_FILES})
 #add_library(${TARGET_NAME} SHARED ${SOURCE_FILES})
 target_include_directories(${TARGET_NAME} PUBLIC include)
diff --git a/common/cpp/src/system_io_windows.cpp b/common/cpp/src/system_io_windows.cpp
index 6a2302bef..1d42b4fcd 100644
--- a/common/cpp/src/system_io_windows.cpp
+++ b/common/cpp/src/system_io_windows.cpp
@@ -85,8 +85,7 @@ std::chrono::system_clock::time_point FileTime2TimePoint(const FILETIME& ft, IOE
     return tp;
 }
 
-FileInfo hidra2::SystemIO::GetFileInfo(const std::string & path, const std::string & name, IOErrors * err) const
-{
+FileInfo hidra2::SystemIO::GetFileInfo(const std::string& path, const std::string& name, IOErrors* err) const {
     return FileInfo();
 }
 
@@ -144,43 +143,38 @@ void SystemIO::CollectFileInformationRecursivly(const std::string& path,
     }
 }
 
-int hidra2::SystemIO::AddressFamilyToPosixFamily(AddressFamilies address_family) const
-{
+int hidra2::SystemIO::AddressFamilyToPosixFamily(AddressFamilies address_family) const {
     return 0;
 }
 
-int hidra2::SystemIO::SocketTypeToPosixType(SocketTypes socket_type) const
-{
+int hidra2::SystemIO::SocketTypeToPosixType(SocketTypes socket_type) const {
     return 0;
 }
 
-int hidra2::SystemIO::SocketProtocolToPosixProtocol(SocketProtocols socket_protocol) const
-{
+int hidra2::SystemIO::SocketProtocolToPosixProtocol(SocketProtocols socket_protocol) const {
     return 0;
 }
 
-void hidra2::SystemIO::InetBind(FileDescriptor socket_fd, const std::string & address, uint16_t port, IOErrors * err) const
-{
+void hidra2::SystemIO::InetBind(FileDescriptor socket_fd, const std::string& address, uint16_t port,
+                                IOErrors* err) const {
 
 }
 
-std::unique_ptr<std::tuple<std::string, FileDescriptor>> SystemIO::InetAccept(FileDescriptor socket_fd, IOErrors * err) const
-{
+std::unique_ptr<std::tuple<std::string, FileDescriptor>> SystemIO::InetAccept(FileDescriptor socket_fd,
+IOErrors* err) const {
     return std::unique_ptr<std::tuple<std::string, FileDescriptor>>();
 }
 
-void hidra2::SystemIO::InetConnect(FileDescriptor socket_fd, const std::string & address, IOErrors * err) const
-{
+void hidra2::SystemIO::InetConnect(FileDescriptor socket_fd, const std::string& address, IOErrors* err) const {
 
 }
 
-size_t hidra2::SystemIO::ReceiveTimeout(FileDescriptor socket_fd, void * buf, size_t length, uint16_t timeout_in_sec, IOErrors * err) const
-{
+size_t hidra2::SystemIO::ReceiveTimeout(FileDescriptor socket_fd, void* buf, size_t length, uint16_t timeout_in_sec,
+                                        IOErrors* err) const {
     return size_t();
 }
 
-FileDescriptor hidra2::SystemIO::_open(const char * filename, int posix_open_flags) const
-{
+FileDescriptor hidra2::SystemIO::_open(const char* filename, int posix_open_flags) const {
     int fd;
     errno = _sopen_s(&fd, filename, posix_open_flags, _SH_DENYNO, _S_IREAD | _S_IWRITE);
     return fd;
diff --git a/examples/producer/dummy-data-producer/CMakeLists.txt b/examples/producer/dummy-data-producer/CMakeLists.txt
index aea16d6f0..e4f8921a2 100644
--- a/examples/producer/dummy-data-producer/CMakeLists.txt
+++ b/examples/producer/dummy-data-producer/CMakeLists.txt
@@ -1,11 +1,16 @@
-set(TARGET_NAME dummy-event-detector)
+set(TARGET_NAME dummy-data-producer)
 set(SOURCE_FILES
         dummy_data_producer.cpp
         )
 
 add_executable(${TARGET_NAME} ${SOURCE_FILES} $<TARGET_OBJECTS:common>)
 target_include_directories(${TARGET_NAME} PUBLIC include ${CMAKE_SOURCE_DIR}/common/cpp/include)
-target_link_libraries(${TARGET_NAME} Threads::Threads producer-api)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
+
+target_link_libraries(${TARGET_NAME} producer-api)
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 
 if (CMAKE_COMPILER_IS_GNUCXX)
diff --git a/examples/worker/process_folder/CMakeLists.txt b/examples/worker/process_folder/CMakeLists.txt
index a9879c3e2..6153ecbb1 100644
--- a/examples/worker/process_folder/CMakeLists.txt
+++ b/examples/worker/process_folder/CMakeLists.txt
@@ -2,7 +2,12 @@ set(TARGET_NAME worker_processfolder)
 set(SOURCE_FILES process_folder.cpp)
 
 add_executable(${TARGET_NAME} ${SOURCE_FILES})
-target_link_libraries(${TARGET_NAME} hidra2-worker Threads::Threads)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
+
+target_link_libraries(${TARGET_NAME} hidra2-worker)
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 #use expression generator to get rid of VS adding Debug/Release folders
 set_target_properties(${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt
index 74916a466..88ac9b4fa 100644
--- a/receiver/CMakeLists.txt
+++ b/receiver/CMakeLists.txt
@@ -11,7 +11,11 @@ set(SOURCE_FILES
 ################################
 add_executable(${TARGET_NAME} ${SOURCE_FILES} $<TARGET_OBJECTS:common>)
 target_include_directories(${TARGET_NAME} PUBLIC include ${CMAKE_SOURCE_DIR}/common/cpp/include)
-target_link_libraries(${TARGET_NAME} Threads::Threads)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
+
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 
 ################################
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 59f4f8214..73ad6a963 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 3.7) # needed for fixtures
-find_package(Threads)
+find_package(Threads REQUIRED)
 
 add_subdirectory(common/cpp)
 add_subdirectory(system_io)
diff --git a/tests/common/cpp/CMakeLists.txt b/tests/common/cpp/CMakeLists.txt
index 1eec82d9f..520d0153d 100644
--- a/tests/common/cpp/CMakeLists.txt
+++ b/tests/common/cpp/CMakeLists.txt
@@ -8,3 +8,7 @@ set(SOURCE_FILES
 add_library(${TARGET_NAME} STATIC ${SOURCE_FILES})
 target_include_directories(${TARGET_NAME} PUBLIC include)
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
diff --git a/tests/system_io/read_file_content/CMakeLists.txt b/tests/system_io/read_file_content/CMakeLists.txt
index 205f02310..a8a2b328a 100644
--- a/tests/system_io/read_file_content/CMakeLists.txt
+++ b/tests/system_io/read_file_content/CMakeLists.txt
@@ -6,7 +6,12 @@ set(SOURCE_FILES read_file_content.cpp)
 # Executable and link
 ################################
 add_executable(${TARGET_NAME} ${SOURCE_FILES} $<TARGET_OBJECTS:common> )
-target_link_libraries(${TARGET_NAME} test_common Threads::Threads)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
+
+target_link_libraries(${TARGET_NAME} test_common)
 target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/common/cpp/include)
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 
diff --git a/tests/system_io/read_files_in_folder/CMakeLists.txt b/tests/system_io/read_files_in_folder/CMakeLists.txt
index 3e2df78a2..41ac8e62a 100644
--- a/tests/system_io/read_files_in_folder/CMakeLists.txt
+++ b/tests/system_io/read_files_in_folder/CMakeLists.txt
@@ -6,7 +6,12 @@ set(SOURCE_FILES read_folder_content.cpp)
 # Executable and link
 ################################
 add_executable(${TARGET_NAME} ${SOURCE_FILES}  $<TARGET_OBJECTS:common>)
-target_link_libraries(${TARGET_NAME} test_common Threads::Threads)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
+
+target_link_libraries(${TARGET_NAME} test_common)
 target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/common/cpp/include)
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 
diff --git a/tests/worker/connect_multithread/CMakeLists.txt b/tests/worker/connect_multithread/CMakeLists.txt
index 31364d77e..abe83367d 100644
--- a/tests/worker/connect_multithread/CMakeLists.txt
+++ b/tests/worker/connect_multithread/CMakeLists.txt
@@ -6,7 +6,7 @@ set(SOURCE_FILES content_multithread.cpp)
 # Executable and link
 ################################
 add_executable(${TARGET_NAME} ${SOURCE_FILES})
-target_link_libraries(${TARGET_NAME} test_common hidra2-worker ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(${TARGET_NAME} test_common hidra2-worker ${HIDRA2_COMMON_IO_LIBRARIES})
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 if (CMAKE_COMPILER_IS_GNUCXX)
     set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "--coverage")
diff --git a/tests/worker/next_multithread/CMakeLists.txt b/tests/worker/next_multithread/CMakeLists.txt
index ebcabc40c..db2a6e5c0 100644
--- a/tests/worker/next_multithread/CMakeLists.txt
+++ b/tests/worker/next_multithread/CMakeLists.txt
@@ -6,7 +6,12 @@ set(SOURCE_FILES next_multithread.cpp)
 # Executable and link
 ################################
 add_executable(${TARGET_NAME} ${SOURCE_FILES})
-target_link_libraries(${TARGET_NAME} test_common hidra2-worker Threads::Threads)
+
+#Add all necessary common libraries
+GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES)
+target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES})
+
+target_link_libraries(${TARGET_NAME} test_common hidra2-worker)
 set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 if (CMAKE_COMPILER_IS_GNUCXX)
     set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "--coverage")
-- 
GitLab