Форматирование кода

This commit is contained in:
Andrei Astafev 2019-02-16 13:10:12 +03:00
parent 209f64bd45
commit f8837304e4
13 changed files with 202 additions and 166 deletions

View File

@ -3,7 +3,9 @@ set(CPACK_SOURCE_GENERATOR TXZ)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_IGNORE_FILE "cmake/etc/cpack_ignore.txt") set(CPACK_IGNORE_FILE "cmake/etc/cpack_ignore.txt")
file(STRINGS ${CPACK_IGNORE_FILE} CPACK_SOURCE_IGNORE_FILES) file(STRINGS ${CPACK_IGNORE_FILE} CPACK_SOURCE_IGNORE_FILES)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CPACK_IGNORE_FILE}) set_property(DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CPACK_IGNORE_FILE})
include(CPack) include(CPack)
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)

View File

@ -1,8 +1,9 @@
# Создание статической и динамической библиотеки из одинаковых объектных файлов # Создание статической и динамической библиотеки из одинаковых объектных файлов
function(add_common_library LIBNAME SOURCES) function(add_common_library LIBNAME SOURCES)
add_library(${LIBNAME} OBJECT ${SOURCES}) add_library(${LIBNAME} OBJECT ${SOURCES})
target_include_directories(${LIBNAME} PUBLIC target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> ${LIBNAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/${LIBNAME}>) $<INSTALL_INTERFACE:include/${LIBNAME}>)
set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
@ -10,16 +11,18 @@ function(add_common_library LIBNAME SOURCES)
add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>) add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>)
get_property(_ver GLOBAL PROPERTY VERSION_STR) get_property(_ver GLOBAL PROPERTY VERSION_STR)
get_property(_sover GLOBAL PROPERTY VERSION_MAJOR) get_property(_sover GLOBAL PROPERTY VERSION_MAJOR)
set_target_properties(${LIBNAME}_shared PROPERTIES set_target_properties(${LIBNAME}_shared
VERSION ${_ver} PROPERTIES VERSION ${_ver}
SOVERSION ${_sover} SOVERSION ${_sover}
OUTPUT_NAME ${LIBNAME} OUTPUT_NAME ${LIBNAME}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR})
add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>) add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>)
set_target_properties(${LIBNAME}_static PROPERTIES set_target_properties(${LIBNAME}_static
OUTPUT_NAME ${LIBNAME} PROPERTIES OUTPUT_NAME ${LIBNAME}
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) ARCHIVE_OUTPUT_DIRECTORY
configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${LIBNAME}.pc) ${CMAKE_INSTALL_LIBDIR})
configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in
${CMAKE_BINARY_DIR}/${LIBNAME}.pc)
endfunction() endfunction()

View File

@ -1,5 +1,4 @@
set(COMMON_CXX_FEATURES set(COMMON_CXX_FEATURES cxx_alias_templates cxx_nullptr cxx_override)
cxx_alias_templates cxx_nullptr cxx_override)
function(common_target_properties Name) function(common_target_properties Name)
get_target_property(__type ${Name} TYPE) get_target_property(__type ${Name} TYPE)
@ -9,8 +8,9 @@ function(common_target_properties Name)
set(__visibility INTERFACE) set(__visibility INTERFACE)
endif() endif()
target_compile_features(${Name} ${__visibility} ${COMMON_CXX_FEATURES}) target_compile_features(${Name} ${__visibility} ${COMMON_CXX_FEATURES})
target_include_directories(${Name} PUBLIC target_include_directories(
$<INSTALL_INTERFACE:include> ${Name}
PUBLIC $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>) $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
@ -19,14 +19,18 @@ function(common_target_properties Name)
endif() endif()
if(NOT __interface) if(NOT __interface)
if(TARGET Qt5::Core) if(TARGET Qt5::Core)
target_compile_options(${Name} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") target_compile_options(${Name}
PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
set_target_properties(${Name} PROPERTIES AUTOMOC TRUE AUTORCC TRUE) set_target_properties(${Name} PROPERTIES AUTOMOC TRUE AUTORCC TRUE)
endif() endif()
if(TARGET Qt5::Widgets) if(TARGET Qt5::Widgets)
set_target_properties(${Name} PROPERTIES AUTOUIC TRUE) set_target_properties(${Name} PROPERTIES AUTOUIC TRUE)
if (CMAKE_VERSION VERSION_LESS 3.7.99) if(CMAKE_VERSION VERSION_LESS 3.7.99)
target_include_directories(${Name} PUBLIC target_include_directories(
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}_autogen/include>) ${Name}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}_autogen/include>
)
endif() endif()
endif() endif()
if(CMAKE_CXX_COMPILER_IS_GCC AND NOT APPLE) if(CMAKE_CXX_COMPILER_IS_GCC AND NOT APPLE)

