From 27857b0369b4787dde90d3542efe9f9673bc6161 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Mon, 9 Aug 2021 22:07:14 +0200 Subject: [PATCH] introduce some required cmake scripts --- cmake/3rdParty.cmake | 8 ++++++ cmake/3rdPartyTargets.cmake | 51 +++++++++++++++++++++++++++++++++++++ cmake/FindEuroScope.cmake | 49 +++++++++++++++++++++++++++++++++++ cmake/Protobuf.cmake | 51 +++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 cmake/3rdParty.cmake create mode 100644 cmake/3rdPartyTargets.cmake create mode 100644 cmake/FindEuroScope.cmake create mode 100644 cmake/Protobuf.cmake diff --git a/cmake/3rdParty.cmake b/cmake/3rdParty.cmake new file mode 100644 index 0000000..54e9190 --- /dev/null +++ b/cmake/3rdParty.cmake @@ -0,0 +1,8 @@ +# Author: +# Sven Czarnian +# License: +# GPLv3 +# Brief: +# Creates the 3rd-party targets + +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/3rdPartyTargets.cmake) diff --git a/cmake/3rdPartyTargets.cmake b/cmake/3rdPartyTargets.cmake new file mode 100644 index 0000000..5df5e79 --- /dev/null +++ b/cmake/3rdPartyTargets.cmake @@ -0,0 +1,51 @@ +# Author: +# Sven Czarnian +# License: +# GPLv3 +# Brief: +# Creates the 3rd-party import targets + +# include the external project library +INCLUDE(ExternalProject) + +# define the import target of libsodium +ADD_LIBRARY(libsodium STATIC IMPORTED) +IF (MSVC) + SET_TARGET_PROPERTIES(libsodium PROPERTIES + IMPORTED_IMPLIB_DEBUG "${CMAKE_SOURCE_DIR}/external/lib/libsodiumd.lib" + IMPORTED_IMPLIB_RELEASE "${CMAKE_SOURCE_DIR}/external/lib/libsodium.lib" + ) + TARGET_INCLUDE_DIRECTORIES(libsodium INTERFACE "${CMAKE_SOURCE_DIR}/external/include") +ELSE () + MESSAGE(FATAL_ERROR "Unsupported compiler") +ENDIF () + +# define the import target of libzmq +ADD_LIBRARY(libzmq STATIC IMPORTED) +ADD_DEPENDENCIES(libzmq libsodium) +IF (MSVC) + SET_TARGET_PROPERTIES(libzmq PROPERTIES + IMPORTED_IMPLIB_DEBUG "${CMAKE_SOURCE_DIR}/external/lib/libzmqd.lib" + IMPORTED_IMPLIB_RELEASE "${CMAKE_SOURCE_DIR}/external/lib/libzmq.lib" + ) + TARGET_INCLUDE_DIRECTORIES(libzmq INTERFACE "${CMAKE_SOURCE_DIR}/external/include") +ELSE () + MESSAGE(FATAL_ERROR "Unsupported compiler") +ENDIF () + +# define the import target of cppzmq +ADD_LIBRARY(cppzmq INTERFACE) +TARGET_INCLUDE_DIRECTORIES(cppzmq INTERFACE "${CMAKE_SOURCE_DIR}/external/include") +ADD_DEPENDENCIES(cppzmq libzmq) + +# define the import target of protobuf +ADD_LIBRARY(protobuf STATIC IMPORTED) +IF (MSVC) + SET_TARGET_PROPERTIES(protobuf PROPERTIES + IMPORTED_LOCATION_DEBUG "${CMAKE_INSTALL_PREFIX}/lib/libprotobufd.lib" + IMPORTED_LOCATION_RELEASE "${CMAKE_INSTALL_PREFIX}/lib/libprotobuf.lib" + ) + TARGET_INCLUDE_DIRECTORIES(protobuf INTERFACE "${CMAKE_INSTALL_PREFIX}/include") +ELSE () + MESSAGE(FATAL_ERROR "Unsupported compiler") +ENDIF () diff --git a/cmake/FindEuroScope.cmake b/cmake/FindEuroScope.cmake new file mode 100644 index 0000000..7f8db4d --- /dev/null +++ b/cmake/FindEuroScope.cmake @@ -0,0 +1,49 @@ +# Author: +# Sven Czarnian +# License: +# LGPLv3 +# Brief: +# Finds the EuroScope headers and libraries +# A target EuroScope will be created and the EuroScope_FOUND flag will be set + +IF(NOT TARGET EuroScope) + IF(NOT EuroScope_DIR) + MESSAGE(FATAL_ERROR "Please set EuroScope_DIR") + SET(EuroScope_DIR "EuroScope_DIR-NOTFOUND" CACHE PATH PARENT_SCOPE) + ENDIF() + + FIND_FILE(EuroScope_EXECUTABLE + NAMES + EuroScope.exe + PATHS + ${EuroScope_DIR} + ) + FIND_FILE(EuroScope_LIBRARY + NAMES + EuroScopePlugInDll.lib + PATHS + ${EuroScope_DIR}/PlugInEnvironment + ) + FIND_PATH(EuroScope_INCLUDE_DIR + NAMES + EuroScopePlugIn.h + PATHS + ${EuroScope_DIR}/PlugInEnvironment + ) + + IF(NOT ${EuroScope_EXECUTABLE} STREQUAL "EuroScope_EXECUTABLE-NOTFOUND" AND + NOT ${EuroScope_LIBRARY} STREQUAL "EuroScope_LIBRARY-NOTFOUND" AND + NOT ${EuroScope_INCLUDE_DIR} STREQUAL "EuroScope_INCLUDE_DIR-NOTFOUND") + MESSAGE(STATUS "Found EuroScope-library:") + MESSAGE(STATUS " ${EuroScope_LIBRARY}") + MESSAGE(STATUS "Found EuroScope-headers:") + MESSAGE(STATUS " ${EuroScope_INCLUDE_DIR}") + + ADD_LIBRARY(EuroScope INTERFACE IMPORTED GLOBAL) + TARGET_LINK_LIBRARIES(EuroScope INTERFACE ${EuroScope_LIBRARY}) + TARGET_INCLUDE_DIRECTORIES(EuroScope INTERFACE ${EuroScope_INCLUDE_DIR}) + SET(EuroScope_FOUND ON) + ENDIF() +ELSE() + MESSAGE(STATUS "EuroScope is already included.") +ENDIF() diff --git a/cmake/Protobuf.cmake b/cmake/Protobuf.cmake new file mode 100644 index 0000000..d4b1413 --- /dev/null +++ b/cmake/Protobuf.cmake @@ -0,0 +1,51 @@ +# Author: +# Sven Czarnian +# License: +# Closed Source +# Brief: +# Defines the protobuf functions + +# Brief: +# Proto-files are compiled into C++ files +# Parameters: +# PROTO_FILES - The proto-files with the message description +# SOURCE_FILES - Contains the filenames and paths of the generated files +FUNCTION(ProtobufCompile PROTO_FILES SOURCE_FILES) + SET(GENERATED_FILES "") + + FOREACH (PROTO ${PROTO_FILES}) + # get the relevant information to configure the protoc-run + GET_FILENAME_COMPONENT(FILENAME ${PROTO} NAME_WLE) + GET_FILENAME_COMPONENT(DIRECTORY ${PROTO} DIRECTORY) + + # define the output files + SET(CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/protobuf/${FILENAME}.pb.cc) + SET(HPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/protobuf/${FILENAME}.pb.h) + + # create the protoc-directory + FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protobuf) + + # define the protoc-command + ADD_CUSTOM_COMMAND( + OUTPUT ${CPP_FILE} ${HPP_FILE} + DEPENDS protobuf + COMMAND ${CMAKE_SOURCE_DIR}/external/bin/protoc.exe + ARGS -I=${DIRECTORY} --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/protobuf ${PROTO} + WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/bin" + COMMENT "Creating C++-sources for ${PROTO}" + ) + + # disable warnings + IF (MSVC) + SET_SOURCE_FILES_PROPERTIES(${CPP_FILE} PROPERTIES COMPILE_FLAGS "/wd4127 /wd5054 /wd4125 /wd4267") + SET_SOURCE_FILES_PROPERTIES(${HPP_FILE} PROPERTIES COMPILE_FLAGS "/wd4127 /wd5054 /wd4125 /wd4267") + ENDIF () + + # add the generated files + LIST(APPEND GENERATED_FILES ${CPP_FILE}) + LIST(APPEND GENERATED_FILES ${HPP_FILE}) + ENDFOREACH () + + # set the output variables + SET(${SOURCE_FILES} ${GENERATED_FILES} PARENT_SCOPE) +ENDFUNCTION()