From 5823b05feb29a59510c32a9c28ca18b50b9b6399 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 1 May 2016 18:06:14 +0200 Subject: sync with upstream --- project/cmake/scripts/common/macros.cmake | 98 +++++++++++++++++-------------- 1 file changed, 54 insertions(+), 44 deletions(-) (limited to 'project/cmake/scripts/common/macros.cmake') diff --git a/project/cmake/scripts/common/macros.cmake b/project/cmake/scripts/common/macros.cmake index dd2233b..0900740 100644 --- a/project/cmake/scripts/common/macros.cmake +++ b/project/cmake/scripts/common/macros.cmake @@ -16,6 +16,12 @@ include(${CORE_SOURCE_DIR}/project/cmake/scripts/${CORE_SYSTEM_NAME}/macros.cmak # Library will be built, optionally added to ${core_DEPENDS} function(core_add_library name) cmake_parse_arguments(arg "NO_MAIN_DEPENDS" "" "" ${ARGN}) + + if(NOT SOURCES) + message(STATUS "No sources added to ${name} skipping") + return() + endif() + add_library(${name} STATIC ${SOURCES} ${HEADERS} ${OTHERS}) set_target_properties(${name} PROPERTIES PREFIX "") if(NOT arg_NO_MAIN_DEPENDS) @@ -53,48 +59,52 @@ endfunction() # Arguments: # file full path to file to mirror # relative the relative base of file path in the build/install tree -# give another parameter to exclude from install target +# Optional Arguments: +# NO_INSTALL: exclude file from installation target # Implicit arguments: # CORE_SOURCE_DIR - root of source tree # On return: -# file is added to ${install_data} and mirrored in build tree +# Files is mirrored to the build tree and added to ${install_data} +# (if NO_INSTALL is not given). function(copy_file_to_buildtree file relative) - if(NOT WIN32) - string(REPLACE "\(" "\\(" file ${file}) - string(REPLACE "\)" "\\)" file ${file}) - endif() + cmake_parse_arguments(arg "NO_INSTALL" "" "" ${ARGN}) string(REPLACE "${relative}/" "" outfile ${file}) + get_filename_component(outdir ${outfile} DIRECTORY) if(NOT TARGET export-files) - add_custom_target(export-files ALL COMMENT "Copying files into build tree") + file(REMOVE ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake) + add_custom_target(export-files ALL COMMENT "Copying files into build tree" + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake) endif() if(NOT ${CORE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR}) if(VERBOSE) - message(STATUS "copy_file_to_buildtree - copying file: ${file} -> ${CMAKE_CURRENT_BINARY_DIR}/${outfile}") + message(STATUS "copy_file_to_buildtree - copying file: ${file} -> ${CMAKE_BINARY_DIR}/${outfile}") endif() - add_custom_command(TARGET export-files COMMAND ${CMAKE_COMMAND} -E copy_if_different "${file}" "${CMAKE_CURRENT_BINARY_DIR}/${outfile}") + file(APPEND ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/ExportFiles.cmake + "file(COPY \"${file}\" DESTINATION \"${CMAKE_BINARY_DIR}/${outdir}\")\n") endif() - if(NOT ARGN) + if(NOT arg_NO_INSTALL) list(APPEND install_data ${outfile}) set(install_data ${install_data} PARENT_SCOPE) endif() endfunction() -# add data files to installation list with a mirror in build tree. +# Add data files to installation list with a mirror in build tree. # reads list of files to install from a given list of text files. # Arguments: # pattern globbing pattern for text files to read -# give another parameter to exclude from installation target +# Optional Arguments: +# NO_INSTALL: exclude files from installation target # Implicit arguments: # CORE_SOURCE_DIR - root of source tree # On return: -# files are added to ${install_data} and mirrored in build tree +# Files are mirrored to the build tree and added to ${install_data} +# (if NO_INSTALL is not given). function(copy_files_from_filelist_to_buildtree pattern) - foreach(arg ${ARGN}) - list(APPEND pattern ${arg}) - endforeach() # copies files listed in text files to the buildtree # Input: [glob pattern: filepattern] + cmake_parse_arguments(arg "NO_INSTALL" "" "" ${ARGN}) + list(APPEND pattern ${ARGN}) list(SORT pattern) if(VERBOSE) message(STATUS "copy_files_from_filelist_to_buildtree - got pattern: ${pattern}") @@ -107,8 +117,8 @@ function(copy_files_from_filelist_to_buildtree pattern) foreach(dir ${fstrings}) file(GLOB_RECURSE files RELATIVE ${CORE_SOURCE_DIR} ${CORE_SOURCE_DIR}/${dir}) foreach(file ${files}) - if(ARGN) - copy_file_to_buildtree(${CORE_SOURCE_DIR}/${file} ${CORE_SOURCE_DIR} 1) + if(arg_NO_INSTALL) + copy_file_to_buildtree(${CORE_SOURCE_DIR}/${file} ${CORE_SOURCE_DIR} NO_INSTALL) else() copy_file_to_buildtree(${CORE_SOURCE_DIR}/${file} ${CORE_SOURCE_DIR}) endif() @@ -315,37 +325,37 @@ macro(today RESULT) endmacro() function(core_find_git_rev) - if(EXISTS ${CORE_SOURCE_DIR}/VERSION) - file(STRINGS ${CORE_SOURCE_DIR}/VERSION VERSION_FILE) - string(SUBSTRING "${VERSION_FILE}" 1 16 GIT_REV) - else() - find_package(Git) - if(GIT_FOUND AND EXISTS ${CORE_SOURCE_DIR}/.git) - execute_process(COMMAND ${GIT_EXECUTABLE} diff-files --ignore-submodules --quiet -- + find_package(Git) + if(GIT_FOUND AND EXISTS ${CORE_SOURCE_DIR}/.git) + execute_process(COMMAND ${GIT_EXECUTABLE} diff-files --ignore-submodules --quiet -- + RESULT_VARIABLE status_code + WORKING_DIRECTORY ${CORE_SOURCE_DIR}) + if (NOT status_code) + execute_process(COMMAND ${GIT_EXECUTABLE} diff-index --ignore-submodules --quiet HEAD -- RESULT_VARIABLE status_code WORKING_DIRECTORY ${CORE_SOURCE_DIR}) - if (NOT status_code) - execute_process(COMMAND ${GIT_EXECUTABLE} diff-index --cached --ignore-submodules --quiet HEAD -- - RESULT_VARIABLE status_code + endif() + if (status_code) + execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h-dirty" HEAD + OUTPUT_VARIABLE HASH WORKING_DIRECTORY ${CORE_SOURCE_DIR}) + string(SUBSTRING ${HASH} 1 13 HASH) + else() + execute_process(COMMAND ${GIT_EXECUTABLE} log -n 1 --pretty=format:"%h" HEAD + OUTPUT_VARIABLE HASH + WORKING_DIRECTORY ${CORE_SOURCE_DIR}) + string(SUBSTRING ${HASH} 1 7 HASH) endif() - today(DATE) - execute_process(COMMAND ${GIT_EXECUTABLE} --no-pager log --abbrev=7 -n 1 - --pretty=format:"%h-dirty" HEAD - OUTPUT_VARIABLE LOG_UNFORMATTED - WORKING_DIRECTORY ${CORE_SOURCE_DIR}) - string(SUBSTRING ${LOG_UNFORMATTED} 1 7 HASH) - else() - execute_process(COMMAND ${GIT_EXECUTABLE} --no-pager log --abbrev=7 -n 1 - --pretty=format:"%h %cd" HEAD - OUTPUT_VARIABLE LOG_UNFORMATTED - WORKING_DIRECTORY ${CORE_SOURCE_DIR}) - string(SUBSTRING ${LOG_UNFORMATTED} 1 7 HASH) - string(SUBSTRING ${LOG_UNFORMATTED} 9 10 DATE) - string(REPLACE "-" "" DATE ${DATE}) - endif() - set(GIT_REV "${DATE}-${HASH}") + execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:"%cd" --date=short HEAD + OUTPUT_VARIABLE DATE + WORKING_DIRECTORY ${CORE_SOURCE_DIR}) + string(SUBSTRING ${DATE} 1 10 DATE) + else() + today(DATE) + set(HASH "nogitfound") endif() + string(REPLACE "-" "" DATE ${DATE}) + set(GIT_REV "${DATE}-${HASH}") if(GIT_REV) set(APP_SCMID ${GIT_REV} PARENT_SCOPE) endif() -- cgit v1.2.3