dermesser / libsocket

The ultimate socket library for C and C++, supporting TCP, UDP and Unix sockets (DGRAM and STREAM) on Linux, FreeBSD, Solaris. See also my uvco library for a refreshed version!
https://borgac.net/~lbo/doc/libsocket/
Other
806 stars 196 forks source link

Build on old systems (e.g., Ubuntu 12.04) #24

Open ducss2015 opened 9 years ago

ducss2015 commented 9 years ago

I use an old system with cmake 2.8.7 (not support TARGET_OBJECTS) and gcc 4.6.3 (not support -std=c++11) so the build does not work. The following patch helps me build successfully.

Hope that helps.

diff --git a/C++/CMakeLists.txt b/C++/CMakeLists.txt
index 36121c5..d05f845 100644
--- a/C++/CMakeLists.txt
+++ b/C++/CMakeLists.txt
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 2.8)

-SET(CMAKE_CXX_FLAGS "-std=c++11") # -DVERBOSE")
+SET(CMAKE_CXX_FLAGS "-std=c++0x") # -DVERBOSE")

 ADD_DEFINITIONS("-DMIXED")

diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt
index 881c5c2..7d7b17d 100644
--- a/C/CMakeLists.txt
+++ b/C/CMakeLists.txt
@@ -7,10 +7,12 @@ SET(libsocket_src

 IF ( NOT IS_SUNOS )
     ADD_DEFINITIONS(-fPIC) # for the static library which needs to be linked into the shared libsocket++.so object.
-    ADD_LIBRARY(socket_o OBJECT ${libsocket_src})
+    #ADD_LIBRARY(socket_o OBJECT ${libsocket_src})

-    ADD_LIBRARY(socket MODULE $<TARGET_OBJECTS:socket_o>)
-    ADD_LIBRARY(socket_int STATIC $<TARGET_OBJECTS:socket_o>)
+    #ADD_LIBRARY(socket MODULE $<TARGET_OBJECTS:socket_o>)
+    #ADD_LIBRARY(socket_int STATIC $<TARGET_OBJECTS:socket_o>)
+    ADD_LIBRARY(socket MODULE ${libsocket_src})
+    ADD_LIBRARY(socket_int STATIC ${libsocket_src})

     INSTALL(TARGETS socket DESTINATION ${LIB_DIR})
 ELSE() # On SunOS (e.g. OpenIndiana) we have to link against the system's libsocket. The library is renamed to libsocket_hl (hl = high-level)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5233618..0def475 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,7 +22,7 @@ CONFIGURE_FILE(headers/conf.h.in ${CMAKE_SOURCE_DIR}/headers/conf.h)

 # Compiler configuration
 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/headers/)
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
 ADD_DEFINITIONS(-Wall -Wextra)
 #ADD_DEFINITIONS(-DVERBOSE)
dermesser commented 9 years ago

Thanks for the patch! However, the documentation makes it clear that a compiler supporting C++11 (i.e. not C++0x) and CMake >= 2.8.8 are required.

Adding the patch as a separate file and referencing it from the README as an easy way to gain compatibility for older systems would be very nice, though!