Commit 7c3894f2 authored by Arnaud Le Meillour's avatar Arnaud Le Meillour
Browse files

Update Build files

parent 2f6438ce
Pipeline #90440 passed with stages
in 1 minute and 38 seconds
......@@ -23,5 +23,5 @@
include:
- project: 'accelerators/cicd/ci-cd/template'
ref: 'Tango_9.3_C'
ref: 'Tango_9.3_latest'
file: 'build_project.yml'
\ No newline at end of file
# Generic main project
project(Root)
cmake_minimum_required (VERSION 3.16)
include(./cmake/library.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(lib-common)
include(lib-project)
###############################################################################
# DEFAULT PROJECT CONFIGURATION
......@@ -15,6 +18,7 @@ set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_SKIP_RPATH true)
OPTION(BUILD_SHARED_LIBS "Build Tango classes as Shared libraries" ON)
OPTION(BUILD_TESTING "Build all the unit-tests" OFF)
###############################################################################
# Load (if exists) cmake INSTITUTE configuration file with include macro with name:
......@@ -24,11 +28,34 @@ OPTION(BUILD_SHARED_LIBS "Build Tango classes as Shared libraries" ON)
#
includeOptional("/opt/os_dev/cpp/ESRF-config.cmake")
include(./cmake/build-common.cmake)
# Manage common tasks
include(build-common)
###############################################################################
# External Tango Classes needed by this project
## ONSITE
# findLibConfig(
# REQUIRED
# CONFIG
# NAME Serial
# NAME_CMAKE Serial
# VERSION 2
# SEARCH_DIRS "${ESRF_DEFAULT_TANGO_CLASS_SEARCH_DIR}/Serial/current"
# EXPECTED_TARGETS Serial::Serial
# )
## OUTSITE
# findLibGit(
# NAME Serial
# GIT_REPO git@gitlab.esrf.fr:accelerators/cicd/generic/protocols/serial.git
# GIT_TAG release
# EXPECTED_TARGETS Serial::Serial
# )
# showTargetProperties(Serial::Serial)
###############################################################################
# Local Tango Classes build in this project
addTangoTargets(
addTangoDevices(
DEVICE_CLASSES
AttributeCombiner 1.0.3
DEVICE_SERVERS
......
......@@ -8,8 +8,7 @@ project(AttributeCombiner
CXX
)
# Tango Class dependencies (inheritance from parent Tango Class) declaration
set(TC_DEPENDENCIES )
set(LINK_LIBRARIES_CLASSES )
###############################################################################
# Build library
include(../../cmake/build-tango-class.cmake)
includeOptional(${CMAKE_CURRENT_SOURCE_DIR}/user-build.cmake)
include(build-tango-class)
# USER (TANGO CLASSES) CONFIGURATION
# Here update configuration of target: ${DEVICE_CLASS_TARGET}
target_sources(${DEVICE_CLASS_TARGET}
PRIVATE
src/AttributeMap.cpp
)
# To add extra sources files for this Tango class,
# use addExtraFiles() macro
addExtraFiles(
AttributeMap.cpp
)
# EXTERNAL (TANGO CLASSES) CONFIGURATION
configTangoClass()
# USER (TANGO CLASSES) CONFIGURATION
msg(DEBUG ">> Load module FindTango")
###############################################################
# This CMake module produce some variables:
# TARGETS_CPPZMQ set with Target name for ZeroMQ
# TARGETS_JPEG set with Target name for Jpeg-Turbo
# TARGETS_CPPTANGO set with Target name for cppTango
# TARGETS_TANGO append with previous Targets
#####################################
# Minimun version needed for libraries and ESRF repo search dir
# Detect some system environment variables and if existing, recreate them as CMake variables
# to use them for config
setEnv2Cmake(CPPZMQ_VERSION)
setEnv2Cmake(CPPZMQ_DIR)
setEnv2Cmake(ZMQ_VERSION)
setEnv2Cmake(ZMQ_DIR)
setEnv2Cmake(OMNIORB_VERSION)
setEnv2Cmake(OMNIORB_DIR)
setEnv2Cmake(CPPTANGO_VERSION)
setEnv2Cmake(CPPTANGO_DIR)
setEnv2Cmake(JPEG_VERSION)
setEnv2Cmake(JPEG_DIR)
#####################################
# List used to contain the Targets needed for dependencies to Tango
set(TARGETS_CPPZMQ )
set(TARGETS_JPEG )
set(TARGETS_CPPTANGO )
set(LINK_LIBRARIES_TANGO )
#####################################
# Get Interface Target for Threads
# find_package() -> Threads::Threads
# pkg_check_modules -> PkgConfig::Threads
# set(THREADS_PREFER_PTHREAD_FLAG ON)
# findLibConfig(
# QUIET
# NAME Threads
# NAME_CMAKE Threads
# NAME_PKG-CONFIG Threads
# EXPECTED_TARGETS Threads::Threads
# OUTPUT_LIST TARGETS_THREADS
# OUTPUT_LIST_APPEND LINK_LIBRARIES_TANGO
# )
#####################################
# Get Interface Target for ZeroMQ
# find_package() -> libzmq;libzmq-static;cppzmq;cppzmq-static
# pkg_check_modules -> PkgConfig::libzmq
findLibConfig(
QUIET
NAME cppzmq
NAME_CMAKE cppzmq
NAME_PKG-CONFIG libzmq
VERSION ${CPPZMQ_VERSION}
SEARCH_DIRS ${ZMQ_DIR};${CPPZMQ_DIR}
EXPECTED_TARGETS cppzmq
OUTPUT_LIST TARGETS_CPPZMQ
OUTPUT_LIST_APPEND LINK_LIBRARIES_TANGO
)
#####################################
# Get Interface Target for JPeg-Turbo
# find_package() -> libjpeg-turbo::jpeg;libjpeg-turbo::turbojpeg;libjpeg-turbo::turbojpeg-static;libjpeg-turbo::jpeg-static
# pkg_check_modules -> PkgConfig::libjpeg
# findLibConfig(
# QUIET
# NAME jpeg
# NAME_CMAKE JPEG
# NAME_PKG-CONFIG libjpeg
# VERSION ${JPEG_VERSION}
# SEARCH_DIRS ${JPEG_DIR}
# EXPECTED_TARGETS JPEG::JPEG
# OUTPUT_LIST TARGETS_JPEG
# OUTPUT_LIST_APPEND LINK_LIBRARIES_TANGO
# )
#####################################
# Get Interface Target for cppTango
# find_package() ->
# pkg_check_modules -> PkgConfig::tango
findLibConfig(
QUIET
REQUIRED
NAME tango
NAME_CMAKE tango
NAME_PKG-CONFIG tango
VERSION ${CPPTANGO_VERSION}
SEARCH_DIRS ${ZMQ_DIR};${CPPZMQ_DIR};${OMNIORB_DIR};${CPPTANGO_DIR};${JPEG_DIR}
EXPECTED_TARGETS tango::tango
OUTPUT_LIST TARGETS_CPPTANGO
OUTPUT_LIST_APPEND LINK_LIBRARIES_TANGO
)
#####################################
# Show recovered Targets information
msg(SECTION "DISPLAY IMPORTED TARGET content for: ${LINK_LIBRARIES_TANGO}")
foreach(TARGET_NAME ${LINK_LIBRARIES_TANGO})
showTargetProperties(${TARGET_NAME})
endforeach()
\ No newline at end of file
###############################################################
# This CMake module produce some variables:
# TARGETS_GTEST set with Target name for googletest
# TARGETS_THREADS set with Target name for Threads
# TARGETS_TEST append with previous Targets
#####################################
# Google Test variables
set(GTEST_LIB_VERSION 1.12)
set(GTEST_LIB_GIT_REPO https://github.com/google/googletest.git)
set(GTEST_LIB_GIT_TAG release-1.12.1)
set(GTEST_LIB_ESRF_REPO /opt/os_dev/cpp/${BUILD_DIR}/lib/googletest/current)
#####################################
# Get Interface Target for googletest/GTest
# find_package() -> GTest::gtest;GTest::gtest_main;GTest::gmock;GTest::gmock_main;GTest::GTest;GTest::Main
# pkg_check_modules ->
findLibConfig(
QUIET
NAME GTest
NAME_CMAKE GTest
NAME_PKG-CONFIG googletest
VERSION ${GTEST_LIB_VERSION}
SEARCH_DIRS ${GTEST_LIB_ESRF_REPO}
EXPECTED_TARGETS GTest::gtest_main
OUTPUT_LIST TARGETS_GTEST
OUTPUT_LIST_APPEND LINK_LIBRARIES_TEST
)
if(NOT TARGETS_GTEST OR "${TARGETS_GTEST}" STREQUAL "")
findLibGit(
NAME googletest
EXPECTED_TARGETS GTest::gtest_main
GIT_REPO ${GTEST_LIB_GIT_REPO}
GIT_TAG ${GTEST_LIB_GIT_TAG}
OUTPUT_LIST TARGETS_GTEST
OUTPUT_LIST_APPEND LINK_LIBRARIES_TEST
)
endif()
#####################################
# Get Interface Target for Threads
# find_package() -> Threads::Threads
# pkg_check_modules -> PkgConfig::Threads
#set(THREADS_PREFER_PTHREAD_FLAG ON)
# findLibConfig(
# QUIET
# NAME Threads
# NAME_CMAKE Threads
# NAME_PKG-CONFIG Threads
# EXPECTED_TARGETS Threads::Threads
# OUTPUT_LIST TARGETS_THREADS
# OUTPUT_LIST_APPEND LINK_LIBRARIES_TEST
# )
#####################################
# Show recovered Targets information
msg(SECTION "DISPLAY IMPORTED TARGET content for: ${LINK_LIBRARIES_TEST}")
foreach(TARGET_NAME ${LINK_LIBRARIES_TEST})
showTargetProperties(${TARGET_NAME})
endforeach()
\ No newline at end of file
# Avoid Re Load this module
set(MODULE_NAME build-common)
if(${MODULE_NAME})
msg(DEBUG ">> module ${MODULE_NAME} already load")
return()
else()
msg(DEBUG ">> Load module ${MODULE_NAME}")
set(${MODULE_NAME} ON)
endif()
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there." )
endif()
# Detect some system environment variables and if existing, recreate them as CMake variables
# to use them for config
msg(DEBUG "Check if envirronment variable for CMake config are set and if yes put them as CMake variables")
setEnv2Cmake(TC_ZMQ_VERSION)
setEnv2Cmake(TC_ZMQ_DIR)
setEnv2Cmake(TC_OMNIORB_VERSION)
setEnv2Cmake(TC_OMNIORB_DIR)
setEnv2Cmake(TC_CPPTANGO_VERSION)
setEnv2Cmake(TC_CPPTANGO_DIR)
setEnv2Cmake(CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${CXX_STANDARD})
......@@ -22,44 +24,33 @@ set(CMAKE_C_STANDARD ${C_STANDARD})
# Check if execute from GitLab
if(DEFINED ENV{CI_COMMIT_SHA})
set(TC_ENV_GITLAB YES)
set(TC_ENV_INTERACTIVE NO)
set(ENV_GITLAB YES)
set(ENV_INTERACTIVE NO)
else()
set(TC_ENV_GITLAB NO)
set(TC_ENV_INTERACTIVE YES)
set(ENV_GITLAB NO)
set(ENV_INTERACTIVE YES)
endif()
set(TC_TEMPLATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake/template)
# Default dir can be override in institute project config file
## use in local CMake library file to search Tango classes external of project
set(TC_DEFAULT_TANGO_CLASS_SEARCH_DIR "/usr/local/lib")
set(TC_DEFAULT_TANGO_LIBS_SEARCH_DIR "/usr/local/lib")
set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(PROJECT_CLASSES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/classes)
set(PROJECT_SERVERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/servers)
set(PROJECT_TEMPLATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake/template)
string(TIMESTAMP VERSION_BUILD_TIMESTAMP "%Y-%m-%d %H:%M:%S")
# INSTITUTE PROJECT CONFIGURATION
# EXTERNAL (PROJECT) CONFIGURATION
configProject()
# Get Git/Gitlab information to set variables
getGitInfo()
###############################################################################
#-CppZMQ-####################
findLib(
NAME cppzmq
NAME_CMAKE cppzmq
VERSION ${TC_CPPZMQ_VERSION}
SEARCH_DIR ${TC_ZMQ_DIR};${TC_CPPZMQ_DIR}
)
# Import Tango libraries Targets
find_package(Tango)
#-cppTango-####################
findLib(
NAME cppTango
NAME_PKG_CONFIG tango
VERSION ${TC_CPPTANGO_VERSION}
SEARCH_DIR ${TC_ZMQ_DIR};${TC_CPPZMQ_DIR};${TC_OMNIORB_DIR};${TC_CPPTANGO_DIR}
)
# test library (optional)
if(BUILD_TESTING)
enable_testing()
find_package(Test)
add_custom_target(tests ALL)
endif()
include(./cmake/debug.cmake)
# Show all variable if debug/verbose
include(debug)
# Avoid Re Load this module
set(MODULE_NAME build-tango-class)
if(${MODULE_NAME})
msg(DEBUG ">> module ${MODULE_NAME} already load")
return()
else()
msg(DEBUG ">> Load module ${MODULE_NAME}")
set(${MODULE_NAME} ON)
endif()
# Set specific Local variables
set(TC_TARGET ${PROJECT_NAME}_lib-target)
set(TC_EXPORT ${PROJECT_NAME}_lib-export)
set(DEVICE_CLASS_TARGET ${PROJECT_NAME})
set(TARGET_EXPORT ${PROJECT_NAME}_export)
# Target declaration
add_library(${TC_TARGET})
msg(STATUS "Define Library target ${TC_TARGET}")
add_library(${DEVICE_CLASS_TARGET})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${DEVICE_CLASS_TARGET})
msg(STATUS "Define Library target ${DEVICE_CLASS_TARGET}")
###############################################################################
# DEFAULT TANGO CLASS BUILD CONFIGURATION #####################################
# DEFAULT TANGO CLASSES BUILD VARIABLES
set(TC_COMPILE_FEATURES )
set(COMPILE_FEATURES )
set(TC_COMPILE_OPTIONS
set(COMPILE_OPTIONS
#-Werror # Make all warnings into errors.
-Wall # This enables all the warnings.
-Wextra # This enables some extra warning flags.
......@@ -24,27 +35,21 @@ set(TC_COMPILE_OPTIONS
set(CMAKE_INSTALL_CMAKEDIR cmake)
# Set name of output lib
set(TC_OUTPUT_NAME ${PROJECT_NAME})
set(TC_OUTPUT_NAME_RELEASE ${PROJECT_NAME})
set(TC_OUTPUT_NAME_DEBUG ${PROJECT_NAME})
set(TC_PERMISSIONS_LIB_FILES ) # Compilation features & options
set(OUTPUT_NAME ${PROJECT_NAME})
set(OUTPUT_NAME_RELEASE ${PROJECT_NAME})
set(OUTPUT_NAME_DEBUG ${PROJECT_NAME})
set(TC_PERMISSIONS_CMAKE_FILES )
set(PERMISSIONS_LIB ) # Compilation features & options
# INSTITUTE TANGO CLASS BUILD CONFIGURATION ###################################
configTangoClass()
###############################################################################
# GLOBAL TANGO CLASSES EXTERNAL/USER CONFIGURATION
includeOptional(${PROJECT_CLASSES_DIR}/config-classes.cmake)
# Add Tango Classes dependencies
addDependencies(${TC_DEPENDENCIES})
# Get header files
getFiles(TC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include "*.hpp")
getFiles(TC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include "*.h")
###############################################################################
# DEFAULT TANGO CLASSES BUILD CONFIGURATION
target_sources(${TC_TARGET}
target_sources(${DEVICE_CLASS_TARGET}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/${PROJECT_NAME}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/${PROJECT_NAME}Class.cpp
......@@ -53,23 +58,22 @@ target_sources(${TC_TARGET}
# Add Version file
configure_file(
"${TC_TEMPLATE_DIR}/VersionConfig.h.in"
"${PROJECT_TEMPLATE_DIR}/VersionConfig.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/VersionConfig.h"
)
target_sources(${TC_TARGET}
target_sources(${DEVICE_CLASS_TARGET}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/VersionConfig.h
)
target_link_libraries(${TC_TARGET}
target_link_libraries(${DEVICE_CLASS_TARGET}
PRIVATE
cppTango-target
cppzmq-target
${LINK_LIBRARIES_TANGO}
PUBLIC
${TC_TANGO_CLASSES_TARGET}
${LINK_LIBRARIES_CLASSES}
)
target_include_directories(${TC_TARGET}
target_include_directories(${DEVICE_CLASS_TARGET}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
PUBLIC
......@@ -77,40 +81,51 @@ target_include_directories(${TC_TARGET}
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_compile_options(${TC_TARGET}
target_compile_options(${DEVICE_CLASS_TARGET}
PRIVATE
${TC_COMPILE_OPTIONS}
${COMPILE_OPTIONS}
)
target_compile_features(${TC_TARGET}
target_compile_features(${DEVICE_CLASS_TARGET}
PRIVATE
${TC_COMPILE_FEATURES}
${COMPILE_FEATURES}
)
set_target_properties(${TC_TARGET}
set_target_properties(${DEVICE_CLASS_TARGET}
PROPERTIES
OUTPUT_NAME ${TC_OUTPUT_NAME}
OUTPUT_NAME_RELEASE ${TC_OUTPUT_NAME_RELEASE}
OUTPUT_NAME_DEBUG ${TC_OUTPUT_NAME_DEBUG}
PUBLIC_HEADER "${TC_HEADER}"
OUTPUT_NAME ${OUTPUT_NAME}
OUTPUT_NAME_RELEASE ${OUTPUT_NAME_RELEASE}
OUTPUT_NAME_DEBUG ${OUTPUT_NAME_DEBUG}
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION
)
install(TARGETS ${TC_TARGET} cppTango-target cppzmq-target
EXPORT ${TC_EXPORT}
PERMISSIONS ${TC_PERMISSIONS_LIB_FILES}
install(TARGETS ${DEVICE_CLASS_TARGET}
EXPORT ${TARGET_EXPORT}
PERMISSIONS ${PERMISSIONS_LIB}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY include/ # source directory
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR} # target directory
FILES_MATCHING # install only matched files
PATTERN "*.h" # Std method
PATTERN "*.tpp"
PATTERN "*.hpp"
PATTERN ".svn" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE
PERMISSIONS
${PERMISSIONS_LIB}
)
# Add Cmake config file
configure_package_config_file(
"${TC_TEMPLATE_DIR}/Config.cmake.in"
"${PROJECT_TEMPLATE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)
......@@ -127,19 +142,62 @@ install(
DESTINATION
${CMAKE_INSTALL_CMAKEDIR}
PERMISSIONS
${TC_PERMISSIONS_CMAKE_FILES}
${PERMISSIONS_LIB}
)
export(EXPORT ${TC_EXPORT}
export(EXPORT ${TARGET_EXPORT}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)
install(EXPORT ${TC_EXPORT}
install(EXPORT ${TARGET_EXPORT}
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
PERMISSIONS ${TC_PERMISSIONS_CMAKE_FILES}
PERMISSIONS ${PERMISSIONS_LIB}
)
include(../../cmake/debug.cmake)
\ No newline at end of file
if(INSTALL_SOURCE_DIR AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
install(
DIRECTORY
src/ # source directory
DESTINATION
${CMAKE_INSTALL_SOURCEDIR} # target directory
FILES_MATCHING # install only matched files
#REGEX "PUBLIC/.+\.h" # RegEx method
PATTERN "*.h" # Std method
PATTERN "*.tpp"
PATTERN "*.hpp"
PATTERN "*.c"
PATTERN "*.cpp"
PATTERN ".svn" EXCLUDE
PATTERN ".vscode" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE
PERMISSIONS
${PERMISSIONS_LIB}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/VersionConfig.h"
DESTINATION
${CMAKE_INSTALL_SOURCEDIR}
PERMISSIONS
${PERMISSIONS_LIB}
)
endif()
if(BUILD_TESTING)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tests)
msg(SECTION "ADD Tests for Tango Class ${PROJECT_NAME}")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
endif()
endif()
###############################################################################
# SPECIFIC TANGO CLASS USER CONFIGURATION
includeOptional(${CMAKE_CURRENT_SOURCE_DIR}/config-class.cmake)
include(debug)
\ No newline at end of file
# Avoid Re Load this module
set(MODULE_NAME build-tango-server)
if(${MODULE_NAME})
msg(DEBUG ">> module ${MODULE_NAME} already load")
return()