View File

@ -1,8 +1,8 @@
# C compiler name # C compiler name
if(CMAKE_C_COMPILER_ID STREQUAL "Intel") if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
set(CMAKE_C_COMPILER_IS_INTEL ON) set(CMAKE_C_COMPILER_IS_INTEL ON)
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang"
CMAKE_C_COMPILER_ID STREQUAL "AppleClang") OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_C_COMPILER_IS_CLANG ON) set(CMAKE_C_COMPILER_IS_CLANG ON)
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(CMAKE_C_COMPILER_IS_GCC ON) set(CMAKE_C_COMPILER_IS_GCC ON)
@ -13,8 +13,8 @@ endif()
# C++ compiler name # C++ compiler name
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(CMAKE_CXX_COMPILER_IS_INTEL ON) set(CMAKE_CXX_COMPILER_IS_INTEL ON)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_CXX_COMPILER_IS_CLANG ON) set(CMAKE_CXX_COMPILER_IS_CLANG ON)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_COMPILER_IS_GCC ON) set(CMAKE_CXX_COMPILER_IS_GCC ON)

View File

@ -18,93 +18,98 @@ macro(CHECK_ENABLE_CXX_FLAG flag)
endmacro() endmacro()
# Common configuration for GCC, clang and Intel. # Common configuration for GCC, clang and Intel.
if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_INTEL OR CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_CLANG
OR CMAKE_CXX_COMPILER_IS_INTEL
OR CMAKE_CXX_COMPILER_IS_GCC)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS YES) set(CMAKE_CXX_EXTENSIONS YES)
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
CHECK_ENABLE_CXX_FLAG(-Wall) check_enable_cxx_flag(-Wall)
CHECK_ENABLE_CXX_FLAG(-Wextra) check_enable_cxx_flag(-Wextra)
CHECK_ENABLE_CXX_FLAG(-Wnon-virtual-dtor) check_enable_cxx_flag(-Wnon-virtual-dtor)
CHECK_ENABLE_CXX_FLAG(-Wnoexcept) check_enable_cxx_flag(-Wnoexcept)
CHECK_ENABLE_CXX_FLAG(-Wlogical-op) check_enable_cxx_flag(-Wlogical-op)
CHECK_ENABLE_CXX_FLAG(-Wconversion) check_enable_cxx_flag(-Wconversion)
CHECK_ENABLE_CXX_FLAG(-Wdeprecated) check_enable_cxx_flag(-Wdeprecated)
# This limit is supposed to be at least 1024 in C++11, but for some reason # This limit is supposed to be at least 1024 in C++11, but for some reason
# clang sets this to 256, and gcc to 900. # clang sets this to 256, and gcc to 900.
CHECK_ENABLE_CXX_FLAG(-ftemplate-depth=1024) check_enable_cxx_flag(-ftemplate-depth=1024)
CHECK_ENABLE_CXX_FLAG(-Wold-style-cast) check_enable_cxx_flag(-Wold-style-cast)
CHECK_ENABLE_CXX_FLAG(-Wdisabled-optimization) check_enable_cxx_flag(-Wdisabled-optimization)
# This is useful when the compiler decides the template backtrace is too verbose. # This is useful when the compiler decides the template backtrace is too
CHECK_ENABLE_CXX_FLAG(-ftemplate-backtrace-limit=0) # verbose.
CHECK_ENABLE_CXX_FLAG(-fstack-protector-all) check_enable_cxx_flag(-ftemplate-backtrace-limit=0)
check_enable_cxx_flag(-fstack-protector-all)
# A few suggestion flags. # A few suggestion flags.
CHECK_ENABLE_CXX_FLAG(-Wsuggest-attribute=pure) check_enable_cxx_flag(-Wsuggest-attribute=pure)
CHECK_ENABLE_CXX_FLAG(-Wsuggest-attribute=const) check_enable_cxx_flag(-Wsuggest-attribute=const)
CHECK_ENABLE_CXX_FLAG(-Wsuggest-attribute=noreturn) check_enable_cxx_flag(-Wsuggest-attribute=noreturn)
CHECK_ENABLE_CXX_FLAG(-Wsuggest-attribute=format) check_enable_cxx_flag(-Wsuggest-attribute=format)
# From GCC 5. # From GCC 5.
CHECK_ENABLE_CXX_FLAG(-Wodr) check_enable_cxx_flag(-Wodr)
CHECK_ENABLE_CXX_FLAG(-Wsuggest-final-types) check_enable_cxx_flag(-Wsuggest-final-types)
CHECK_ENABLE_CXX_FLAG(-Wsuggest-final-methods) check_enable_cxx_flag(-Wsuggest-final-methods)
CHECK_ENABLE_CXX_FLAG(-Wsuggest-override) check_enable_cxx_flag(-Wsuggest-override)
# From GCC 6. # From GCC 6.
CHECK_ENABLE_CXX_FLAG(-Wshift-negative-value) check_enable_cxx_flag(-Wshift-negative-value)
CHECK_ENABLE_CXX_FLAG(-Wshift-overflow=2) check_enable_cxx_flag(-Wshift-overflow=2)
CHECK_ENABLE_CXX_FLAG(-Wduplicated-cond) check_enable_cxx_flag(-Wduplicated-cond)
CHECK_ENABLE_CXX_FLAG(-Wnull-dereference) check_enable_cxx_flag(-Wnull-dereference)
# From GCC 7. # From GCC 7.
CHECK_ENABLE_CXX_FLAG(-Wrestrict) check_enable_cxx_flag(-Wrestrict)
CHECK_ENABLE_CXX_FLAG(-Waligned-new) check_enable_cxx_flag(-Waligned-new)
# From GCC 8. # From GCC 8.
CHECK_ENABLE_CXX_FLAG(-Wcast-align=strict) check_enable_cxx_flag(-Wcast-align=strict)
# This is supposed to produce a nice graphical visualization # This is supposed to produce a nice graphical visualization of mismatching
# of mismatching template errors. # template errors.
CHECK_ENABLE_CXX_FLAG(-fdiagnostics-show-template-tree) check_enable_cxx_flag(-fdiagnostics-show-template-tree)
CHECK_ENABLE_CXX_FLAG(-fdiagnostics-show-option) check_enable_cxx_flag(-fdiagnostics-show-option)
CHECK_ENABLE_CXX_FLAG(-pedantic) check_enable_cxx_flag(-pedantic)
CHECK_ENABLE_CXX_FLAG(-Wcast-align) check_enable_cxx_flag(-Wcast-align)
CHECK_ENABLE_CXX_FLAG(-Wcast-qual) check_enable_cxx_flag(-Wcast-qual)
CHECK_ENABLE_CXX_FLAG(-Wctor-dtor-privacy) check_enable_cxx_flag(-Wctor-dtor-privacy)
CHECK_ENABLE_CXX_FLAG(-Wdisabled-optimization) check_enable_cxx_flag(-Wdisabled-optimization)
CHECK_ENABLE_CXX_FLAG(-Wformat=2) check_enable_cxx_flag(-Wformat=2)
CHECK_ENABLE_CXX_FLAG(-Winit-self) check_enable_cxx_flag(-Winit-self)
CHECK_ENABLE_CXX_FLAG(-Wmissing-include-dirs) check_enable_cxx_flag(-Wmissing-include-dirs)
CHECK_ENABLE_CXX_FLAG(-Woverloaded-virtual) check_enable_cxx_flag(-Woverloaded-virtual)
CHECK_ENABLE_CXX_FLAG(-Wredundant-decls) check_enable_cxx_flag(-Wredundant-decls)
CHECK_ENABLE_CXX_FLAG(-Wsign-promo) check_enable_cxx_flag(-Wsign-promo)
CHECK_ENABLE_CXX_FLAG(-Wstrict-overflow=5) check_enable_cxx_flag(-Wstrict-overflow=5)
CHECK_ENABLE_CXX_FLAG(-Wundef) check_enable_cxx_flag(-Wundef)
CHECK_ENABLE_CXX_FLAG(-Wno-unused) check_enable_cxx_flag(-Wno-unused)
CHECK_ENABLE_CXX_FLAG(-Wno-variadic-macros) check_enable_cxx_flag(-Wno-variadic-macros)
CHECK_ENABLE_CXX_FLAG(-Wno-parentheses) check_enable_cxx_flag(-Wno-parentheses)
CHECK_ENABLE_CXX_FLAG(-Wstrict-null-sentinel) check_enable_cxx_flag(-Wstrict-null-sentinel)
CHECK_ENABLE_CXX_FLAG(-Wshadow) check_enable_cxx_flag(-Wshadow)
CHECK_ENABLE_CXX_FLAG(-Wshadow-all) check_enable_cxx_flag(-Wshadow-all)
endif() endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release") if(CMAKE_BUILD_TYPE STREQUAL "Release")
CHECK_ENABLE_CXX_FLAG(-flto) check_enable_cxx_flag(-flto)
if(CMAKE_CXX_COMPILER_IS_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8") if(CMAKE_CXX_COMPILER_IS_GCC
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8")
# Doesn't work with GCC 4.7.2 in Astra Linux 1.5 # Doesn't work with GCC 4.7.2 in Astra Linux 1.5
CHECK_ENABLE_CXX_FLAG(-fno-fat-lto-objects) check_enable_cxx_flag(-fno-fat-lto-objects)
endif() endif()
endif() endif()
endif() endif()
if (CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_GCC)
CHECK_ENABLE_CXX_FLAG(-fdiagnostics-color=auto) check_enable_cxx_flag(-fdiagnostics-color=auto)
# The -Wmaybe-uninitialized flag is enabled by -Wall, but it is known # The -Wmaybe-uninitialized flag is enabled by -Wall,
# to emit a lot of possibly spurious warnings. Let's just disable it. # but it is known to emit a lot of possibly spurious warnings.
CHECK_ENABLE_CXX_FLAG(-Wno-maybe-uninitialized) # Let's just disable it.
check_enable_cxx_flag(-Wno-maybe-uninitialized)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.999") if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.999")
# NOTE: GCC >= 6 seems to be wrongly warning about visibility attributes # NOTE: GCC >= 6 seems to be wrongly warning about visibility attributes
# in some situations: # in some situations:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947
# Let's just disable the warning for now. # Let's just disable the warning for now.
CHECK_ENABLE_CXX_FLAG(-Wno-attributes) check_enable_cxx_flag(-Wno-attributes)
endif() endif()
endif() endif()

