11cmake_minimum_required (VERSION 3.10 )
22# Set the project name
33project (grpc_server)
4+
45# Find GMP library
56find_path (GMP_INCLUDE_DIR NAMES gmp.h )
67find_library (GMP_LIBRARY NAMES gmp )
@@ -10,25 +11,30 @@ if(NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARY OR NOT GMPXX_LIBRARY)
1011endif ()
1112include_directories (${GMP_INCLUDE_DIR} )
1213include_directories (${CMAKE_CURRENT_SOURCE_DIR} /include )
14+
1315# Specify C++ standard
1416set (CMAKE_CXX_STANDARD 17)
1517set (CMAKE_CXX_STANDARD_REQUIRED ON )
18+
1619# Find Protobuf and gRPC packages
1720find_package (Protobuf REQUIRED )
1821find_package (gRPC REQUIRED )
22+
1923# Gather all source files in src directory
20- file (GLOB SOURCES "src/*.cpp" )
24+ file (GLOB SOURCES "src/*.cpp" )
25+
2126# Specify the path to the proto files
2227set (PROTO_FILES
2328 ${CMAKE_SOURCE_DIR} /proto/encryption.proto
2429)
30+
2531# Paths to the protoc and grpc_cpp_plugin binaries
2632set (PROTOC_PATH "/usr/local/bin/protoc" )
2733set (GRPC_CPP_PLUGIN_PATH "/usr/local/bin/grpc_cpp_plugin" )
34+
2835# Specify output directory for generated files
29- # set(PROTO_GEN_DIR "${CMAKE_BINARY_DIR}/generated")
3036set (PROTO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR} )
31- # file(MAKE_DIRECTORY ${PROTO_GEN_DIR})
37+
3238# Generate C++ source files from proto files
3339foreach (proto_file ${PROTO_FILES} )
3440 get_filename_component (proto_name ${proto_file} NAME_WE )
@@ -52,27 +58,35 @@ foreach(proto_file ${PROTO_FILES})
5258 list (APPEND PROTO_SRCS ${PROTO_GEN_DIR} /${proto_name} .pb.cc ${PROTO_GEN_DIR} /${proto_name} .grpc.pb.cc)
5359 list (APPEND PROTO_HDRS ${PROTO_GEN_DIR} /${proto_name} .pb.h ${PROTO_GEN_DIR} /${proto_name} .grpc.pb.h)
5460endforeach ()
61+
5562# Include the generated files directory
5663include_directories (${PROTO_GEN_DIR} )
64+
5765# Include directories for protobuf and gRPC
5866include_directories (${Protobuf_INCLUDE_DIRS} ${GRPC_INCLUDE_DIRS} )
5967
6068# Add the logger library
6169file (GLOB LOGGER_SOURCES "logger/*.cpp" )
6270add_library (logger STATIC ${LOGGER_SOURCES} )
71+
6372# Add the executable
6473add_executable (grpc_server src/my_logger.cpp ${SOURCES} ${PROTO_SRCS} )
74+
6575# Link against protobuf, gRPC, GMP, and logger libraries
6676target_link_libraries (grpc_server ${Protobuf_LIBRARIES} ${GMP_LIBRARY} ${GMPXX_LIBRARY} gRPC::grpc++ logger )
77+
6778# Ensure that protobuf and gRPC code generation is properly configured
6879add_custom_target (proto_gen ALL
6980 DEPENDS ${PROTO_SRCS} ${PROTO_HDRS}
7081 COMMENT "Generating protobuf and gRPC code"
7182)
83+
7284# Add dependencies to ensure proper build order
7385add_dependencies (grpc_server proto_gen )
74- # Set build type to Debug
75- set (CMAKE_BUILD_TYPE Debug)
76- # Add debug flags
77- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" )
78- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g" )
86+
87+ # Set build type to Release for optimizations
88+ set (CMAKE_BUILD_TYPE Release)
89+
90+ # Set optimization flags for Release mode
91+ set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3" )
92+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3" )
0 commit comments