Newer
Older
cmake_minimum_required(VERSION 3.18)
project(${TARGET_NAME})
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${TARGET_NAME}.proto)
find_package(PkgConfig)
pkg_check_modules(BOTAN2 REQUIRED botan-2)
find_path(
LEVELDB_INCLUDE_DIR
NAMES leveldb/db.h
DOC "leveldb include dir"
)
find_library(
LEVELDB_LIBRARY
NAMES leveldb
DOC "leveldb library"
)
set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR})
set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY})
find_package(Threads REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(COMMON_SRCS
src/game.cpp
${PROTO_SRCS}
${PROTO_HDRS}
)
set(COMMON_LIBS
${Protobuf_LIBRARIES}
${BOTAN2_LIBRARIES}
${BOTAN2_LDFLAGS}
cxxopts
)
# Docs
option(BUILD_DOC "Build documentation" ON)
# check if Doxygen is installed
find_package(Doxygen)
if(DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
else(DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif(DOXYGEN_FOUND)
# Server
set(server_sources src/server_main.cpp src/server.cpp ${COMMON_SRCS})
add_executable(${TARGET_NAME}_server ${server_sources})
target_link_libraries(${TARGET_NAME}_server ${COMMON_LIBS})
# target_link_libraries(${TARGET_NAME}_server ${Protobuf_LIBRARIES})
# target_link_libraries(${TARGET_NAME}_server ${BOTAN2_LIBRARIES} ${BOTAN2_LDFLAGS})
# target_link_libraries(${TARGET_NAME}_server cxxopts)
target_link_libraries(${TARGET_NAME}_server ${LEVELDB_LIBRARIES})
target_include_directories(
${TARGET_NAME}_server PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include
${BOTAN2_INCLUDE_DIRS}
${LEVELDB_INCLUDE_DIRS}
cxxopts
set(client_sources src/client_main.cpp src/client.cpp ${COMMON_SRCS})
add_executable(${TARGET_NAME}_client ${client_sources})
target_link_libraries(${TARGET_NAME}_client ${COMMON_LIBS})
# target_link_libraries(${TARGET_NAME}_client ${Protobuf_LIBRARIES})
# target_link_libraries(${TARGET_NAME}_client ${BOTAN2_LIBRARIES} ${BOTAN2_LDFLAGS})
# target_link_libraries(${TARGET_NAME}_client cxxopts)
${TARGET_NAME}_client PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include
${BOTAN2_INCLUDE_DIRS}