View File

@ -5,5 +5,6 @@ function(cmlib_config_hpp_generate)
get_property(VERSION_INT GLOBAL PROPERTY VERSION_INT) get_property(VERSION_INT GLOBAL PROPERTY VERSION_INT)
get_property(VERSION_STR GLOBAL PROPERTY VERSION_STR) get_property(VERSION_STR GLOBAL PROPERTY VERSION_STR)
get_property(ORGANIZATION_NAME GLOBAL PROPERTY ORGANIZATION_NAME) get_property(ORGANIZATION_NAME GLOBAL PROPERTY ORGANIZATION_NAME)
configure_file(${CMLIB_MODULE_DIR}/hpp/config.hpp.in ${CMAKE_BINARY_DIR}/include/config.hpp) configure_file(${CMLIB_MODULE_DIR}/hpp/config.hpp.in
${CMAKE_BINARY_DIR}/include/config.hpp)
endfunction() endfunction()

View File

@ -17,13 +17,11 @@ file(GLOB_RECURSE _cmakelists_files RELATIVE ${_source_realpath} CMakeLists.txt)
foreach(_it ${_cmakelists_files}) foreach(_it ${_cmakelists_files})
get_filename_component(_file ${_it} REALPATH) get_filename_component(_file ${_it} REALPATH)
get_filename_component(_dir ${_file} DIRECTORY) get_filename_component(_dir ${_file} DIRECTORY)
file(REMOVE_RECURSE file(REMOVE_RECURSE ${_dir}/CMakeFiles
${_dir}/CMakeFiles
${_dir}/CMakeCache.txt ${_dir}/CMakeCache.txt
${_dir}/cmake_install.cmake ${_dir}/cmake_install.cmake
${_dir}/Makefile ${_dir}/Makefile
${_dir}/build.ninja ${_dir}/build.ninja
${_dir}/rules.ninja ${_dir}/rules.ninja)
)
endforeach() endforeach()

