From 0206941fa94b096807fc366c4d799be1ae97e3f9 Mon Sep 17 00:00:00 2001 From: bergmann Date: Tue, 11 Jun 2019 23:23:03 +0200 Subject: [PATCH] * Moved all configurable variables to a new include file * Use Find_Package to find local packages * Improved tool --- CMakeLists.txt | 7 ++++-- projects/helloworld/CMakeLists.txt | 21 ++-------------- .../helloworld/cmake/helloworld-var.cmake | 17 +++++++++++++ projects/helloworld/src/CMakeLists.txt | 3 +++ projects/libhelloworld/CMakeLists.txt | 24 +++---------------- .../cmake/libhelloworld-config.cmake | 4 ++++ .../cmake/libhelloworld-var.cmake | 20 ++++++++++++++++ projects/libhelloworld/src/CMakeLists.txt | 7 ++++-- tool | 9 ++++--- 9 files changed, 65 insertions(+), 47 deletions(-) create mode 100644 projects/helloworld/cmake/helloworld-var.cmake create mode 100644 projects/libhelloworld/cmake/libhelloworld-var.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f2525cb..6d88b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,11 @@ If ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ) EndIf ( ) +# Includes +Include ( CTest ) +Include ( GNUInstallDirs ) + # Projects ######################################################################################## Message ( WARNING "Please configure the subprojects of this project group!" ) -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/projects/libhelloworld ) -Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/projects/helloworld ) +# Find_Package ( ) diff --git a/projects/helloworld/CMakeLists.txt b/projects/helloworld/CMakeLists.txt index 2e50fb6..b29e5c7 100644 --- a/projects/helloworld/CMakeLists.txt +++ b/projects/helloworld/CMakeLists.txt @@ -20,29 +20,12 @@ EndIf ( ) # Project ######################################################################################### -# Version -Set ( HELLOWORLD_VERSION_MAJOR 1 ) -Set ( HELLOWORLD_VERSION_MINOR 0 ) -Set ( HELLOWORLD_VERSION_PATCH 0 ) -Set ( HELLOWORLD_VERSION_BUILD 0 ) -Set ( HELLOWORLD_VERSION_SHORT "${HELLOWORLD_VERSION_MAJOR}.${HELLOWORLD_VERSION_MINOR}" ) -Set ( HELLOWORLD_VERSION "${HELLOWORLD_VERSION_SHORT}.${HELLOWORLD_VERSION_PATCH}.${HELLOWORLD_VERSION_BUILD}" ) -Set ( HELLOWORLD_NAME "helloworld-${HELLOWORLD_VERSION_SHORT}" ) - -# Install directories -Set ( HELLOWORLD_INSTALL_DIR_BIN "bin" ) - -# Project +Include ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/helloworld-var.cmake" ) Project ( helloworld DESCRIPTION "A simple library" VERSION "${HELLOWORLD_VERSION}" ) Include ( CTest ) - -# C Standard -Set ( CMAKE_C_STANDARD 11 ) -Set ( CMAKE_CXX_STANDARD 17 ) -Set ( CMAKE_C_STANDARD_REQUIRED ON ) -Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) +Include ( GNUInstallDirs ) # Subdirectories Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) diff --git a/projects/helloworld/cmake/helloworld-var.cmake b/projects/helloworld/cmake/helloworld-var.cmake new file mode 100644 index 0000000..6c96ccb --- /dev/null +++ b/projects/helloworld/cmake/helloworld-var.cmake @@ -0,0 +1,17 @@ +# Version +Set ( HELLOWORLD_VERSION_MAJOR 1 ) +Set ( HELLOWORLD_VERSION_MINOR 0 ) +Set ( HELLOWORLD_VERSION_PATCH 0 ) +Set ( HELLOWORLD_VERSION_BUILD 0 ) +Set ( HELLOWORLD_VERSION_SHORT "${HELLOWORLD_VERSION_MAJOR}.${HELLOWORLD_VERSION_MINOR}" ) +Set ( HELLOWORLD_VERSION "${HELLOWORLD_VERSION_SHORT}.${HELLOWORLD_VERSION_PATCH}.${HELLOWORLD_VERSION_BUILD}" ) +Set ( HELLOWORLD_NAME "helloworld-${HELLOWORLD_VERSION_SHORT}" ) + +# Install directories +Set ( HELLOWORLD_INSTALL_DIR_BIN "bin" ) + +# C Standard +Set ( CMAKE_C_STANDARD 11 ) +Set ( CMAKE_CXX_STANDARD 17 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/projects/helloworld/src/CMakeLists.txt b/projects/helloworld/src/CMakeLists.txt index 8937f33..096d450 100644 --- a/projects/helloworld/src/CMakeLists.txt +++ b/projects/helloworld/src/CMakeLists.txt @@ -42,6 +42,9 @@ Target_Link_Libraries ( helloworld-objects Set ( HELLOWORLD_MAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ) Add_Executable ( helloworld ${HELLOWORLD_MAIN_FILE} ) +Set_Target_Properties ( helloworld + PROPERTIES + VERSION ${HELLOWORLD_VERSION} ) Target_Link_Libraries ( helloworld PUBLIC helloworld-objects ) diff --git a/projects/libhelloworld/CMakeLists.txt b/projects/libhelloworld/CMakeLists.txt index cb00eca..bdf10f5 100644 --- a/projects/libhelloworld/CMakeLists.txt +++ b/projects/libhelloworld/CMakeLists.txt @@ -20,31 +20,12 @@ EndIf ( ) # Project ######################################################################################### -# Version -Set ( LIBHELLOWORLD_VERSION_MAJOR 1 ) -Set ( LIBHELLOWORLD_VERSION_MINOR 0 ) -Set ( LIBHELLOWORLD_VERSION_PATCH 0 ) -Set ( LIBHELLOWORLD_VERSION_BUILD 0 ) -Set ( LIBHELLOWORLD_VERSION_SHORT "${LIBHELLOWORLD_VERSION_MAJOR}.${LIBHELLOWORLD_VERSION_MINOR}" ) -Set ( LIBHELLOWORLD_VERSION "${LIBHELLOWORLD_VERSION_SHORT}.${LIBHELLOWORLD_VERSION_PATCH}.${LIBHELLOWORLD_VERSION_BUILD}" ) -Set ( LIBHELLOWORLD_NAME "libhelloworld-${LIBHELLOWORLD_VERSION_SHORT}" ) - -# Install directories -Set ( LIBHELLOWORLD_INSTALL_DIR_INCLUDE "include/${LIBHELLOWORLD_NAME}" ) -Set ( LIBHELLOWORLD_INSTALL_DIR_LIB "lib/${LIBHELLOWORLD_NAME}" ) -Set ( LIBHELLOWORLD_INSTALL_DIR_SHARE "share/${LIBHELLOWORLD_NAME}" ) - -# Project +Include ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhelloworld-var.cmake" ) Project ( libhelloworld DESCRIPTION "A simple library" VERSION "${LIBHELLOWORLD_VERSION}" ) Include ( CTest ) - -# C Standard -Set ( CMAKE_C_STANDARD 11 ) -Set ( CMAKE_CXX_STANDARD 17 ) -Set ( CMAKE_C_STANDARD_REQUIRED ON ) -Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) +Include ( GNUInstallDirs ) # Subdirectories Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) @@ -61,6 +42,7 @@ Configure_File ( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libhellow Set ( ConfigPackageLocation "${LIBHELLOWORLD_INSTALL_DIR_SHARE}/cmake" ) Install ( EXPORT libhelloworld + NAMESPACE libhelloworld:: DESTINATION ${ConfigPackageLocation} ) Install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/libhelloworld-config.cmake" diff --git a/projects/libhelloworld/cmake/libhelloworld-config.cmake b/projects/libhelloworld/cmake/libhelloworld-config.cmake index b19b8da..9b88c09 100644 --- a/projects/libhelloworld/cmake/libhelloworld-config.cmake +++ b/projects/libhelloworld/cmake/libhelloworld-config.cmake @@ -2,3 +2,7 @@ Get_Filename_Component ( CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH ) Include ( ${CURRENT_DIR}/libhelloworld.cmake ) + +Message ( WARNING "Please configure the dependencies of this package!" ) +# Include ( CMakeFindDependencyMacro ) +# Find_Dependency ( ) diff --git a/projects/libhelloworld/cmake/libhelloworld-var.cmake b/projects/libhelloworld/cmake/libhelloworld-var.cmake new file mode 100644 index 0000000..ac176ec --- /dev/null +++ b/projects/libhelloworld/cmake/libhelloworld-var.cmake @@ -0,0 +1,20 @@ +# Version +Set ( LIBHELLOWORLD_VERSION_MAJOR 1 ) +Set ( LIBHELLOWORLD_VERSION_MINOR 0 ) +Set ( LIBHELLOWORLD_VERSION_PATCH 0 ) +Set ( LIBHELLOWORLD_VERSION_BUILD 0 ) +Set ( LIBHELLOWORLD_VERSION_SHORT "${LIBHELLOWORLD_VERSION_MAJOR}.${LIBHELLOWORLD_VERSION_MINOR}" ) +Set ( LIBHELLOWORLD_VERSION "${LIBHELLOWORLD_VERSION_SHORT}.${LIBHELLOWORLD_VERSION_PATCH}.${LIBHELLOWORLD_VERSION_BUILD}" ) +Set ( LIBHELLOWORLD_NAME "libhelloworld-${LIBHELLOWORLD_VERSION_SHORT}" ) +Set ( LIBHELLOWORLD_OUTPUTNAME "helloworld" ) + +# Install directories +Set ( LIBHELLOWORLD_INSTALL_DIR_INCLUDE "include/${LIBHELLOWORLD_NAME}" ) +Set ( LIBHELLOWORLD_INSTALL_DIR_LIB "lib" ) +Set ( LIBHELLOWORLD_INSTALL_DIR_SHARE "share/${LIBHELLOWORLD_NAME}" ) + +# C Standard +Set ( CMAKE_C_STANDARD 11 ) +Set ( CMAKE_CXX_STANDARD 17 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/projects/libhelloworld/src/CMakeLists.txt b/projects/libhelloworld/src/CMakeLists.txt index 6fdf16b..11f4b5a 100644 --- a/projects/libhelloworld/src/CMakeLists.txt +++ b/projects/libhelloworld/src/CMakeLists.txt @@ -47,7 +47,8 @@ Message ( WARNING "Please configure the output name of the s Add_Library ( libhelloworld-static STATIC $ ) Set_Target_Properties ( libhelloworld-static PROPERTIES - OUTPUT_NAME "helloworld" ) + OUTPUT_NAME "helloworld" + VERSION ${LIBHELLOWORLD_VERSION} ) Target_Include_Directories ( libhelloworld-static PUBLIC $ @@ -59,7 +60,9 @@ Message ( WARNING "Please configure the output name of the s Add_Library ( libhelloworld-shared SHARED $ ) Set_Target_Properties ( libhelloworld-shared PROPERTIES - OUTPUT_NAME "helloworld" ) + OUTPUT_NAME "helloworld" + VERSION ${LIBHELLOWORLD_VERSION} + SOVERSION ${LIBHELLOWORLD_VERSION_SHORT} ) Target_Include_Directories ( libhelloworld-shared PUBLIC $ diff --git a/tool b/tool index 891bb87..64d45c1 100755 --- a/tool +++ b/tool @@ -221,7 +221,8 @@ while [ $# -gt 0 ]; do if [ $# -lt 2 ]; then Panic "Parameter $1 expects exactly one parameter!" fi - Operations+=("grp:$2") + tmp=$(readlink -f "$2") + Operations+=("grp:$tmp") shift ;; @@ -229,7 +230,8 @@ while [ $# -gt 0 ]; do if [ $# -lt 3 ]; then Panic "Parameter $1 expects exactly two parameter!" fi - Operations+=("lib:$2:$3") + tmp=$(readlink -f "$3") + Operations+=("lib:$2:$tmp") shift shift ;; @@ -238,7 +240,8 @@ while [ $# -gt 0 ]; do if [ $# -lt 3 ]; then Panic "Parameter $1 expects exactly two parameter!" fi - Operations+=("exe:$2:$3") + tmp=$(readlink -f "$3") + Operations+=("exe:$2:$tmp") shift shift ;;