Comment on page
Building with CMake
When building the Muxer Server and Muxer Client Plugins into your applications it will be necessary to update your build system to correctly source all of the required dependencies. Details of which headers to add to your source can be found in the Integration and Setup section.
Below we look at how to set up CMake to correctly build for two targets, the server application and the client application.
On this page we provide a CMakeLists.txt configurations to build libraries for both the muxer-server-plugin and muxer-client-plugin, these can be found at the bottom of the page and should be added to the muxer-sdk in the folders
repclient
and muxer-server.
Immediately below is an example of how you could set up your project to link in to the plugins for both a server and client application.
cMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(my-example-project-client)
option(BUILD_SERVER "Build the server" ON)
option(BUILD_CLIENT "Build the client" ON)
# General setting for your project, these are not requirements for Muxer
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g ")
else(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -fpermissive")
endif(WIN32)
message(STATUS "Starting build, Client : ${BUILD_CLIENT} Server : ${BUILD_SERVER}")
# REQUIRED
# Here we build a server side application written in the server.cc file
# We link in to the muxer-server directory where you can place the additional
# CMakeLists.txt that specify the muxer-server-plugin
if(BUILD_SERVER)
message(STATUS "Building Muxer Server Example")
add_subdirectory(muxer-sdk/muxer-server)
add_executable(server
${CMAKE_CURRENT_LIST_DIR}/server.cc
)
target_link_libraries(server muxer-server-plugin)
endif()
# REQUIRED
# Here we build a client side application written in the client.cc file
# We link in to the muxer-server directory where you can place the additional
# CMakeLists.txt that specify the muxer-server-plugin
if(BUILD_CLIENT)
message(STATUS "Building Muxer Client Example")
add_subdirectory(muxer-sdk/repclient)
add_executable(client
${CMAKE_CURRENT_LIST_DIR}/client.cc
)
target_link_libraries(client muxer-client-plugin)
endif()
Below we show CMake configurations for including both the server and client plugins. The files assume that they are located within the muxer-sdk.
CMakeLists.txt
#---------------------------------- MUXER CLIENT - in muxer-sdk/repclient
if(WIN32)
set(LIB_FOLDER win64)
else()
set(LIB_FOLDER linux)
# This ensures that the hadean logging library is available for ther server plugin
find_package(PkgConfig REQUIRED)
pkg_check_modules(HADEAN-LOGGER REQUIRED hadean-logger-cc)
# Only required in the unix version
find_library(MUXER-FMT NAMES libfmt.a PATHS ${CMAKE_CURRENT_LIST_DIR}/../common/lib/${LIB_FOLDER} REQUIRED)
endif()
message(STATUS "Building Muxer Server Plugin for ${LIB_FOLDER}")
# Set the locations of the various required files based on where you have deployed the muxer sdk
set( PROTOCOL_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/../protocol/include)
set( PROTOCOL_SRC_PATH ${CMAKE_CURRENT_LIST_DIR}/../protocol/src)
set( COMMON_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/../common/include)
set( COMMON_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/../common/lib)
set( CLIENT_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/include)
set( CLIENT_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/lib)
set( CLIENT_SRC_PATH ${CMAKE_CURRENT_LIST_DIR}/src)
find_library(MUXER-CAPNP NAMES libcapnp.a capnp.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-CAPNPJSON NAMES libcapnp-json.a capnp-json.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-CAPNPRPC NAMES libcapnp-rpc.a capnp-rpc.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-KJ NAMES libkj.a kj.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-KJHTTP NAMES libkj-http.a kj-http.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-COMMON NAMES libaether_common.a PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
add_library(muxer-client-plugin
${PROTOCOL_SRC_PATH}/marshalling.cc
${CLIENT_SRC_PATH}/repclient.cc
)
target_compile_features(muxer-client-plugin PUBLIC cxx_std_14)
target_compile_definitions(muxer-client-plugin PUBLIC WITHOUT_HADEAN_LOGGING)
target_include_directories(muxer-client-plugin
PUBLIC ${CLIENT_INCLUDE_PATH}
PUBLIC ${PROTOCOL_INCLUDE_PATH}
PUBLIC ${COMMON_INCLUDE_PATH}
PUBLIC $ENV{HADEAN_SDK}/sdk/include
)
target_link_libraries(
muxer-client-plugin
${MUXER-CAPNP}
${MUXER-CAPNPJSON}
${MUXER-CAPNPRPC}
${MUXER-KJ}
${MUXER-COMMON}
${HADEAN-LOGGER_LDFLAGS}
${MUXER-FMT}
)
#---------------------------------- MUXER SERVER - in muxer-sdk/muxer-server
if(WIN32)
set(LIB_FOLDER win64)
else()
set(LIB_FOLDER linux)
# This ensures that the hadean logging library is available for ther server plugin
find_package(PkgConfig REQUIRED)
pkg_check_modules(HADEAN-LOGGER REQUIRED hadean-logger-cc)
# Only required in the unix version
find_library(MUXER-FMT NAMES libfmt.a PATHS ${CMAKE_CURRENT_LIST_DIR}/../common/lib/${LIB_FOLDER} REQUIRED)
endif()
message(STATUS "Building Muxer Server Plugin for ${LIB_FOLDER}")
# Set the locations of the various required files based on where you have deployed the muxer sdk
set( PROTOCOL_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/../protocol/include)
set( PROTOCOL_SRC_PATH ${CMAKE_CURRENT_LIST_DIR}/../protocol/src)
set( COMMON_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/../common/include)
set( COMMON_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/../common/lib)
set( SERVER_INCLUDE_PATH ${CMAKE_CURRENT_LIST_DIR}/include)
set( SERVER_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/lib)
set( SERVER_SRC_PATH ${CMAKE_CURRENT_LIST_DIR}/src)
find_library(MUXER-SERVER NAMES libmuxer-server.a PATHS ${SERVER_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-CAPNP NAMES libcapnp.a capnp.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-CAPNPJSON NAMES libcapnp-json.a capnp-json.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-CAPNPRPC NAMES libcapnp-rpc.a capnp-rpc.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-KJ NAMES libkj.a kj.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-KJTEST NAMES libkj-test.a kj-test.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-KJASYNC NAMES libkj-async.a kj-async.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-KJHTTP NAMES libkj-http.a kj-http.lib PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
find_library(MUXER-COMMON NAMES libaether_common.a PATHS ${COMMON_LIB_PATH}/${LIB_FOLDER} REQUIRED)
add_library(muxer-server-plugin
${PROTOCOL_SRC_PATH}/marshalling.cc
)
target_compile_features(muxer-server-plugin PUBLIC cxx_std_17)
target_compile_definitions(muxer-server-plugin PUBLIC WITHOUT_HADEAN_LOGGING)
target_include_directories(muxer-server-plugin
PUBLIC ${SERVER_INCLUDE_PATH}
PUBLIC ${PROTOCOL_INCLUDE_PATH}
PUBLIC ${COMMON_INCLUDE_PATH}
PUBLIC $ENV{HADEAN_SDK}/sdk/include
)
target_link_libraries(
muxer-server-plugin
${MUXER-SERVER}
${MUXER-CAPNP}
${MUXER-CAPNPJSON}
${MUXER-CAPNPRPC}
${MUXER-KJ}
${MUXER-KJTEST}
${MUXER-KJHTTP}
${MUXER-KJASYNC}
${MUXER-COMMON}
${HADEAN-LOGGER_LDFLAGS}
${MUXER-FMT}
)
Last modified 1yr ago