View File

@ -10,11 +10,11 @@ macro(remove_flag_from_target _target _flag)
get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS) get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS)
if(_target_cxx_flags) if(_target_cxx_flags)
list(REMOVE_ITEM _target_cxx_flags ${_flag}) list(REMOVE_ITEM _target_cxx_flags ${_flag})
set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}") set_target_properties(${_target}
PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
endif() endif()
endmacro() endmacro()
# #
# Removes the specified compiler flag from the specified file. # Removes the specified compiler flag from the specified file.
# _target - The target that _file belongs to # _target - The target that _file belongs to
@ -41,16 +41,20 @@ macro(remove_flag_from_file _target _file _flag)
# Apply the target compile flags to each source file. # Apply the target compile flags to each source file.
foreach(_source_file ${_target_sources}) foreach(_source_file ${_target_sources})
# Check for pre-existing flags set by set_source_files_properties(). # Check for pre-existing flags set by set_source_files_properties().
get_source_file_property(_source_file_cxx_flags ${_source_file} COMPILE_FLAGS) get_source_file_property(_source_file_cxx_flags ${_source_file}
COMPILE_FLAGS)
if(_source_file_cxx_flags) if(_source_file_cxx_flags)
separate_arguments(_source_file_cxx_flags UNIX_COMMAND ${_source_file_cxx_flags}) separate_arguments(_source_file_cxx_flags UNIX_COMMAND
${_source_file_cxx_flags})
list(APPEND _source_file_cxx_flags "${_target_cxx_flags}") list(APPEND _source_file_cxx_flags "${_target_cxx_flags}")
else() else()
set(_source_file_cxx_flags "${_target_cxx_flags}") set(_source_file_cxx_flags "${_target_cxx_flags}")
endif() endif()
# Apply the compile flags to the current source file. # Apply the compile flags to the current source file.
string(REPLACE ";" " " _source_file_cxx_flags_string "${_source_file_cxx_flags}") string(REPLACE ";" " " _source_file_cxx_flags_string
set_source_files_properties(${_source_file} PROPERTIES COMPILE_FLAGS "${_source_file_cxx_flags_string}") "${_source_file_cxx_flags}")
set_source_files_properties(${_source_file} PROPERTIES COMPILE_FLAGS
"${_source_file_cxx_flags_string}")
endforeach() endforeach()
endif() endif()
list(FIND _target_sources ${_file} _file_found_at) list(FIND _target_sources ${_file} _file_found_at)
@ -59,13 +63,18 @@ macro(remove_flag_from_file _target _file _flag)
# Cache the compile flags for the specified file. # Cache the compile flags for the specified file.
# This is the list that we'll be removing flags from. # This is the list that we'll be removing flags from.
get_source_file_property(_source_file_cxx_flags ${_file} COMPILE_FLAGS) get_source_file_property(_source_file_cxx_flags ${_file} COMPILE_FLAGS)
separate_arguments(_source_file_cxx_flags UNIX_COMMAND ${_source_file_cxx_flags}) separate_arguments(_source_file_cxx_flags UNIX_COMMAND
set(_cached_${_target}_${_file}_cxx_flags ${_source_file_cxx_flags} CACHE INTERNAL "") ${_source_file_cxx_flags})
set(_cached_${_target}_${_file}_cxx_flags ${_source_file_cxx_flags}
CACHE INTERNAL "")
endif() endif()
# Remove the specified flag, then re-apply the rest. # Remove the specified flag, then re-apply the rest.
list(REMOVE_ITEM _cached_${_target}_${_file}_cxx_flags ${_flag}) list(REMOVE_ITEM _cached_${_target}_${_file}_cxx_flags ${_flag})
string(REPLACE ";" " " _cached_${_target}_${_file}_cxx_flags_string "${_cached_${_target}_${_file}_cxx_flags}") string(REPLACE ";" " " _cached_${_target}_${_file}_cxx_flags_string
set_source_files_properties(${_file} PROPERTIES COMPILE_FLAGS "${_cached_${_target}_${_file}_cxx_flags_string}") "${_cached_${_target}_${_file}_cxx_flags}")
set_source_files_properties(
${_file} PROPERTIES COMPILE_FLAGS
"${_cached_${_target}_${_file}_cxx_flags_string}")
endif() endif()
endmacro() endmacro()

