Skip to content
Snippets Groups Projects
CMakeLists.txt 2.83 KiB
Newer Older
cmake_minimum_required(VERSION 3.18)
set(TARGET_NAME wordle-de)
Lukas Güldenstein's avatar
Lukas Güldenstein committed

project(${TARGET_NAME})
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Protobuf
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)
Lukas Güldenstein's avatar
Lukas Güldenstein committed

# Botan2 via PkgConfig
find_package(PkgConfig)
pkg_check_modules(BOTAN2 REQUIRED botan-2)
Lukas Güldenstein's avatar
Lukas Güldenstein committed

# LevelDB
Lukas Güldenstein's avatar
Lukas Güldenstein committed
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})

# Threads
find_package(Threads REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

# CXXOPTS
Lukas Güldenstein's avatar
Lukas Güldenstein committed
add_subdirectory(extern/cxxopts)

# Common Sources for both executables
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)
Lukas Güldenstein's avatar
Lukas Güldenstein committed
target_link_libraries(${TARGET_NAME}_server ${LEVELDB_LIBRARIES})
target_include_directories(
Lukas Güldenstein's avatar
Lukas Güldenstein committed
	${TARGET_NAME}_server PRIVATE
	${CMAKE_SOURCE_DIR}/src
	${CMAKE_SOURCE_DIR}/include
	${BOTAN2_INCLUDE_DIRS}
	${LEVELDB_INCLUDE_DIRS}
	cxxopts

# Client
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)
Lukas Güldenstein's avatar
Lukas Güldenstein committed
target_include_directories(
Lukas Güldenstein's avatar
Lukas Güldenstein committed
	${TARGET_NAME}_client PRIVATE
	${CMAKE_SOURCE_DIR}/src
	${CMAKE_SOURCE_DIR}/include
	${BOTAN2_INCLUDE_DIRS}
Lukas Güldenstein's avatar
Lukas Güldenstein committed
)