From 772ec5a466d1f9315e924e2101f87b1fe29b2159 Mon Sep 17 00:00:00 2001 From: Peter M. Groen Date: Mon, 24 Jan 2022 22:43:13 +0100 Subject: [PATCH] Added cmake environment --- COPYING.OSDEV | 10 ++++++++++ FindGMock.cmake | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FindJsoncpp.cmake | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ FindYamlCpp.cmake | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ application.cmake | 38 ++++++++++++++++++++++++++++++++++++++ application.post_install.inc.cmake.in | 14 ++++++++++++++ application.post_uninstall.inc.cmake.in | 5 +++++ artifacts.cmake | 40 ++++++++++++++++++++++++++++++++++++++++ compiler.cmake | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.cmake.in | 22 ++++++++++++++++++++++ installation.cmake | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ld.so.conf.d.cmake.in | 1 + library.cmake | 34 ++++++++++++++++++++++++++++++++++ library.post_install.inc.cmake.in | 16 ++++++++++++++++ packaging.cmake | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ projectheader.cmake | 23 +++++++++++++++++++++++ qtmoc.cmake | 33 +++++++++++++++++++++++++++++++++ qtuic.cmake | 39 +++++++++++++++++++++++++++++++++++++++ service.cmake.in | 11 +++++++++++ sync.sh | 33 +++++++++++++++++++++++++++++++++ targetprops.cmake | 7 +++++++ 21 files changed, 985 insertions(+), 0 deletions(-) create mode 100644 COPYING.OSDEV create mode 100644 FindGMock.cmake create mode 100644 FindJsoncpp.cmake create mode 100644 FindYamlCpp.cmake create mode 100644 application.cmake create mode 100644 application.post_install.inc.cmake.in create mode 100644 application.post_uninstall.inc.cmake.in create mode 100644 artifacts.cmake create mode 100644 compiler.cmake create mode 100644 config.cmake.in create mode 100644 installation.cmake create mode 100644 ld.so.conf.d.cmake.in create mode 100644 library.cmake create mode 100644 library.post_install.inc.cmake.in create mode 100644 packaging.cmake create mode 100644 projectheader.cmake create mode 100644 qtmoc.cmake create mode 100644 qtuic.cmake create mode 100644 service.cmake.in create mode 100755 sync.sh create mode 100644 targetprops.cmake diff --git a/COPYING.OSDEV b/COPYING.OSDEV new file mode 100644 index 0000000..5c9da8c --- /dev/null +++ b/COPYING.OSDEV @@ -0,0 +1,10 @@ +Copyright (c) 2005-2019 by Open Systems Development B.V. + +Proprietry Software License + +All Rights Reserved +Copying is expressly prohibited. +All use strictly prohibited without express permission. + +Open Systems Development B.V. * http://www.osdev.nl + diff --git a/FindGMock.cmake b/FindGMock.cmake new file mode 100644 index 0000000..0e6d4c8 --- /dev/null +++ b/FindGMock.cmake @@ -0,0 +1,72 @@ +#.rst: +# FindGMock +# --------- +# +# Locate the Google C++ Mocking Framework. +# +# Defines the following variables: +# +# :: +# +# GMOCK_FOUND - Found the Google Testing framework +# GMOCK_INCLUDE_DIRS - Include directories +# +# +# +# Also defines the gmock source path +# +# :: +# +# GMOCK_SOURCE_DIR - directory containing the gmock sources +# +# +# +# Accepts the following variables as input: +# +# :: +# +# GMOCK_ROOT - (as a CMake or environment variable) +# The root directory of the gmock install prefix +# +# +# +# +# Example Usage: +# +# :: +# +# enable_testing() +# find_package(GMock REQUIRED) +# include_directories(${GMOCK_INCLUDE_DIRS}) +# +# +# +# :: +# +# add_executable(foo ${GMOCK_SOURCE_DIR}/gmock-all.cc foo.cc) +# target_link_libraries(foo) +# +# + +find_path(GMOCK_INCLUDE_DIR gmock/gmock.h + HINTS + $ENV{GMOCK_ROOT}/include + ${GMOCK_ROOT}/include +) +mark_as_advanced(GMOCK_INCLUDE_DIR) + +find_path(GMOCK_SOURCE_DIR gmock-all.cc + HINTS + $ENV{GMOCK_ROOT}/src/gmock + ${GMOCK_ROOT}/src/gmock + PATHS + ${GMOCK_INCLUDE_DIR}/../src/gmock +) +mark_as_advanced(GMOCK_SOURCE_DIR) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_INCLUDE_DIR GMOCK_SOURCE_DIR) + +if(GMOCK_FOUND) + set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR}) +endif() + diff --git a/FindJsoncpp.cmake b/FindJsoncpp.cmake new file mode 100644 index 0000000..b7338a5 --- /dev/null +++ b/FindJsoncpp.cmake @@ -0,0 +1,53 @@ +# Locate jsoncpp +# +# This module defines +# JSONCPP_FOUND, if false, do not try to link to jsoncpp +# JSONCPP_LIBRARY, where to find jsoncpp +# JSONCPP_INCLUDE_DIR, where to find json.h +# +# By default, the dynamic libraries of jsoncpp will be found. To find the static ones instead, +# you must set the JSONCPP_STATIC_LIBRARY variable to TRUE before calling find_package(Jsoncpp ...). +# +# If jsoncpp is not installed in a standard path, you can use the JSONCPP_DIR CMake variable +# to tell CMake where jsoncpp is. + +set(JSONCPP_FOUND 0) + +# attempt to find static library first if this is set +if(JSONCPP_STATIC_LIBRARY) + set(JSONCPP_STATIC libjsoncpp.a) +endif() + +# find the jsoncpp include directory +find_path(JSONCPP_INCLUDE_DIR json/json.h + PATHS + ~/Library/Frameworks/jsoncpp/include/ + /Library/Frameworks/jsoncpp/include/ + /usr/local/include/ + /usr/include/ + /sw/jsoncpp/ # Fink + /opt/local/jsoncpp/ # DarwinPorts + /opt/csw/jsoncpp/ # Blastwave + /opt/jsoncpp/ + ${JSONCPP_DIR}/include/ + PATH_SUFFIXES jsoncpp) + +# find the jsoncpp library +find_library(JSONCPP_LIBRARY + NAMES ${JSONCPP_STATIC} jsoncpp + PATH_SUFFIXES lib64 lib + PATHS ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ${JSONCPP_DIR}/lib) + +# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE if all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(JSONCPP DEFAULT_MSG JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) +mark_as_advanced(JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) +message("JSONCPP_FOUND = ${JSONCPP_FOUND}, includedir = ${JSONCPP_INCLUDE_DIR}, lib = ${JSONCPP_LIBRARY}") diff --git a/FindYamlCpp.cmake b/FindYamlCpp.cmake new file mode 100644 index 0000000..1ec9798 --- /dev/null +++ b/FindYamlCpp.cmake @@ -0,0 +1,50 @@ +# Locate yaml-cpp +# +# This module defines +# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp +# YAMLCPP_LIBRARY, where to find yaml-cpp +# YAMLCPP_INCLUDE_DIR, where to find yaml.h +# +# By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead, +# you must set the YAMLCPP_STATIC_LIBRARY variable to TRUE before calling find_package(YamlCpp ...). +# +# If yaml-cpp is not installed in a standard path, you can use the YAMLCPP_DIR CMake variable +# to tell CMake where yaml-cpp is. + +# attempt to find static library first if this is set +if(YAMLCPP_STATIC_LIBRARY) + set(YAMLCPP_STATIC libyaml-cpp.a) +endif() + +# find the yaml-cpp include directory +find_path(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks/yaml-cpp/include/ + /Library/Frameworks/yaml-cpp/include/ + /usr/local/include/ + /usr/include/ + /sw/yaml-cpp/ # Fink + /opt/local/yaml-cpp/ # DarwinPorts + /opt/csw/yaml-cpp/ # Blastwave + /opt/yaml-cpp/ + ${YAMLCPP_DIR}/include/) + +# find the yaml-cpp library +find_library(YAMLCPP_LIBRARY + NAMES ${YAMLCPP_STATIC} yaml-cpp + PATH_SUFFIXES lib64 lib + PATHS ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ${YAMLCPP_DIR}/lib) + +# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(YAMLCPP DEFAULT_MSG YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY) +mark_as_advanced(YAMLCPP_INCLUDE_DIR YAMLCPP_LIBRARY) diff --git a/application.cmake b/application.cmake new file mode 100644 index 0000000..9d509d8 --- /dev/null +++ b/application.cmake @@ -0,0 +1,38 @@ +# @brief Adds an executable target and performs related actions, +# such as verioning, binary dir and configuration. +# @note The default binary directory is PROJECT_BINARY_DIR, but can be overridden by specifying the ${PROJECT_NAME}_CURRENT_BINARY_DIR. +function(add_application) + +message( STATUS "${PROJECT_NAME} linking libraries : ${ARGN}") + +# Use PROJECT_BINARY_DIR by default, but override if necessary. +set(CURRENT_PROJECT_BINARY_DIR ${PROJECT_BINARY_DIR}) +if (${PROJECT_NAME}_CURRENT_BINARY_DIR) + set(CURRENT_PROJECT_BINARY_DIR ${${PROJECT_NAME}_CURRENT_BINARY_DIR}) +endif() +message(STATUS "CURRENT_PROJECT_BINARY_DIR : ${CURRENT_PROJECT_BINARY_DIR}") + +include_directories(${HSOA_VERSION_INCLUDE_DIR}) + +add_executable( ${PROJECT_NAME} + ${HSOA_VERSION_SRC_FILE} + ${SRC_LIST} +) + +target_link_libraries( ${PROJECT_NAME} + ${ARGN} +) + +set_target_properties( ${PROJECT_NAME} + PROPERTIES + VERSION ${PROJECT_VERSION} + RUNTIME_OUTPUT_DIRECTORY ${CURRENT_PROJECT_BINARY_DIR}/bin +) + +# Copy the testconfig to the build dir, so the binaries are testable from the build dir. +# The created packages will not contain the testconfig but the production config instead. See installation.cmake. +if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/testconfig/) + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/testconfig/" DESTINATION "${CURRENT_PROJECT_BINARY_DIR}/etc") +endif() + +endfunction() diff --git a/application.post_install.inc.cmake.in b/application.post_install.inc.cmake.in new file mode 100644 index 0000000..448a8d1 --- /dev/null +++ b/application.post_install.inc.cmake.in @@ -0,0 +1,14 @@ +# Make sure the mLogic group exists +MLOGIC_GROUP=mlogic +groupadd --force $MLOGIC_GROUP +# Create the user +appuserid=$(id -u @PROJECT_NAME@) +if [ ! $appuserid ] ; then + useradd --groups $MLOGIC_GROUP --no-create-home @PROJECT_NAME@ +fi +# Prevent direct login +passwd --lock @PROJECT_NAME@ +# Change group ownership of log folder +chgrp $MLOGIC_GROUP @PROJCOMP_LOG_INSTALL_DIR@ +# Change group ownership of run folder +chgrp $MLOGIC_GROUP @PROJCOMP_RUN_INSTALL_DIR@ diff --git a/application.post_uninstall.inc.cmake.in b/application.post_uninstall.inc.cmake.in new file mode 100644 index 0000000..8811e65 --- /dev/null +++ b/application.post_uninstall.inc.cmake.in @@ -0,0 +1,5 @@ +# Remove the user +appuserid=$(id -u @PROJECT_NAME@) +if [ $appuserid ] ; then + userdel --remove --force @PROJECT_NAME@ +fi diff --git a/artifacts.cmake b/artifacts.cmake new file mode 100644 index 0000000..6f541b8 --- /dev/null +++ b/artifacts.cmake @@ -0,0 +1,40 @@ +# @brief Tries to find the module with find_package, and uses CMAKE_INSTALL_PREFIX (see documentation). +# If the module can't be found, includes the directory by the specified module path. +# @param module The name of the module on which a dependency is added +# @param modulepath The relative path of the module wrt the current project +# @param moduleincludepath [optional] The relative path to the include directory +# @note Needs to be a macro because of the scope of the variables that are set by find_package. +macro(depend_module module modulepath) + message(STATUS "module : ${module}") + message(STATUS "modulepath : ${modulepath}") + + set ( optional_macro_args ${ARGN} ) + list ( LENGTH optional_macro_args num_optional_args ) + if ( ${num_optional_args} GREATER 0 ) + list ( GET optional_macro_args 0 moduleincludepath ) + else() + set ( moduleincludepath include ) + endif() + message(STATUS "moduleincludepath : ${moduleincludepath}") + + find_package(${module} CONFIG QUIET) + message( STATUS "${module}_FOUND: ${${module}_FOUND}" ) + + string( TOUPPER ${module} MODULE_NAME_UPPER ) + + # check if the constructed variable name exists and if so check also the content. + if ( NOT ${${module}_FOUND} ) + if ( NOT TARGET ${module} ) + message( STATUS "Adding subdirectory ${modulepath}/${module} as subdirectory ${CMAKE_CURRENT_LIST_DIR}/staging/${module}." ) + add_subdirectory(${modulepath}/${module} staging/${module}) + endif() + + set( ${MODULE_NAME_UPPER}_INCLUDE_DIR ${modulepath}/${module}/${moduleincludepath} CACHE STRING "${module} include path" FORCE ) + set( ${MODULE_NAME_UPPER}_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE STRING "${module} library path" FORCE ) + set( ${MODULE_NAME_UPPER}_LIB_NAME "${module}" CACHE STRING "${module} library name" FORCE ) + endif() + + message( STATUS "${MODULE_NAME_UPPER}_INCLUDE_DIR: ${${MODULE_NAME_UPPER}_INCLUDE_DIR}" ) + message( STATUS "${MODULE_NAME_UPPER}_LIB_DIR: ${${MODULE_NAME_UPPER}_LIB_DIR}" ) + message( STATUS "${MODULE_NAME_UPPER}_LIB_NAME: ${${MODULE_NAME_UPPER}_LIB_NAME}" ) +endmacro() diff --git a/compiler.cmake b/compiler.cmake new file mode 100644 index 0000000..79198c3 --- /dev/null +++ b/compiler.cmake @@ -0,0 +1,211 @@ +include(CheckCXXCompilerFlag) + +set(PLATFORM_RELEASE "") +function(platformRelease) + set(PR, "") + execute_process(COMMAND /bin/bash -c "if [ -e /etc/redhat-release ]; then cat /etc/redhat-release | tr -d '\n'; fi" OUTPUT_VARIABLE PR) + message(STATUS "Platform is ${PR}") + set(PLATFORM_RELEASE "${PR}" PARENT_SCOPE) +endfunction(platformRelease) + +# The target architecture (-march, -mtune) is assumed to be the architecture that was used to build gcc. +# If cross-compilation is required, this should be specified as cmake arguments. + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshadow" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Woverloaded-virtual -Winit-self -Wuninitialized -Wunused -Wcast-qual" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type" ) + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-noexcept-type" ) +endif() + +if(CMAKE_COMPILER_IS_GNUCC + AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9 + AND NOT APPLE) + # Mac OSX doesn't seem to honour -isystem, so not for Mac. + # Also, GCC 4.8 complains about boost + MESSAGE(STATUS "Don't treat warnings as errors") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" ) +endif() +if(BUILD_WITH_PROFILING) + message(STATUS "Profiling enabled") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg" ) +else() + message(STATUS "Profiling disabled") +endif() + +# Allow linking into a dynamic library +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" ) + +# Use RelWithDebInfo as default build type +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo") +endif() +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + +if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(NOASSERTS 1) # Disable asserts as well + # -O3 causes weird crashes on win32 so we force -O2 for release builds also for linux builds + string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + if(MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s") + endif() +else() + # Let Qt track the use of QSharedPointer + set(CMAKE_CXX_CFLAGS "${CMAKE_CXX_FLAGS} -DQT_SHAREDPOINTER_TRACK_POINTERS") + # If we're debugging, remove -O2 completely + string(REGEX REPLACE "-O2" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REGEX REPLACE "-O2" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REGEX REPLACE "-O2" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + string(REGEX REPLACE "-O2" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") +endif() + +# Disable asserts with -DNOASSERTS=1 as a CMake command-line parameter +if(NOASSERTS) + add_definitions(-DQT_NO_DEBUG) + add_definitions(-DNDEBUG) + message(STATUS "Asserts have been disabled") +endif(NOASSERTS) + +if(APPLE) + # AVX instructions currently cause assembler errors, so disabling them + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -mno-avx -mmacosx-version-min=10.7 -stdlib=libc++ ") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -mno-avx -mmacosx-version-min=10.7") +endif(APPLE) + +if(UNIX) + if(BUILD_WITH_COVERAGE) + # Specifically enable coverate info, since ccache can't cache with + # profiling enabled, seriously hurting build-times in Debug-mode + message(STATUS "Generate coverage info") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") + if (NOT TARGET RemoveGCDA) + add_custom_target(RemoveGCDA ALL + COMMAND find . -name "*.gcda" -delete + COMMENT "Removing gcda files") + endif(NOT TARGET RemoveGCDA) + + if(NOT NOASSERTS) + add_definitions(-DQT_SHAREDPOINTER_TRACK_POINTERS) + endif(NOT NOASSERTS) + else() + message(STATUS "Building without coverage info") + endif() +endif(UNIX) + +if(UNIX AND NOT APPLE) + # needed for making qwt happy + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt" ) +endif(UNIX AND NOT APPLE) + +if(MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows" ) +endif(MINGW) + +CHECK_CXX_COMPILER_FLAG( -fstack-protector-all result ) +if(result) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") +endif(result) + +CHECK_CXX_COMPILER_FLAG( -fthreadsafe-statics THREADSAFE_RESULT) +if( NOT THREADSAFE_RESULT) + message(FATAL_ERROR, "Compiler does not support threadsafe statics variables in methods") +endif() +# We use static variables in method scope, they must be threadsafe, this is on by default since gcc 4 but this flag is a check +# If the compiler does not support this then build will fail. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fthreadsafe-statics") + +if(CMAKE_COMPILER_IS_GNUCXX) + # Check on which architecture we are. ARM doesn't support mfpmath + if(CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse" ) + endif() + + # -std=c++11 will be supported starting GCC 4.7, older versions need c++0x + CHECK_CXX_COMPILER_FLAG( -std=c++11 cxxresult ) + + if( NOT cxxresult) + message(FATAL_ERROR, "Compiler does not support c++11") + endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + + # -Wzero-as-null-pointer-constant is disabled for now, since the Qt 4.8.4 + # macro's produce a bucketload of these warnings. Might be useful later on. +# CHECK_CXX_COMPILER_FLAG( -Wzero-as-null-pointer-constant cxxresult ) +# if(cxxresult) +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant") +# endif(cxxresult) + # Leave out deprecation warnings, mostly generated by CppUnit + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") + +endif(CMAKE_COMPILER_IS_GNUCXX) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + MESSAGE(STATUS "Enabling Clang flags") + # We enable all warnings and disable what we don't need + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything") + # Warns if items need to be re-aligned to 4-byte boundaries. Since we use + # booleans in our code, these warnings are all over the place. If + # memory-usage becomes an issue, we can pack all booleans together using + # this warning. However, it's currently not practical to eliminate them all. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-padded") + # We use a lot of static objects, which get cleaned up at exit by their destructors. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-exit-time-destructors") + # Static objects tend to have global constructors + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-global-constructors") + # We mix int / unsigned int a lot, so disabled it for the moment + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-conversion") + # Warning caused by the Qt translations + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-prototypes") + # We standardize on C++11, so don't bother us with C++98 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic") + # We explicitly want to use the switch(){default: break;} construction + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum") + # Q_OBJECT does an "int i = i;"... + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-self-assign") + # Compile for C++11 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + # Don't complain about unused arguments, since this also triggers warnings + # about include-directories that are unused... + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") + # Don't complain about fall-throughs in switch/case statements + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-fallthrough") + # Since "Q_ASSERT(false)" creates a not of noise, disable it when asserts are active + if(NOT NOASSERTS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unreachable-code") + endif(NOT NOASSERTS) + # There is no way to avoid this warning right now, so we disable it + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-template-vtables") + # Warning caused by Qt resource files, so disabling it + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-variable-declarations") + # WORKAROUND: Somehow Qt forgets that Clang is a C++11 compiler + ADD_DEFINITIONS("-DQ_COMPILER_INITIALIZER_LISTS") + # Clang 3.3 doesn't know Doxygens' "\test" and "\retval" tags, so disabling + # check for unknown tags for now + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-documentation-unknown-command") + + if(CMAKE_CXX_COMPILER_VERSION MATCHES "3\\.4\\.2") + message(STATUS "compiler is clang version 3.4.2") + platformRelease() + if("${PLATFORM_RELEASE}" MATCHES "CentOS Linux release 7\\.2\\..+") + # Override the gnu minor version only for this specific combination of platform and clang version + set(CMAKE_CXX_FLAGS "-U__GNUC_MINOR__ -D__GNUC_MINOR__=3 ${CMAKE_CXX_FLAGS}") + message(STATUS "Overriding clang gnu minor version to 3 so that several libstd c++11 features like tuple can be used") + endif("${PLATFORM_RELEASE}" MATCHES "CentOS Linux release 7\\.2\\..+") + endif(CMAKE_CXX_COMPILER_VERSION MATCHES "3\\.4\\.2") +endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + +if(APPLE) + set(WHOLE_ARCHIVE_ON "-all_load") + set(WHOLE_ARCHIVE_OFF "") +else() + set(WHOLE_ARCHIVE_ON "-Wl,-whole-archive") + set(WHOLE_ARCHIVE_OFF "-Wl,-no-whole-archive") +endif() diff --git a/config.cmake.in b/config.cmake.in new file mode 100644 index 0000000..161ab72 --- /dev/null +++ b/config.cmake.in @@ -0,0 +1,22 @@ +@PACKAGE_INIT@ + +string( TOUPPER @PROJECT_NAME@ PROJECT_NAME_UPPER ) + +string( CONCAT MY_PACKAGE_INCLUDE_DIR ${PROJECT_NAME_UPPER} "_INCLUDE_DIR" ) +set_and_check(${MY_PACKAGE_INCLUDE_DIR} "@PACKAGE_PROJCOMP_INCLUDE_INSTALL_DIR@") +message( STATUS "${MY_PACKAGE_INCLUDE_DIR}: ${${MY_PACKAGE_INCLUDE_DIR}}" ) + +string( CONCAT MY_PACKAGE_LIB_DIR ${PROJECT_NAME_UPPER} "_LIB_DIR" ) +set_and_check(${MY_PACKAGE_LIB_DIR} "@PACKAGE_PROJCOMP_LIB_INSTALL_DIR@") +message( STATUS "${MY_PACKAGE_LIB_DIR}: ${${MY_PACKAGE_LIB_DIR}}" ) + +string( CONCAT MY_PACKAGE_CMAKE_DIR ${PROJECT_NAME_UPPER} "_CMAKE_DIR" ) +set_and_check(${MY_PACKAGE_CMAKE_DIR} "@PACKAGE_PROJCOMP_CMAKE_INSTALL_DIR@") +message( STATUS "${MY_PACKAGE_CMAKE_DIR}: ${${MY_PACKAGE_CMAKE_DIR}}" ) + +string( CONCAT MY_PACKAGE_LIB_NAME ${PROJECT_NAME_UPPER} "_LIB_NAME" ) +set(${MY_PACKAGE_LIB_NAME} "@PROJECT_NAME@") +message( STATUS "${MY_PACKAGE_LIB_NAME}: ${${MY_PACKAGE_LIB_NAME}}" ) + +check_required_components("@PROJECT_NAME@") +#message( STATUS "@PROJECT_NAME@_FOUND: ${${@PROJECT_NAME@}_FOUND}" ) diff --git a/installation.cmake b/installation.cmake new file mode 100644 index 0000000..ce38a18 --- /dev/null +++ b/installation.cmake @@ -0,0 +1,192 @@ +set( INSTALLATION_CURRENT_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR} ) + +# Layout +set(USR_LOCAL_DIR "/usr/local" CACHE STRING "" FORCE) +set(LD_SO_CONF_D_DIR "/etc/ld.so.conf.d" CACHE STRING "" FORCE) +set(SYSTEMD_CONFIG_DIR "/etc/systemd/system" CACHE STRING "" FORCE) +set(VAR_LOG_DIR "/var/log" CACHE STRING "" FORCE) +set(VAR_RUN_DIR "/var/run" CACHE STRING "" FORCE) +set(PROJCOMP_LOG_INSTALL_DIR "${VAR_LOG_DIR}/${PROJECT_NAME}") +set(PROJCOMP_RUN_INSTALL_DIR "${VAR_RUN_DIR}/${PROJECT_NAME}") +set(PROJCOMP_BIN_INSTALL_DIR "${PROJECT_NAME}/bin") +set(PROJCOMP_LIB_INSTALL_DIR "lib") +set(PROJCOMP_INCLUDE_INSTALL_DIR "${PROJECT_NAME}/include") +set(PROJCOMP_ETC_INSTALL_DIR "${PROJECT_NAME}/etc") +set(PROJCOMP_CMAKE_INSTALL_DIR "${PROJECT_NAME}/cmake") +set(PROJCOMP_COMPONENT_NAME "${REPOSITORY_PACKAGE_NAME}-${PROJECT_NAME}") +set(PROJCOMP_COMPONENT_NAME_DEVEL "${PROJCOMP_COMPONENT_NAME}-devel") + +# @brief Installs a library component and performs related actions. +function(install_component) + +set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") + +# Configuration +string(TOLOWER ${PROJECT_NAME} MODULE_NAME_LOWER) +set(PROJECT_CONFIG "${GENERATED_DIR}/${MODULE_NAME_LOWER}-config.cmake") + +# Generate the cmake config file +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${INSTALLATION_CURRENT_CMAKE_DIR}/config.cmake.in" + "${PROJECT_CONFIG}" + INSTALL_DESTINATION "${PROJCOMP_CMAKE_INSTALL_DIR}" + PATH_VARS PROJCOMP_INCLUDE_INSTALL_DIR PROJCOMP_LIB_INSTALL_DIR PROJCOMP_CMAKE_INSTALL_DIR +) + +# Install license file +if (EXISTS "${INSTALLATION_CURRENT_CMAKE_DIR}/COPYING.OSDEV") + install( + FILES "${INSTALLATION_CURRENT_CMAKE_DIR}/COPYING.OSDEV" + DESTINATION ${PROJCOMP_LIB_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" + ) +endif() + +# Install targets +install( + TARGETS ${PROJECT_NAME} + DESTINATION ${PROJCOMP_LIB_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" +) + +# Configure and install dynamic linker runtime bindings (ld.so.conf.d file) +configure_file( + "${INSTALLATION_CURRENT_CMAKE_DIR}/ld.so.conf.d.cmake.in" + "${GENERATED_DIR}/${PROJECT_NAME}.conf" +) +install( + FILES "${GENERATED_DIR}/${PROJECT_NAME}.conf" + DESTINATION ${LD_SO_CONF_D_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" +) + +# Configure and set cpack post install script +configure_file( + "${INSTALLATION_CURRENT_CMAKE_DIR}/library.post_install.inc.cmake.in" + "${GENERATED_DIR}/library.post_install.inc" +) +# Set the per-component post install script file. +set(CPACK_RPM_${PROJCOMP_COMPONENT_NAME}_POST_INSTALL_SCRIPT_FILE "${GENERATED_DIR}/library.post_install.inc" CACHE STRING "${PROJECT_NAME} post_install script" FORCE) + +# Headers +# At the moment, we anticipate the headers to be located according to either 1) or 2). + +# 1) Apply glob style pattern for those projects that have the header files in the root folder of the repository (such as opcua_model). +file (GLOB PACKAGE_HEADERS "${CMAKE_CURRENT_LIST_DIR}/*.h*") +install( + FILES ${PACKAGE_HEADERS} + DESTINATION ${PROJCOMP_INCLUDE_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME_DEVEL}" +) +# 2) Copy the include dir for those projects that have the header files in include/mlogic (such as opc_utils). +if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/include/mlogic) + install( + DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/mlogic + DESTINATION ${PROJCOMP_INCLUDE_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME_DEVEL}" + ) +endif() + +# Install cmake project config +install( + FILES ${PROJECT_CONFIG} + DESTINATION ${PROJCOMP_CMAKE_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME_DEVEL}" +) + +# The -devel package depends on the runtime package +set(CPACK_RPM_${PROJCOMP_COMPONENT_NAME_DEVEL}_PACKAGE_REQUIRES "${PROJCOMP_COMPONENT_NAME} = ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}-${CURRENT_PROJECT_VERSION_RELEASENR}" CACHE STRING "${PROJCOMP_COMPONENT_NAME_DEVEL} dependency" FORCE ) +# Clear the dependencies for the runtime package, as cpack erroneously added unexpected dependencies (hints towards the previously built package) +set(CPACK_RPM_${PROJCOMP_COMPONENT_NAME}_PACKAGE_REQUIRES "" CACHE STRING "${PROJCOMP_COMPONENT_NAME} dependencies" FORCE ) + +endfunction() + +# @brief Installs the executable binary and related items +# (such as systemd service files, log folder, post [un]install scripts) +# @param INSTALL_SYSTEMD_SERVICE [optional] Boolean to indicate whether the systemd unit files must be installed. Optional. The default is ON. +function(install_application) + +set ( optional_macro_args ${ARGN} ) +list ( LENGTH optional_macro_args num_optional_args ) +if ( ${num_optional_args} GREATER 0 ) + list ( GET optional_macro_args 0 INSTALL_SYSTEMD_SERVICE ) +endif() + +if(NOT DEFINED INSTALL_SYSTEMD_SERVICE) + set(INSTALL_SYSTEMD_SERVICE "ON") +endif() + +message(STATUS "INSTALL_SYSTEMD_SERVICE: ${INSTALL_SYSTEMD_SERVICE}") + +set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") + +# Install license file +if (EXISTS "${INSTALLATION_CURRENT_CMAKE_DIR}/COPYING.OSDEV") + install( + FILES "${INSTALLATION_CURRENT_CMAKE_DIR}/COPYING.OSDEV" + DESTINATION ${PROJCOMP_BIN_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" + ) +endif() + +# Install binary file +install( + TARGETS ${PROJECT_NAME} + DESTINATION ${PROJCOMP_BIN_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" +) + +# Install configuration +if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/config/) + install( + DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/config/ + DESTINATION ${PROJCOMP_ETC_INSTALL_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" + ) +endif() + +if (INSTALL_SYSTEMD_SERVICE STREQUAL "ON") + # Configure and install systemd unit file + configure_file( + "${INSTALLATION_CURRENT_CMAKE_DIR}/service.cmake.in" + "${GENERATED_DIR}/${PROJECT_NAME}.service" + ) + install( + FILES "${GENERATED_DIR}/${PROJECT_NAME}.service" + DESTINATION ${SYSTEMD_CONFIG_DIR} + COMPONENT "${PROJCOMP_COMPONENT_NAME}" + ) +endif() + +# Install log folder +install( + DIRECTORY + DESTINATION ${PROJCOMP_LOG_INSTALL_DIR} + DIRECTORY_PERMISSIONS + OWNER_WRITE OWNER_READ OWNER_EXECUTE + GROUP_WRITE GROUP_READ GROUP_EXECUTE SETGID + # No permissions for WORLD + COMPONENT "${PROJCOMP_COMPONENT_NAME}" +) + +# Install run folder +install( + DIRECTORY + DESTINATION ${PROJCOMP_RUN_INSTALL_DIR} + DIRECTORY_PERMISSIONS + OWNER_WRITE OWNER_READ OWNER_EXECUTE + GROUP_WRITE GROUP_READ GROUP_EXECUTE + # No permissions for WORLD + COMPONENT "${PROJCOMP_COMPONENT_NAME}" +) + +# Configure and set cpack post install script +configure_file( + "${INSTALLATION_CURRENT_CMAKE_DIR}/application.post_install.inc.cmake.in" + "${GENERATED_DIR}/application.post_install.inc" +) +# Set the per-component post install script file. +set(CPACK_RPM_${PROJCOMP_COMPONENT_NAME}_POST_INSTALL_SCRIPT_FILE "${GENERATED_DIR}/application.post_install.inc" CACHE STRING "${PROJECT_NAME} post_install script" FORCE) + +endfunction() diff --git a/ld.so.conf.d.cmake.in b/ld.so.conf.d.cmake.in new file mode 100644 index 0000000..3aee369 --- /dev/null +++ b/ld.so.conf.d.cmake.in @@ -0,0 +1 @@ +@CMAKE_INSTALL_PREFIX@/@PROJCOMP_LIB_INSTALL_DIR@/ diff --git a/library.cmake b/library.cmake new file mode 100644 index 0000000..1afa245 --- /dev/null +++ b/library.cmake @@ -0,0 +1,34 @@ +# @brief Adds a single shared library target and performs related actions, +# such as target properties, hsoa versioning, and some packaging variables. +# @note The default binary directory is CMAKE_BINARY_DIR, but can be overridden by specifying the ${PROJECT_NAME}_CURRENT_BINARY_DIR. +function(add_libraries) + +message( STATUS "${PROJECT_NAME} linking libraries : ${ARGN}") + +# Use CMAKE_BINARY_DIR by default, but override if necessary. +set(CURRENT_PROJECT_BINARY_DIR ${CMAKE_BINARY_DIR}) +if (${PROJECT_NAME}_CURRENT_BINARY_DIR) + set(CURRENT_PROJECT_BINARY_DIR ${${PROJECT_NAME}_CURRENT_BINARY_DIR}) +endif() +message(STATUS "CURRENT_PROJECT_BINARY_DIR : ${CURRENT_PROJECT_BINARY_DIR}") + +include_directories(${HSOA_VERSION_INCLUDE_DIR}) + +add_library( ${PROJECT_NAME} SHARED + ${HSOA_VERSION_SRC_FILE} + ${SRC_LIST} +) + +target_link_libraries( ${PROJECT_NAME} + ${ARGN} +) + +set_target_properties( ${PROJECT_NAME} + PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} + LIBRARY_OUTPUT_DIRECTORY ${CURRENT_PROJECT_BINARY_DIR}/lib + ARCHIVE_OUTPUT_DIRECTORY ${CURRENT_PROJECT_BINARY_DIR}/archive +) + +endfunction() diff --git a/library.post_install.inc.cmake.in b/library.post_install.inc.cmake.in new file mode 100644 index 0000000..6bdc1cc --- /dev/null +++ b/library.post_install.inc.cmake.in @@ -0,0 +1,16 @@ +# Update the dynamic linker runtime bindings. +VAR1="/sbin/ldconfig" +VAR2=`which ldconfig` + +if [ -e $VAR1 ]; then + $VAR1 +elif [ ! -z $VAR2 ]; then + $VAR2 +else + VAR3=`find / -name ldconfig -type f` + if [ -e $VAR3 ]; then + $VAR3 + else + echo "ldconfig not found!!!" + fi +fi diff --git a/packaging.cmake b/packaging.cmake new file mode 100644 index 0000000..cfef30e --- /dev/null +++ b/packaging.cmake @@ -0,0 +1,81 @@ +set( PACKAGING_CURRENT_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR} ) + +# @brief Creates component packages. Can be executed by calling "make package". +function(package_component) + +# Determine build architecture +execute_process( + COMMAND uname -m + COMMAND tr -d '\n' + OUTPUT_VARIABLE ARCHITECTURE +) + +# Set package name +# Known issue: Due to the way cpack works (only evaluated once), the PROJECT_NAME will be the last package to +# call this function. We worked around this by including packaging.cmake only from 1 location in the repository. +# However, in a superbuild (i.e. from an mlogic parent directory building all repositories at once), +# this will yield an erroneous package name (usually datacollector, as that is the last project to be evaluated). +# In order to prevent dynamic package names caused by different build directories, +# The package name is set to a fixed value. The actual name of the rpm and package will be determined by +# other variable values such as the component name and version, leading to uniquely identifiable packages. +set(CPACK_PACKAGE_NAME osdev) + +# Set package version numbers +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +# The release number is not part of CPACK_PACKAGE_VERSION and is dealt with seperately (see below) +set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +message( STATUS "Packaging ${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION} for ${ARCHITECTURE}.") + +set(CPACK_PACKAGE_RELEASE "1") +if (CURRENT_PROJECT_VERSION_RELEASENR) + set(CPACK_PACKAGE_RELEASE ${CURRENT_PROJECT_VERSION_RELEASENR}) +endif() + +# Build CPack driven installer packages +include(InstallRequiredSystemLibraries) + +# This doesn't seem to work, only the specific archive variables (_RPM_, _DEB_) seem to work +#set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_IGNORE_GROUPS 1) +# Enable the line below if the repository being built has only 1 target that's installed +# (No longer necessary, as we now have at least 2 components: runtime and development components.) +#set(CPACK_COMPONENTS_ALL ${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_NAME}-devel) + +# Enable DESTDIR and copy CMAKE_INSTALL_PREFIX, which requires disabling rpm relocatability +set(CPACK_SET_DESTDIR 1) +set(CPACK_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) +set(CPACK_PACKAGE_RELOCATABLE OFF) + +# Set package metadata +if (EXISTS "${PACKAGING_CURRENT_CMAKE_DIR}/../../../COPYING.OSDEV") + set(CPACK_RESOURCE_FILE_LICENSE "${PACKAGING_CURRENT_CMAKE_DIR}/../../../COPYING.OSDEV") +endif() +if (EXISTS "${PACKAGING_CURRENT_CMAKE_DIR}/../../../README.md") + set(CPACK_RESOURCE_FILE_README "${PACKAGING_CURRENT_CMAKE_DIR}/../../../README.md") +endif() +set(CPACK_SYSTEM_NAME "${ARCHITECTURE}") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CURRENT_PROJECT_VERSION_LETTER}-${CPACK_PACKAGE_RELEASE}.${ARCHITECTURE}") + +# RPM specific fields +set(CPACK_RPM_PACKAGE_ARCHITECTURE "${ARCHITECTURE}") +set(CPACK_RPM_COMPONENT_INSTALL ON) +set(CPACK_RPM_PACKAGE_GROUP "${CPACK_PACKAGE_NAME}-${REPOSITORY_PACKAGE_NAME}") +# Unfortunately, CPACK_RPM_PACKAGE_RELEASE isn't inherited from CPACK_PACKAGE_RELEASE automatically. +set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE}) +set(CPACK_RPM_PACKAGE_VENDOR ${CURRENT_PROJECT_MANUFACTURER_CODE}) +set(CPACK_RPM_PACKAGE_SUMMARY "${CPACK_PACKAGE_NAME} package") +set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_RPM_PACKAGE_SUMMARY}") +set(CPACK_RPM_PACKAGE_LICENSE "${CURRENT_PROJECT_MANUFACTURER_CODE}") + +# Select CPack generators +set(CPACK_GENERATOR "RPM") + +# Exclude certain system directories from the rpm +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr;/etc;/etc/systemd;/var;${USR_LOCAL_DIR};${LD_SO_CONF_D_DIR};${SYSTEMD_CONFIG_DIR};${VAR_LOG_DIR};${VAR_RUN_DIR}) + +# This line should come last +include(CPack) + +endfunction(package_component) diff --git a/projectheader.cmake b/projectheader.cmake new file mode 100644 index 0000000..83df340 --- /dev/null +++ b/projectheader.cmake @@ -0,0 +1,23 @@ +# @brief Defines the project name, version and binary dir. +# @param CURRENT_PROJECT_NAME The name of the project to define. +# @param CURRENT_PROJECT_BINARY_DIR [optional] Override for the default project binary dir (PROJECT_BINARY_DIR for executables, CMAKE_BINARY_DIR for libraries). +macro ( project_header CURRENT_PROJECT_NAME ) + +message( STATUS "" ) +message( STATUS "================================================================" ) +message( STATUS "Creating Makefile of ${CURRENT_PROJECT_NAME}" ) +message( STATUS "================================================================" ) +message( STATUS "CURRENT_PROJECT_VERSION: ${CURRENT_PROJECT_VERSION}" ) + +project(${CURRENT_PROJECT_NAME} VERSION ${CURRENT_PROJECT_VERSION}) +set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_NO_CYCLES 1) + +set ( optional_macro_args ${ARGN} ) +list ( LENGTH optional_macro_args num_optional_args ) +if ( ${num_optional_args} GREATER 0 ) + # Set project binary dir override to the specified value + list ( GET optional_macro_args 0 CURRENT_PROJECT_BINARY_DIR ) + set ( ${PROJECT_NAME}_CURRENT_BINARY_DIR ${CURRENT_PROJECT_BINARY_DIR} CACHE STRING "${PROJECT_NAME} binary dir" FORCE ) +endif() + +endmacro() diff --git a/qtmoc.cmake b/qtmoc.cmake new file mode 100644 index 0000000..d6c31fc --- /dev/null +++ b/qtmoc.cmake @@ -0,0 +1,33 @@ +# @brief Creates the qt5 mocs for the specified header files. +# @param SRC_LIST The current source list of the project, to which to add the created moc files. +# @param MOC_LIST The list of header files for which to create qt5 mocs. +macro(create_mocs SRC_LIST MOC_LIST) + +message( STATUS "${PROJECT_NAME} Creating mocs for: ${ARGN}") + +set( MOCABLE_LIST + ${ARGN} +) + +# Empty the MOC_LIST variable +set( ${MOC_LIST} +) + +# Create the MOC_LIST +QT5_WRAP_CPP( ${MOC_LIST} ${MOCABLE_LIST} ) + +# Append SRC_LIST with MOC_LIST +list ( APPEND SRC_LIST + ${${MOC_LIST}} +) + +message( STATUS "${PROJECT_NAME} MOC_LIST: ${${MOC_LIST}}") +message( STATUS "${PROJECT_NAME} SRC_LIST: ${${SRC_LIST}}") + +set_source_files_properties( + ${${MOC_LIST}} + PROPERTIES + COMPILE_FLAGS -Wno-undefined-reinterpret-cast +) + +endmacro() diff --git a/qtuic.cmake b/qtuic.cmake new file mode 100644 index 0000000..8e3bf21 --- /dev/null +++ b/qtuic.cmake @@ -0,0 +1,39 @@ +# @brief Creates the qt5 ui_ headers for the specified designer files. +# @param SRC_LIST The current source list of the project, to which to add the created moc files. +# @param UIC_LIST The list of designer files for which to create qt5 headers. +macro(create_ui SRC_LIST UIC_LIST) + +message( STATUS "${PROJECT_NAME} Creating headers for: ${ARGN}") + +set( UICABLE_LIST + ${ARGN} +) + +# Empty the UIC_LIST variable +set( ${UIC_LIST} +) + +# Create the UIC_LIST +QT5_WRAP_UI( ${UIC_LIST} ${UICABLE_LIST} ) + +# Append SRC_LIST with UIC_LIST +list ( APPEND SRC_LIST + ${${UIC_LIST}} +) + +# Avoid warnings by including a generated header file. +include_directories( ${SYSTEMORNOT} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR} +) + +message( STATUS "${PROJECT_NAME} UIC_LIST: ${${UIC_LIST}}") +message( STATUS "${PROJECT_NAME} SRC_LIST: ${${SRC_LIST}}") + +set_source_files_properties( + ${${UIC_LIST}} + PROPERTIES + COMPILE_FLAGS -Wno-undefined-reinterpret-cast +) + +endmacro() diff --git a/service.cmake.in b/service.cmake.in new file mode 100644 index 0000000..1193cc8 --- /dev/null +++ b/service.cmake.in @@ -0,0 +1,11 @@ +[Unit] +Description=Mlogic @PROJECT_NAME@ +After=network.target + +[Service] +WorkingDirectory=@CMAKE_INSTALL_PREFIX@/@PROJECT_NAME@/ +ExecStart=@CMAKE_INSTALL_PREFIX@/@PROJCOMP_BIN_INSTALL_DIR@/@PROJECT_NAME@ +User=@PROJECT_NAME@ + +[Install] +WantedBy=multi-user.target diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..a921bb0 --- /dev/null +++ b/sync.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# $1: cmake-file-filename +function sync-file() +{ + echo ---------- Syncing $1 started + + cp -f ../../mlogic_support/cmake/$1 $1 + if [ $? -ne 0 ] ; then + echo ---------- Syncing $1 failed + return 1 + fi + + echo ---------- Syncing $1 finished +} + +# We don't copy installation.cmake, because the includes files are in the src folder. +# datacollector is different in this respect from the other repositories. +MLOGIC_CMAKE_FILES="artifacts.cmake +compiler.cmake +config.cmake.in +FindGMock.cmake +library.cmake +packaging.cmake +projectheader.cmake +qtmoc.cmake" + +# Process the cmake files +cd $(dirname $(readlink -f $0)) || exit 1 +for cmake_file in ${MLOGIC_CMAKE_FILES} +do + sync-file ${cmake_file} +done diff --git a/targetprops.cmake b/targetprops.cmake new file mode 100644 index 0000000..2ac88c9 --- /dev/null +++ b/targetprops.cmake @@ -0,0 +1,7 @@ +set_target_properties( ${PROJECT_NAME} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive + LINKER_LANGUAGE CXX +) + -- libgit2 0.21.4