View File

@ -6,13 +6,16 @@ find_program(_lsb_release_executable lsb_release)
if(_lsb_release_executable) if(_lsb_release_executable)
execute_process(COMMAND ${_lsb_release_executable} -sc execute_process(COMMAND ${_lsb_release_executable} -sc
OUTPUT_VARIABLE LSB_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${_lsb_release_executable} -sr execute_process(COMMAND ${_lsb_release_executable} -sr
OUTPUT_VARIABLE LSB_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${_lsb_release_executable} -si execute_process(COMMAND ${_lsb_release_executable} -si
OUTPUT_VARIABLE LSB_DISTRIBUTOR_ID OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_DISTRIBUTOR_ID
OUTPUT_STRIP_TRAILING_WHITESPACE)
else() else()
set(LSB_DISTRIBUTOR_ID "unknown") set(LSB_DISTRIBUTOR_ID "unknown")
set(LSB_RELEASE "unknown") set(LSB_RELEASE "unknown")

View File

@ -6,7 +6,9 @@ function(set_organization_name)
message(FATAL_ERROR "File ${ORGANIZATION_FILE} doesn't exist") message(FATAL_ERROR "File ${ORGANIZATION_FILE} doesn't exist")
endif() endif()
file(READ "${_organization_file}" _org) file(READ "${_organization_file}" _org)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_organization_file}) set_property(DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${_organization_file})
if(NOT "${_org}" MATCHES "^([0-9A-Za-z ,.]+)\n") if(NOT "${_org}" MATCHES "^([0-9A-Za-z ,.]+)\n")
message(FATAL_ERROR "File ${_organization_file} has wrong format") message(FATAL_ERROR "File ${_organization_file} has wrong format")

View File

@ -7,7 +7,9 @@ function(set_project_version)
message(FATAL_ERROR "File ${_version_file} doesn't exists") message(FATAL_ERROR "File ${_version_file} doesn't exists")
endif() endif()
file(READ "${_version_file}" _version) file(READ "${_version_file}" _version)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_version_file}) set_property(DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${_version_file})
if(NOT "${_version}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\n") if(NOT "${_version}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\n")
message(FATAL_ERROR "${_version_file} has wrong format") message(FATAL_ERROR "${_version_file} has wrong format")
@ -18,8 +20,11 @@ function(set_project_version)
set_property(GLOBAL PROPERTY VERSION_MAJOR ${CMAKE_MATCH_1}) set_property(GLOBAL PROPERTY VERSION_MAJOR ${CMAKE_MATCH_1})
set_property(GLOBAL PROPERTY VERSION_MINOR ${CMAKE_MATCH_2}) set_property(GLOBAL PROPERTY VERSION_MINOR ${CMAKE_MATCH_2})
set_property(GLOBAL PROPERTY VERSION_PATCH ${CMAKE_MATCH_3}) set_property(GLOBAL PROPERTY VERSION_PATCH ${CMAKE_MATCH_3})
math(EXPR _version_int "(${CMAKE_MATCH_1} << 16) + (${CMAKE_MATCH_2} << 8) + ${CMAKE_MATCH_3}") math(EXPR _version_int
"(${CMAKE_MATCH_1} << 16) + (${CMAKE_MATCH_2} << 8) + ${CMAKE_MATCH_3}")
set_property(GLOBAL PROPERTY VERSION_INT ${_version_int}) set_property(GLOBAL PROPERTY VERSION_INT ${_version_int})
set_property(GLOBAL PROPERTY VERSION_STR "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") set_property(GLOBAL
PROPERTY VERSION_STR
"${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
endfunction() endfunction()

View File

@ -29,18 +29,23 @@ function(qt_translation)
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version=\"2.1\" language=\"${_lang}\"></TS>") <TS version=\"2.1\" language=\"${_lang}\"></TS>")
endif() endif()
string(APPEND L10N_QRC_BODY "<file alias=\"${_qm}\">${CMAKE_BINARY_DIR}/${_qm}</file>\n") string(APPEND L10N_QRC_BODY
"<file alias=\"${_qm}\">${CMAKE_BINARY_DIR}/${_qm}</file>\n")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_qm} add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_qm}
COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${_ts_dir}/${_ts} -qm ${CMAKE_BINARY_DIR}/${_qm} COMMAND ${Qt5_LRELEASE_EXECUTABLE}
ARGS ${_ts_dir}/${_ts} -qm
${CMAKE_BINARY_DIR}/${_qm}
DEPENDS ${_ts_dir}/${_ts}) DEPENDS ${_ts_dir}/${_ts})
endforeach() endforeach()
add_custom_command(OUTPUT ${_ts_list} add_custom_command(OUTPUT ${_ts_list}
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ARGS ${_sources_list} -ts ${_ts_list} COMMAND ${Qt5_LUPDATE_EXECUTABLE}
ARGS ${_sources_list} -ts ${_ts_list}
DEPENDS ${_sources_list}) DEPENDS ${_sources_list})
configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc) configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in
${CMAKE_BINARY_DIR}/${_target}_l10n.qrc)
qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc) qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc)
add_custom_target(_qrc_target DEPENDS ${_qrc}) add_custom_target(_qrc_target DEPENDS ${_qrc})

View File

@ -1,9 +1,8 @@
if(NOT TARGET uninstall) if(NOT TARGET uninstall)
configure_file( configure_file("${CMLIB_MODULE_DIR}/CMLibUninstall.cmake.in"
"${CMLIB_MODULE_DIR}/CMLibUninstall.cmake.in" "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake) COMMAND ${CMAKE_COMMAND} -P
${CMAKE_BINARY_DIR}/cmake_uninstall.cmake)
endif() endif()