-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
147 lines (130 loc) · 4.49 KB
/
CMakeLists.txt
File metadata and controls
147 lines (130 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
cmake_minimum_required(VERSION 3.14)
project(bidding_model_server)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Option to use system libraries or local libraries
option(USE_SYSTEM_LIBS "Use system installed libraries" OFF)
# Find dependencies
# Add vcpkg paths to search for libraries when USE_SYSTEM_LIBS is ON
if(USE_SYSTEM_LIBS)
set(VCPKG_INSTALL_DIR "C:/Users/tchu/PycharmProjects/vcpkg/installed/x64-windows")
list(APPEND CMAKE_PREFIX_PATH ${VCPKG_INSTALL_DIR})
list(APPEND CMAKE_INCLUDE_PATH ${VCPKG_INSTALL_DIR}/include)
list(APPEND CMAKE_LIBRARY_PATH ${VCPKG_INSTALL_DIR}/lib)
list(APPEND CMAKE_PROGRAM_PATH ${VCPKG_INSTALL_DIR}/tools/protobuf)
endif()
find_package(protobuf CONFIG QUIET)
if(NOT protobuf_FOUND)
find_package(Protobuf REQUIRED)
set(protobuf_LIBRARIES ${Protobuf_LIBRARIES})
set(protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS})
set(protobuf_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
set(protobuf_FOUND TRUE)
else()
set(protobuf_LIBRARIES protobuf::libprotobuf)
set(protobuf_INCLUDE_DIRS ${protobuf_INCLUDE_DIRS})
set(protobuf_PROTOC_EXECUTABLE protobuf::protoc)
endif()
find_package(gRPC CONFIG QUIET)
if(NOT gRPC_FOUND)
# Try to find gRPC manually
set(gRPC_INCLUDE_DIRS "${VCPKG_INSTALL_DIR}/include")
set(gRPC_LIBRARIES "${VCPKG_INSTALL_DIR}/lib/grpc++.lib")
set(gRPC_FOUND TRUE)
else()
set(gRPC_LIBRARIES gRPC::grpc++)
set(gRPC_INCLUDE_DIRS ${gRPC_INCLUDE_DIRS})
endif()
find_package(OpenSSL REQUIRED)
find_package(yaml-cpp CONFIG QUIET)
if(NOT yaml-cpp_FOUND)
# Try to find yaml-cpp manually
set(yaml-cpp_INCLUDE_DIRS "${VCPKG_INSTALL_DIR}/include")
set(yaml-cpp_LIBRARIES "${VCPKG_INSTALL_DIR}/lib/yaml-cpp.lib")
set(yaml-cpp_FOUND TRUE)
else()
set(yaml-cpp_LIBRARIES yaml-cpp::yaml-cpp)
set(yaml-cpp_INCLUDE_DIRS ${yaml-cpp_INCLUDE_DIRS})
endif()
# Use project's built-in log4cpp headers
set(LOG4CPP_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include/log4cpp)
set(LOG4CPP_LIBRARY "")
message(STATUS "Using built-in log4cpp headers from ${LOG4CPP_INCLUDE_DIR}")
message(STATUS "Using protobuf: ${protobuf_INCLUDE_DIRS}, ${protobuf_LIBRARIES}")
message(STATUS "Using gRPC: ${gRPC_INCLUDE_DIRS}, ${gRPC_LIBRARIES}")
message(STATUS "Using yaml-cpp: ${yaml-cpp_INCLUDE_DIRS}, ${yaml-cpp_LIBRARIES}")
message(STATUS "Using log4cpp: ${LOG4CPP_INCLUDE_DIR}, ${LOG4CPP_LIBRARY}")
# Include directories
include_directories(
${PROJECT_SOURCE_DIR}/include
${protobuf_INCLUDE_DIRS}
${gRPC_INCLUDE_DIRS}
${yaml-cpp_INCLUDE_DIRS}
${LOG4CPP_INCLUDE_DIR}
)
# Source files
set(SOURCES
main.cpp
include/common.cpp
manager/bid_server_manager.cpp
manager/index_manager.cpp
manager/index.cpp
manager/ad_index.cpp
manager/campaign_index.cpp
service/bid_service.cpp
handler/bid_handler.cpp
proto/ad_bid.pb.cc
proto/ad_bid.grpc.pb.cc
)
# Header files (for IDE support)
set(HEADERS
include/common.h
include/const.h
include/simple_logger.h
handler/bid_handler.h
manager/bid_server_manager.h
manager/index_manager.h
manager/index.h
manager/ad_index.h
manager/campaign_index.h
service/bid_service.h
proto/ad_bid.pb.h
proto/ad_bid.grpc.pb.h
)
# Create executable
add_executable(bidding_model_server ${SOURCES} ${HEADERS})
# Link libraries
if(MSVC)
# For Visual Studio - use vcpkg managed libraries
target_link_libraries(bidding_model_server
${protobuf_LIBRARIES}
${gRPC_LIBRARIES}
${yaml-cpp_LIBRARIES}
OpenSSL::SSL
OpenSSL::Crypto
)
else()
# For MinGW - use system libraries or vcpkg libraries
target_link_libraries(bidding_model_server
${protobuf_LIBRARIES}
${gRPC_LIBRARIES}
${yaml-cpp_LIBRARIES}
${OPENSSL_LIBRARIES}
)
endif()
# Windows specific libraries
if(WIN32)
target_link_libraries(bidding_model_server ws2_32 wsock32)
endif()
# Set output directory
set_target_properties(bidding_model_server PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin
)
# Copy configuration files to output directory
configure_file(config.yaml ${PROJECT_SOURCE_DIR}/bin/config.yaml COPYONLY)
configure_file(data/index_config_0 ${PROJECT_SOURCE_DIR}/bin/data/index_config_0 COPYONLY)
configure_file(data/index_config_1 ${PROJECT_SOURCE_DIR}/bin/data/index_config_1 COPYONLY)
# Create data directory in output
add_custom_command(TARGET bidding_model_server POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/bin/data
)