From beb724465891947dc5182539e7599651b7651a6d Mon Sep 17 00:00:00 2001
From: Mayank Rathee <mayankrathee.japan@gmail.com>
Date: Tue, 2 Jun 2020 03:22:20 +0530
Subject: [PATCH] Added CMake build system

---
 Porthos/.gitignore           |  1 +
 Porthos/makefile             |  2 +-
 Porthos/src/CMakeLists.txt   | 36 ++++++++++++++++++++++++++++++++++++
 Porthos/src/basicSockets.cpp | 11 ++++++++++-
 Porthos/src/basicSockets.h   |  6 ++++++
 5 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 Porthos/src/CMakeLists.txt

diff --git a/Porthos/.gitignore b/Porthos/.gitignore
index 778019b..41181ff 100644
--- a/Porthos/.gitignore
+++ b/Porthos/.gitignore
@@ -4,3 +4,4 @@ util/Miracl/
 *.log
 **/*.swp
 lib_eigen/
+**/build/
diff --git a/Porthos/makefile b/Porthos/makefile
index 2c78a31..d3aa804 100644
--- a/Porthos/makefile
+++ b/Porthos/makefile
@@ -7,7 +7,7 @@ OBJ_FILES    	  += $(patsubst src/%.cpp, src/%.o, $(SRC_CPP_FILES))
 OBJ_FILES    	  += $(patsubst util/%.cpp, util/%.o, $(OBJ_CPP_FILES))
 HEADER_FILES       = $(wildcard src/*.h)
 
-FLAGS := -w -std=c++14 -pthread -msse4.1 -maes -msse2 -mpclmul -fpermissive -fpic #-fopenmp
+FLAGS := -w -std=c++14 -pthread -msse4.1 -maes -msse2 -mpclmul -fpermissive -fpic -fopenmp
 LIBS := -lcrypto -lssl
 OBJ_INCLUDES := -I 'lib_eigen/' -I 'src/'
 UTIL_INCLUDES := $($(OBJ_INCLUDES), -L./)
diff --git a/Porthos/src/CMakeLists.txt b/Porthos/src/CMakeLists.txt
new file mode 100644
index 0000000..0fd6e4e
--- /dev/null
+++ b/Porthos/src/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required (VERSION 3.0)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+if(APPLE)
+    set(CMAKE_C_COMPILER "/usr/local/bin/gcc-9")
+    set(CMAKE_CXX_COMPILER "/usr/local/bin/g++-9")
+endif()
+
+project(Porthos)
+set(NAME "Porthos")
+
+find_package(OpenMP REQUIRED)
+find_package(OpenSSL REQUIRED)
+
+FILE(GLOB CXXSources *.cpp)
+list(REMOVE_ITEM CXXSources ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
+add_library(Porthos-Protocols ${CXXSources})
+
+target_include_directories(Porthos-Protocols 
+	PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../lib_eigen/
+	${OPENSSL_INCLUDE_DIR})
+
+target_link_libraries(Porthos-Protocols
+	PUBLIC OpenMP::OpenMP_CXX
+	${OPENSSL_LIBRARIES})
+
+add_executable(Porthos3PC ${CMAKE_CURRENT_SOURCE_DIR}/example_neural_nets/mainResNet50.cpp)
+target_link_libraries(Porthos3PC Porthos-Protocols)
+
+target_compile_options(Porthos-Protocols
+	PUBLIC "-pthread;-Wall;-march=native;-msse4.1;-maes;-mpclmul;-mrdseed;-fpermissive;-fpic;-std=c++17;-w;-O3")
+
+target_compile_options(Porthos3PC
+	PRIVATE "-pthread;-Wall;-march=native;-msse4.1;-maes;-mpclmul;-mrdseed;-fpermissive;-fpic;-std=c++17;-w;-O3")
+
+
diff --git a/Porthos/src/basicSockets.cpp b/Porthos/src/basicSockets.cpp
index 4e94991..108a078 100644
--- a/Porthos/src/basicSockets.cpp
+++ b/Porthos/src/basicSockets.cpp
@@ -35,6 +35,16 @@ using namespace std::chrono;
 #define Sockwrite(sock, data, size) write(sock, data, size)
 #define Sockread(sock, buff, bufferSize) read(sock, buff, bufferSize)
 //#define socklen_t int
+
+#elif __APPLE__
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#define Sockwrite(sock, data, size) write(sock, data, size)
+#define Sockread(sock, buff, bufferSize) read(sock, buff, bufferSize)
+//#define socklen_t int
+
 #elif _WIN32
 //#pragma comment (lib, "ws2_32.lib") //Winsock Library
 #pragma comment (lib, "Ws2_32.lib")
@@ -46,7 +56,6 @@ using namespace std::chrono;
 #define close closesocket
 #define Sockwrite(sock, data, size) send(sock, (char*)data, size, 0)
 #define Sockread(sock, buff, bufferSize) recv(sock, (char*)buff, bufferSize, 0)
-
 #endif
 
 /*GLOBAL VARIABLES - LIST OF IP ADDRESSES*/
diff --git a/Porthos/src/basicSockets.h b/Porthos/src/basicSockets.h
index bb3c2fe..f8698b6 100644
--- a/Porthos/src/basicSockets.h
+++ b/Porthos/src/basicSockets.h
@@ -12,7 +12,13 @@
 //#include <stropts.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+
+#ifdef __APPLE__
+#include <net/if.h>
+#else
 #include <linux/netdevice.h>
+#endif
+
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <unistd.h>
-- 
GitLab