From c962ce6f96bec8b101f4f6ea85bc52321b3fb254 Mon Sep 17 00:00:00 2001
From: Markus Rathgeb <maggu2810@gmail.com>
Date: Tue, 5 Oct 2021 10:28:26 +0200
Subject: [PATCH 1/2] fix CMakeLists.txt

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
---
 CMakeLists.txt | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6095da..980c385 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,8 @@ message( "#                                                            #" )
 message( "##############################################################" )
 message( "                                                              " )
 
+include(GNUInstallDirs)
+
 #
 # Build Options
 #
@@ -27,19 +29,10 @@ set( CMAKE_CXX_STANDARD 14 )
 set( INCLUDE_DIR "${PROJECT_SOURCE_DIR}/source" )
 set( SOURCE_DIR  "${PROJECT_SOURCE_DIR}/source/corvusoft/${PROJECT_NAME}" )
 
-if ( NOT DEFINED CMAKE_INSTALL_LIBDIR )
-    set( CMAKE_INSTALL_LIBDIR "library")
-endif ( )
-
-if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
-    set( CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/distribution" CACHE PATH "Install path prefix" FORCE )
-endif ( )
-
 if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_WIN32_WINNT=0x0601 /W4 /wd4068 /wd4702 /wd4996 /wd4265" )
-endif ( )
-
-if( NOT WIN32 )
+    set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251" )
+else ( )
     set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Weffc++ -pedantic -Wno-unknown-pragmas -Wno-deprecated-declarations -Wno-non-virtual-dtor" )
 endif ( )
 
@@ -53,22 +46,18 @@ endif ( )
 
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake" )
 
-find_package( asio REQUIRED )
-
 if ( BUILD_SSL )
     add_definitions( "-DBUILD_SSL" )
-    find_package( openssl REQUIRED )
 endif ( )
 
-include_directories( ${INCLUDE_DIR} SYSTEM ${asio_INCLUDE} ${ssl_INCLUDE} )
+include_directories( ${INCLUDE_DIR} )
 
 if ( BUILD_IPC )
     add_definitions( "-DBUILD_IPC" )
 endif ( )
 
 if ( WIN32 )
-	add_definitions( -DWIN_DLL_EXPORT )
-	set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251" )
+    add_definitions( -DWIN_DLL_EXPORT )
 endif ( )
 
 #
@@ -86,7 +75,7 @@ set( SHARED_LIBRARY_NAME "${PROJECT_NAME}-shared" )
 add_library( ${SHARED_LIBRARY_NAME} SHARED ${MANIFEST} )
 set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD 14 )
 set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
-if ( WIN32 )
+if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
 	# Workaround to avoid name clash of static lib and dynamic import lib under windows.
 	set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}-shared" )
 else ( )
@@ -94,9 +83,13 @@ else ( )
 endif ( )	
 set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} )
 
+if ( WIN32 )
+    target_link_libraries( ${SHARED_LIBRARY_NAME} PRIVATE ws2_32 wsock32 )
+endif ( )
+
 if ( BUILD_SSL )
-    target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_SHARED} ${crypto_LIBRARY_SHARED} )
-    target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_STATIC} ${crypto_LIBRARY_STATIC} ${CMAKE_DL_LIBS} )
+    target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE ssl crypto )
+    target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE ssl crypto ${CMAKE_DL_LIBS} )
 else ( )
     target_link_libraries( ${SHARED_LIBRARY_NAME} )
     target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} )
@@ -119,5 +112,5 @@ file( GLOB ARTIFACTS "${SOURCE_DIR}/*.hpp" )
 
 install( FILES "${INCLUDE_DIR}/${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" )
 install( FILES ${ARTIFACTS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/corvusoft/${PROJECT_NAME}" )
-install( TARGETS ${STATIC_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
-install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
+install( TARGETS ${STATIC_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
+install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
-- 
2.33.0

