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

This commit is contained in:
Andrei Astafev 2019-12-03 19:23:14 +03:00
parent 8e75846a91
commit 32dcec014f
27 changed files with 290 additions and 275 deletions

View File

@ -6,16 +6,12 @@ if(CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Profile) list(APPEND CMAKE_CONFIGURATION_TYPES Profile)
endif() endif()
else() else()
set(_allowed_build_types set(_allowed_build_types None Debug Release Profile RelWithDebInfo MinSizeRel)
None
Debug
Release
Profile
RelWithDebInfo
MinSizeRel)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_allowed_build_types}) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_allowed_build_types})
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE) set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
elseif(NOT "${CMAKE_BUILD_TYPE}" IN_LIST _allowed_build_types) elseif(NOT "${CMAKE_BUILD_TYPE}" IN_LIST _allowed_build_types)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}") message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif() endif()
@ -24,12 +20,24 @@ endif()
if(CMAKE_BUILD_TYPE STREQUAL Profile) if(CMAKE_BUILD_TYPE STREQUAL Profile)
# Ключи компиляции для режима профилирования в зависимости от типа компилятора # Ключи компиляции для режима профилирования в зависимости от типа компилятора
if(CMAKE_CXX_COMPILER_IS_Clang OR CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_Clang OR CMAKE_CXX_COMPILER_IS_GCC)
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -ggdb -pg" CACHE STRING "") set(CMAKE_C_FLAGS_PROFILE
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -ggdb -pg" CACHE STRING "") "${CMAKE_C_FLAGS_RELEASE} -ggdb -pg"
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -pg" CACHE STRING "") CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -pg" CACHE STRING "") set(CMAKE_CXX_FLAGS_PROFILE
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -pg" CACHE STRING "") "${CMAKE_CXX_FLAGS_RELEASE} -ggdb -pg"
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -pg" CACHE STRING "") CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS_PROFILE
"${CMAKE_EXE_LINKER_FLAGS_RELEASE} -pg"
CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -pg"
CACHE STRING "")
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE
"${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -pg"
CACHE STRING "")
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE
"${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -pg"
CACHE STRING "")
elseif(CMAKE_CXX_COMPILER_IS_Intel) elseif(CMAKE_CXX_COMPILER_IS_Intel)
message("Set options for profiling with Intel C++") message("Set options for profiling with Intel C++")
elseif(CMAKE_CXX_COMPILER_IS_MSVC) elseif(CMAKE_CXX_COMPILER_IS_MSVC)
@ -39,8 +47,8 @@ if(CMAKE_BUILD_TYPE STREQUAL Profile)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug) elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
# В режиме отладки подробный вывод сообщений компилятора # В режиме отладки подробный вывод сообщений компилятора
if(CMAKE_CXX_COMPILER_IS_Clang OR CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_Clang OR CMAKE_CXX_COMPILER_IS_GCC)
string(APPEND CMAKE_C_FLAGS_DEBUG " -ggdb") string(APPEND CMAKE_C_FLAGS_DEBUG " -ggdb")
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -ggdb") string(APPEND CMAKE_CXX_FLAGS_DEBUG " -ggdb")
endif() endif()
set(CMAKE_VERBOSE_MAKEFILE 1) set(CMAKE_VERBOSE_MAKEFILE 1)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@ -54,5 +62,7 @@ elseif(CMAKE_BUILD_TYPE STREQUAL None)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set(USE_CLANG_TIDY ON CACHE BOOL "Use clang-tidy") # set(USE_CLANG_TIDY ON CACHE BOOL "Use clang-tidy")
# set(USE_CPPCHECK ON CACHE BOOL "Use cppcheck") # set(USE_CPPCHECK ON CACHE BOOL "Use cppcheck")
set(USE_PVS_STUDIO ON CACHE BOOL "Use PVS-Studio") set(USE_PVS_STUDIO
ON
CACHE BOOL "Use PVS-Studio")
endif() endif()

View File

@ -6,7 +6,8 @@ set(CPACK_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CPACK_TARGET_ARCH "amd64") set(CPACK_TARGET_ARCH "amd64")
endif() endif()
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}") set(CPACK_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_TARGET_ARCH}")
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,10 +1,5 @@
find_program(CLANG_CHECK_EXE find_program(CLANG_CHECK_EXE NAMES clang-check-10 clang-check-9 clang-check-8
NAMES clang-check-10 clang-check-7 clang-check-6.0 clang-check)
clang-check-9
clang-check-8
clang-check-7
clang-check-6.0
clang-check)
if(CLANG_CHECK_EXE) if(CLANG_CHECK_EXE)
option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF) option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF)
endif() endif()
@ -21,14 +16,11 @@ function(add_clang_analyze_check)
if(NOT TARGET clang-analyze-check) if(NOT TARGET clang-analyze-check)
add_custom_target(clang-analyze-check) add_custom_target(clang-analyze-check)
endif() endif()
add_custom_target(clang-analyze-check-${_target} add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} clang-analyze-check-${_target}
COMMAND ${CLANG_CHECK_EXE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-analyze COMMAND ${CLANG_CHECK_EXE} -analyze -extra-arg="-Wno-unknown-warning-option" -p
-extra-arg="-Wno-unknown-warning-option" ${CMAKE_BINARY_DIR} ${_sources})
-p
${CMAKE_BINARY_DIR}
${_sources})
add_dependencies(clang-analyze-check-${_target} ${_target}) add_dependencies(clang-analyze-check-${_target} ${_target})
add_dependencies(clang-analyze-check clang-analyze-check-${_target}) add_dependencies(clang-analyze-check clang-analyze-check-${_target})
else() else()

View File

@ -1,10 +1,5 @@
find_program(CLANG_TIDY_EXE find_program(CLANG_TIDY_EXE NAMES clang-tidy-10 clang-tidy-9 clang-tidy-8 clang-tidy-7
NAMES clang-tidy-10 clang-tidy-6.0 clang-tidy)
clang-tidy-9
clang-tidy-8
clang-tidy-7
clang-tidy-6.0
clang-tidy)
if(CLANG_TIDY_EXE) if(CLANG_TIDY_EXE)
option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF) option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF)
if(CLANG_TIDY_FIX) if(CLANG_TIDY_FIX)
@ -21,13 +16,11 @@ function(add_clang_tidy_check)
if(NOT TARGET clang-tidy-check) if(NOT TARGET clang-tidy-check)
add_custom_target(clang-tidy-check) add_custom_target(clang-tidy-check)
endif() endif()
add_custom_target(clang-tidy-check-${_target} add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} clang-tidy-check-${_target}
COMMAND ${CLANG_TIDY_EXE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-extra-arg="-Wno-unknown-warning-option" COMMAND ${CLANG_TIDY_EXE} -extra-arg="-Wno-unknown-warning-option" -p
-p ${CMAKE_BINARY_DIR} ${_sources})
${CMAKE_BINARY_DIR}
${_sources})
add_dependencies(clang-tidy-check-${_target} ${_target}) add_dependencies(clang-tidy-check-${_target} ${_target})
add_dependencies(clang-tidy-check clang-tidy-check-${_target}) add_dependencies(clang-tidy-check clang-tidy-check-${_target})
else() else()

View File

@ -1,4 +1,6 @@
set(clazy_checks container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast) set(clazy_checks
container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast
)
function(add_clazy_check) function(add_clazy_check)
list(GET ARGN 0 _target) list(GET ARGN 0 _target)
@ -10,14 +12,11 @@ function(add_clazy_check)
if(NOT TARGET clazy-check) if(NOT TARGET clazy-check)
add_custom_target(clazy-check) add_custom_target(clazy-check)
endif() endif()
add_custom_target(clazy-check-${_target} add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} clazy-check-${_target}
COMMAND ${CLAZY_EXE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-checks=level2,${clazy_checks} COMMAND ${CLAZY_EXE} -checks=level2,${clazy_checks}
-extra-arg="-Wno-unknown-warning-option" -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources})
-p
${CMAKE_BINARY_DIR}
${_sources})
add_dependencies(clazy-check-${_target} ${_target}) add_dependencies(clazy-check-${_target} ${_target})
add_dependencies(clazy-check clazy-check-${_target}) add_dependencies(clazy-check clazy-check-${_target})
else() else()

View File

@ -8,16 +8,15 @@ function(add_pvs_check)
if(NOT TARGET pvs-check) if(NOT TARGET pvs-check)
add_custom_target(pvs-check) add_custom_target(pvs-check)
endif() endif()
pvs_studio_add_target(TARGET pvs-check-${_target} pvs_studio_add_target(
DEPENDS ${_target} TARGET pvs-check-${_target}
COMPILE_COMMANDS HIDE_HELP OUTPUT DEPENDS ${_target}
FORMAT errorfile COMPILE_COMMANDS HIDE_HELP OUTPUT
CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${_target}.cfg" FORMAT errorfile
ARGS --analysis-mode CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${_target}.cfg"
29 ARGS --analysis-mode 29 --exclude-path
--exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${_target}_autogen
${CMAKE_CURRENT_BINARY_DIR}/${_target}_autogen MODE GA:1,2,3;64:1;OP:1,2;CS:1,2)
MODE GA:1,2,3;64:1;OP:1,2;CS:1,2)
add_dependencies(pvs-check pvs-check-${_target}) add_dependencies(pvs-check pvs-check-${_target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
@ -26,6 +25,7 @@ function(add_pvs_check)
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message( message(
STATUS " Option CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.") STATUS
" Option CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.")
endif() endif()
endfunction() endfunction()

View File

@ -13,25 +13,20 @@ function(add_code_coverage)
set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF}) set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF})
if(LCOV_EXE) if(LCOV_EXE)
add_custom_target(coverage-${_target} add_custom_target(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} coverage-${_target}
COMMAND ${LCOV_EXE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
--test-name COMMAND
${_target} ${LCOV_EXE} --test-name ${_target} --output "${_target}.lcov" --capture
--output --directory ${CMAKE_BINARY_DIR})
"${_target}.lcov"
--capture
--directory
${CMAKE_BINARY_DIR})
add_dependencies(coverage-${_target} ${_target}) add_dependencies(coverage-${_target} ${_target})
if(GENHTML_EXE) if(GENHTML_EXE)
add_custom_target(coverage-report-${_target} add_custom_target(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} coverage-report-${_target}
COMMAND ${GENHTML_EXE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
--output-directory COMMAND ${GENHTML_EXE} --output-directory "report-${_target}"
"report-${_target}" "${_target}.lcov")
"${_target}.lcov")
add_dependencies(coverage-report-${_target} coverage-${_target}) add_dependencies(coverage-report-${_target} coverage-${_target})
endif() endif()
endif() endif()

View File

@ -4,11 +4,7 @@ function(add_common_library)
set(oneValueArgs TARGET OUTPUT_NAME) set(oneValueArgs TARGET OUTPUT_NAME)
set(multiValueArgs SOURCES) set(multiValueArgs SOURCES)
cmake_parse_arguments(_LOCAL cmake_parse_arguments(_LOCAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})
set(LIBNAME ${_LOCAL_TARGET}) set(LIBNAME ${_LOCAL_TARGET})
set(SOURCES ${_LOCAL_SOURCES}) set(SOURCES ${_LOCAL_SOURCES})
@ -19,36 +15,39 @@ function(add_common_library)
endif() endif()
add_library(${LIBNAME} OBJECT ${SOURCES}) add_library(${LIBNAME} OBJECT ${SOURCES})
target_include_directories(${LIBNAME} target_include_directories(
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> ${LIBNAME}
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> PUBLIC
$<INSTALL_INTERFACE:include/${LIBNAME}>) $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/${LIBNAME}>)
set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>) add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>)
set_target_properties(${LIBNAME}_shared set_target_properties(
PROPERTIES VERSION ${LIBNAME}_shared
${PROJECT_VERSION} PROPERTIES
SOVERSION VERSION
${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION}
OUTPUT_NAME SOVERSION
${OUTNAME} ${PROJECT_VERSION_MAJOR}
LIBRARY_OUTPUT_DIRECTORY OUTPUT_NAME
${CMAKE_INSTALL_LIBDIR}) ${OUTNAME}
LIBRARY_OUTPUT_DIRECTORY
${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${LIBNAME}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS ${LIBNAME}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()
if(NOT SKIP_STATIC_LIBS) if(NOT SKIP_STATIC_LIBS)
add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>) add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>)
set_target_properties(${LIBNAME}_static set_target_properties(
PROPERTIES OUTPUT_NAME ${LIBNAME}_static PROPERTIES OUTPUT_NAME ${OUTNAME} ARCHIVE_OUTPUT_DIRECTORY
${OUTNAME} ${CMAKE_INSTALL_LIBDIR})
ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${LIBNAME}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS ${LIBNAME}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()
configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${LIBNAME}.pc) configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${LIBNAME}.pc)
install(FILES ${CMAKE_BINARY_DIR}/${LIBNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${CMAKE_BINARY_DIR}/${LIBNAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endfunction() endfunction()

View File

@ -12,11 +12,12 @@ function(common_target_properties Name)
if(_targetType STREQUAL "EXECUTABLE" AND CMAKE_CXX_COMPILE_OPTIONS_PIE) if(_targetType STREQUAL "EXECUTABLE" AND CMAKE_CXX_COMPILE_OPTIONS_PIE)
target_compile_options(${Name} PUBLIC "${CMAKE_CXX_COMPILE_OPTIONS_PIE}") target_compile_options(${Name} PUBLIC "${CMAKE_CXX_COMPILE_OPTIONS_PIE}")
endif() endif()
target_include_directories(${Name} target_include_directories(
PUBLIC $<INSTALL_INTERFACE:include> ${Name}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>) $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
if(APPLE) if(APPLE)
target_compile_definitions(${Name} ${__visibility} Darwin) target_compile_definitions(${Name} ${__visibility} Darwin)
endif() endif()
@ -25,11 +26,7 @@ function(common_target_properties Name)
if(_targetType STREQUAL "EXECUTABLE") if(_targetType STREQUAL "EXECUTABLE")
target_compile_options(${Name} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") target_compile_options(${Name} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
endif() endif()
set_target_properties(${Name} set_target_properties(${Name} PROPERTIES AUTOMOC TRUE AUTORCC TRUE)
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)
@ -52,19 +49,24 @@ function(common_target_properties Name)
check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG) check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG)
check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_LTO_FLAG) check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_LTO_FLAG)
if(CMAKE_CXX_COMPILER_IS_GCC AND CXX_HAS_LTO_FLAG) if(CMAKE_CXX_COMPILER_IS_GCC AND CXX_HAS_LTO_FLAG)
find_program(CMAKE_GCC_AR find_program(
NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX}" CMAKE_GCC_AR
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX}"
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
find_program(CMAKE_GCC_NM HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm${_CMAKE_TOOLCHAIN_SUFFIX}" find_program(
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm" CMAKE_GCC_NM
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm${_CMAKE_TOOLCHAIN_SUFFIX}"
find_program(CMAKE_GCC_RANLIB "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm"
NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_TOOLCHAIN_SUFFIX}" HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib" find_program(
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) CMAKE_GCC_RANLIB
if(CMAKE_GCC_AR AND CMAKE_GCC_NM AND CMAKE_GCC_RANLIB) NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_TOOLCHAIN_SUFFIX}"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(CMAKE_GCC_AR
AND CMAKE_GCC_NM
AND CMAKE_GCC_RANLIB)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
if(CXX_HAS_NO_FAT_LTO_FLAG) if(CXX_HAS_NO_FAT_LTO_FLAG)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-fat-lto-objects") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-fat-lto-objects")
@ -75,7 +77,8 @@ function(common_target_properties Name)
else() else()
message( message(
WARNING WARNING
"GCC indicates LTO support, but binutils wrappers could not be found. Disabling LTO.") "GCC indicates LTO support, but binutils wrappers could not be found. Disabling LTO."
)
endif() endif()
else() else()
check_enable_compiler_flag(-flto) check_enable_compiler_flag(-flto)

View File

@ -12,7 +12,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 CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" 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

@ -1,17 +1,16 @@
include(WriteCompilerDetectionHeader) include(WriteCompilerDetectionHeader)
write_compiler_detection_header(FILE include/compiler_features.hpp write_compiler_detection_header(
PREFIX ${CMLIB_PROJECT_NAME_CANONICAL} FILE include/compiler_features.hpp
COMPILERS GNU PREFIX ${CMLIB_PROJECT_NAME_CANONICAL}
Clang COMPILERS GNU Clang MSVC Intel
MSVC FEATURES
Intel cxx_nullptr
FEATURES cxx_nullptr cxx_override
cxx_override cxx_alignas
cxx_alignas cxx_alignof
cxx_alignof cxx_attributes
cxx_attributes cxx_auto_type
cxx_auto_type cxx_constexpr
cxx_constexpr cxx_digit_separators
cxx_digit_separators cxx_range_for)
cxx_range_for)

View File

@ -31,7 +31,9 @@ else()
endif() endif()
# 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)

View File

@ -13,15 +13,19 @@ if(${_source_realpath} STREQUAL ${_binary_realpath})
endif() endif()
# Очистка от сгенерированных файлов # Очистка от сгенерированных файлов
file(GLOB_RECURSE _cmakelists_files RELATIVE ${_source_realpath} CMakeLists.txt) 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(
${_dir}/CMakeFiles REMOVE_RECURSE
${_dir}/CMakeCache.txt ${_dir}/CMakeFiles
${_dir}/cmake_install.cmake ${_dir}/CMakeCache.txt
${_dir}/Makefile ${_dir}/cmake_install.cmake
${_dir}/build.ninja ${_dir}/Makefile
${_dir}/rules.ninja) ${_dir}/build.ninja
${_dir}/rules.ninja)
endforeach() endforeach()

View File

@ -2,10 +2,12 @@ find_program(DISTCC_EXECUTABLE distcc)
mark_as_advanced(DISTCC_EXECUTABLE) mark_as_advanced(DISTCC_EXECUTABLE)
if(DISTCC_EXECUTABLE) if(DISTCC_EXECUTABLE)
foreach(LANG C CXX) foreach(LANG C CXX)
if(NOT DEFINED CMAKE_${LANG}_COMPILER_LAUNCHER if(NOT DEFINED CMAKE_${LANG}_COMPILER_LAUNCHER AND NOT CMAKE_${LANG}_COMPILER MATCHES
AND NOT CMAKE_${LANG}_COMPILER MATCHES ".*/distcc$") ".*/distcc$")
message(STATUS "Enabling distcc for ${LANG}") message(STATUS "Enabling distcc for ${LANG}")
set(CMAKE_${LANG}_COMPILER_LAUNCHER ${DISTCC_EXECUTABLE} CACHE STRING "") set(CMAKE_${LANG}_COMPILER_LAUNCHER
${DISTCC_EXECUTABLE}
CACHE STRING "")
endif() endif()
endforeach() endforeach()
endif() endif()

View File

@ -37,7 +37,8 @@ function(add_breathe_target)
set(oneValueArgs TARGET_NAME COMMENT) set(oneValueArgs TARGET_NAME COMMENT)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN})
if(BREATHE_FOUND) if(BREATHE_FOUND)
set(WORK_DIR ${CMAKE_BINARY_DIR}/_breathe) set(WORK_DIR ${CMAKE_BINARY_DIR}/_breathe)
set(BREATHE_DOCS_BUILD_DIR ${WORK_DIR}) set(BREATHE_DOCS_BUILD_DIR ${WORK_DIR})
@ -63,8 +64,9 @@ function(add_breathe_target)
configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY) configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY)
file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md) file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md)
if(MD_FILES) if(MD_FILES)
add_custom_command(TARGET ${_BREATHE_TARGET_NAME} PRE_BUILD add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MD_FILES} ${WORK_DIR}) TARGET ${_BREATHE_TARGET_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MD_FILES} ${WORK_DIR})
endif() endif()
endif() endif()
@ -73,12 +75,14 @@ function(add_breathe_target)
configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY) configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY)
file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst) file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst)
if(RST_FILES) if(RST_FILES)
add_custom_command(TARGET ${_BREATHE_TARGET_NAME} PRE_BUILD add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RST_FILES} ${WORK_DIR}) TARGET ${_BREATHE_TARGET_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RST_FILES} ${WORK_DIR})
endif() endif()
endif() endif()
else() else()
add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM add_custom_target(
COMMENT "Breathe is not found. Skipping target ${_BREATHE_TARGET_NAME} build") ${_BREATHE_TARGET_NAME} VERBATIM
COMMENT "Breathe is not found. Skipping target ${_BREATHE_TARGET_NAME} build")
endif() endif()
endfunction() endfunction()

View File

@ -19,7 +19,8 @@ function(add_doxygen_target)
set(oneValueArgs TARGET_NAME SQLITE LATEX HTML) set(oneValueArgs TARGET_NAME SQLITE LATEX HTML)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(_DOXYGEN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_DOXYGEN "${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN})
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
set(GENERATE_XML NO) set(GENERATE_XML NO)
set(GENERATE_HTML NO) set(GENERATE_HTML NO)
@ -45,7 +46,8 @@ function(add_doxygen_target)
WORKING_DIRECTORY ${WORK_DIR} WORKING_DIRECTORY ${WORK_DIR}
COMMENT "Generating API documentation with Doxygen") COMMENT "Generating API documentation with Doxygen")
else() else()
add_custom_target(${_DOXYGEN_TARGET_NAME} VERBATIM add_custom_target(
COMMENT "Doxygen is not found. Skipping target ${_DOXYGEN_TARGET_NAME} build") ${_DOXYGEN_TARGET_NAME} VERBATIM
COMMENT "Doxygen is not found. Skipping target ${_DOXYGEN_TARGET_NAME} build")
endif() endif()
endfunction() endfunction()

View File

@ -22,10 +22,7 @@ endmacro()
# #
# Pre: apply_global_cxx_flags_to_all_targets() must be invoked. # Pre: apply_global_cxx_flags_to_all_targets() must be invoked.
# #
macro(remove_flag_from_file macro(remove_flag_from_file _target _file _flag)
_target
_file
_flag)
get_target_property(_target_sources ${_target} SOURCES) get_target_property(_target_sources ${_target} SOURCES)
# Check if a sync is required, in which case we'll force a rewrite of the cache variables. # Check if a sync is required, in which case we'll force a rewrite of the cache variables.
if(_flag_sync_required) if(_flag_sync_required)
@ -38,7 +35,9 @@ macro(remove_flag_from_file
if(NOT _cached_${_target}_cxx_flags) if(NOT _cached_${_target}_cxx_flags)
# Obtain and cache the target compiler options, then clear them. # Obtain and cache the target compiler options, then clear them.
get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS) get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS)
set(_cached_${_target}_cxx_flags "${_target_cxx_flags}" CACHE INTERNAL "") set(_cached_${_target}_cxx_flags
"${_target_cxx_flags}"
CACHE INTERNAL "")
set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "") set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "")
# 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})
@ -51,13 +50,8 @@ macro(remove_flag_from_file
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 ";" string(REPLACE ";" " " _source_file_cxx_flags_string "${_source_file_cxx_flags}")
" " 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}") "${_source_file_cxx_flags_string}")
endforeach() endforeach()
endif() endif()
@ -68,17 +62,15 @@ macro(remove_flag_from_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 ${_source_file_cxx_flags})
set(_cached_${_target}_${_file}_cxx_flags ${_source_file_cxx_flags} CACHE INTERNAL "") 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 ";" string(REPLACE ";" " " _cached_${_target}_${_file}_cxx_flags_string
" "
_cached_${_target}_${_file}_cxx_flags_string
"${_cached_${_target}_${_file}_cxx_flags}") "${_cached_${_target}_${_file}_cxx_flags}")
set_source_files_properties(${_file} set_source_files_properties(${_file} PROPERTIES COMPILE_FLAGS
PROPERTIES
COMPILE_FLAGS
"${_cached_${_target}_${_file}_cxx_flags_string}") "${_cached_${_target}_${_file}_cxx_flags_string}")
endif() endif()
endmacro() endmacro()

View File

@ -9,14 +9,12 @@ function(add_format_sources)
find_program(UNCRUSTIFY_EXE NAMES uncrustify) find_program(UNCRUSTIFY_EXE NAMES uncrustify)
if(UNCRUSTIFY_EXE) if(UNCRUSTIFY_EXE)
list(APPEND UNCRUSTIFY_OPTS list(APPEND UNCRUSTIFY_OPTS -lCPP --replace --no-backup)
-lCPP
--replace
--no-backup)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
endif() endif()
add_custom_target(format-sources-uncrustify-${_target} COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} ${_sources}) add_custom_target(format-sources-uncrustify-${_target}
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} ${_sources})
add_dependencies(format-sources format-sources-uncrustify-${_target}) add_dependencies(format-sources format-sources-uncrustify-${_target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
@ -25,10 +23,9 @@ function(add_format_sources)
find_program(DOS2UNIX_EXE NAMES dos2unix) find_program(DOS2UNIX_EXE NAMES dos2unix)
if(DOS2UNIX_EXE) if(DOS2UNIX_EXE)
list(APPEND DOS2UNIX_OPTS list(APPEND DOS2UNIX_OPTS -k -r)
-k add_custom_target(format-sources-dos2unix-${_target} COMMAND ${DOS2UNIX_EXE} ${OPTS}
-r) ${_sources})
add_custom_target(format-sources-dos2unix-${_target} COMMAND ${DOS2UNIX_EXE} ${OPTS} ${_sources})
add_dependencies(format-sources format-sources-dos2unix-${_target}) add_dependencies(format-sources format-sources-dos2unix-${_target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")

View File

@ -1,10 +1,6 @@
# CMLIB_PROJECT_NAME_CANONICAL # CMLIB_PROJECT_NAME_CANONICAL
string(TOUPPER ${PROJECT_NAME} _project_name_uppercase) string(TOUPPER ${PROJECT_NAME} _project_name_uppercase)
string(REGEX string(REGEX REPLACE "[ -]" "_" _project_name_fixed ${_project_name_uppercase})
REPLACE "[ -]"
"_"
_project_name_fixed
${_project_name_uppercase})
set(CMLIB_PROJECT_NAME_CANONICAL ${_project_name_fixed}) set(CMLIB_PROJECT_NAME_CANONICAL ${_project_name_fixed})
# CMLIB_MODULE_DIR # CMLIB_MODULE_DIR

View File

@ -13,22 +13,26 @@ set(LSB_RELEASE "unknown")
if(EXISTS /etc/mcst_version) if(EXISTS /etc/mcst_version)
set(LSB_DISTRIBUTOR_ID "ElbrusD") set(LSB_DISTRIBUTOR_ID "ElbrusD")
set(LSB_CODENAME "Jessie") set(LSB_CODENAME "Jessie")
execute_process(COMMAND cat /etc/mcst_version execute_process(
OUTPUT_VARIABLE LSB_RELEASE COMMAND cat /etc/mcst_version
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE)
else() else()
find_program(_lsb_release_executable lsb_release) find_program(_lsb_release_executable lsb_release)
if(_lsb_release_executable) if(_lsb_release_executable)
execute_process(COMMAND ${_lsb_release_executable} -si execute_process(
OUTPUT_VARIABLE LSB_DISTRIBUTOR_ID COMMAND ${_lsb_release_executable} -si
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_DISTRIBUTOR_ID
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${_lsb_release_executable} -sc execute_process(
OUTPUT_VARIABLE LSB_CODENAME COMMAND ${_lsb_release_executable} -sc
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${_lsb_release_executable} -sr execute_process(
OUTPUT_VARIABLE LSB_RELEASE COMMAND ${_lsb_release_executable} -sr
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_VARIABLE LSB_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif() endif()
endif() endif()

View File

@ -61,38 +61,48 @@ macro(cmlib_test_large_files VARIABLE)
message(STATUS "Checking for 64-bit off_t") message(STATUS "Checking for 64-bit off_t")
# First check without any special flags # First check without any special flags
try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c") try_compile(FILE64_OK "${CMAKE_BINARY_DIR}"
"${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c")
if(FILE64_OK) if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present") message(STATUS "Checking for 64-bit off_t - present")
endif() endif()
if(NOT FILE64_OK) if(NOT FILE64_OK)
# Test with _FILE_OFFSET_BITS=64 # Test with _FILE_OFFSET_BITS=64
try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c" try_compile(
COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64") FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
if(FILE64_OK) if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64") message(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
set(_FILE_OFFSET_BITS 64 CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64") set(_FILE_OFFSET_BITS
64
CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64")
endif() endif()
endif() endif()
if(NOT FILE64_OK) if(NOT FILE64_OK)
# Test with _LARGE_FILES # Test with _LARGE_FILES
try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c" try_compile(
COMPILE_DEFINITIONS "-D_LARGE_FILES") FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_LARGE_FILES")
if(FILE64_OK) if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES") message(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
set(_LARGE_FILES 1 CACHE INTERNAL "64-bit off_t requires _LARGE_FILES") set(_LARGE_FILES
1
CACHE INTERNAL "64-bit off_t requires _LARGE_FILES")
endif() endif()
endif() endif()
if(NOT FILE64_OK) if(NOT FILE64_OK)
# Test with _LARGEFILE_SOURCE # Test with _LARGEFILE_SOURCE
try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c" try_compile(
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE") FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE")
if(FILE64_OK) if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE") message(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE") set(_LARGEFILE_SOURCE
1
CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE")
endif() endif()
endif() endif()
@ -115,12 +125,15 @@ macro(cmlib_test_large_files VARIABLE)
if(NOT FSEEKO_COMPILE_OK) if(NOT FSEEKO_COMPILE_OK)
# glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...) # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
try_compile(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}" try_compile(
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c" FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE") "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE")
if(FSEEKO_COMPILE_OK) if(FSEEKO_COMPILE_OK)
message(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE") message(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE") set(_LARGEFILE_SOURCE
1
CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
else() else()
set(FILE64_OK 0) set(FILE64_OK 0)
message(STATUS "64-bit off_t present but fseeko/ftello not found!") message(STATUS "64-bit off_t present but fseeko/ftello not found!")
@ -130,23 +143,36 @@ macro(cmlib_test_large_files VARIABLE)
if(NOT FILE64_OK) if(NOT FILE64_OK)
# now check for Windows stuff # now check for Windows stuff
try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestWindowsFSeek.c") try_compile(FILE64_OK "${CMAKE_BINARY_DIR}"
"${CMLIB_MODULE_DIR}/tests/TestWindowsFSeek.c")
if(FILE64_OK) if(FILE64_OK)
message(STATUS "Checking for 64-bit off_t - present with _fseeki64") message(STATUS "Checking for 64-bit off_t - present with _fseeki64")
set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64") set(HAVE__FSEEKI64
1
CACHE INTERNAL "64-bit off_t requires _fseeki64")
endif() endif()
endif() endif()
if(FSEEKO_COMPILE_OK) if(FSEEKO_COMPILE_OK)
set(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE) set(${VARIABLE}
set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" FORCE) 1
CACHE INTERNAL "Result of test for large file support" FORCE)
set(HAVE_FSEEKO
1
CACHE INTERNAL "64bit fseeko is available" FORCE)
elseif(HAVE__FSEEKI64) elseif(HAVE__FSEEKI64)
set(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE) set(${VARIABLE}
set(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE) 1
CACHE INTERNAL "Result of test for large file support" FORCE)
set(HAVE__FSEEKI64
1
CACHE INTERNAL "Windows 64-bit fseek" FORCE)
else() else()
check_type_size("long int" SIZEOF_LONG_INT) check_type_size("long int" SIZEOF_LONG_INT)
if(SIZEOF_LONG_INT EQUAL 8) #standard fseek is OK for 64bit if(SIZEOF_LONG_INT EQUAL 8) #standard fseek is OK for 64bit
set(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE) set(${VARIABLE}
1
CACHE INTERNAL "Result of test for large file support" FORCE)
else() else()
message(FATAL_ERROR "Checking for 64bit file support failed.") message(FATAL_ERROR "Checking for 64bit file support failed.")
endif() endif()

View File

@ -6,16 +6,16 @@ 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")
endif() endif()
string(REGEX MATCH string(REGEX MATCH "^([0-9A-Za-z ,.]+)\n" _ ${_org})
"^([0-9A-Za-z ,.]+)\n"
_
${_org})
set_property(GLOBAL PROPERTY ORGANIZATION_NAME ${CMAKE_MATCH_1}) set_property(GLOBAL PROPERTY ORGANIZATION_NAME ${CMAKE_MATCH_1})
endfunction() endfunction()

View File

@ -4,7 +4,9 @@ function(set_project_version)
endif() endif()
math( math(
EXPR _version_int EXPR
"(${PROJECT_VERSION_MAJOR} << 16) + (${PROJECT_VERSION_MINOR} << 8) + ${PROJECT_VERSION_PATCH}") _version_int
"(${PROJECT_VERSION_MAJOR} << 16) + (${PROJECT_VERSION_MINOR} << 8) + ${PROJECT_VERSION_PATCH}"
)
set_property(GLOBAL PROPERTY PROJECT_VERSION_INT ${_version_int}) set_property(GLOBAL PROPERTY PROJECT_VERSION_INT ${_version_int})
endfunction() endfunction()

View File

@ -1,15 +1,14 @@
function(qt_translation) function(qt_translation)
find_package(Qt5 COMPONENTS LinguistTools REQUIRED) find_package(
Qt5
COMPONENTS LinguistTools
REQUIRED)
set(options) set(options)
set(oneValueArgs TARGET TS_DIR) set(oneValueArgs TARGET TS_DIR)
set(multiValueArgs LANGUAGES) set(multiValueArgs LANGUAGES)
cmake_parse_arguments(_QTTR cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})
set(_target ${_QTTR_TARGET}) set(_target ${_QTTR_TARGET})
set(_ts_dir ${_QTTR_TS_DIR}) set(_ts_dir ${_QTTR_TS_DIR})
set(_languages ${_QTTR_LANGUAGES}) set(_languages ${_QTTR_LANGUAGES})
@ -23,16 +22,14 @@ function(qt_translation)
set(_qm "${_target}_${_lang}.qm") set(_qm "${_target}_${_lang}.qm")
list(APPEND _ts_list ${_ts_dir}/${_ts}) list(APPEND _ts_list ${_ts_dir}/${_ts})
list(APPEND _l10n_targets "${_target}_l10n_${_lang}") list(APPEND _l10n_targets "${_target}_l10n_${_lang}")
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_target(${_target}_l10n_${_lang} add_custom_target(
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_target}_l10n_${_lang}
${_sources} COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_sources} -ts ${_ts_dir}/${_ts} -target-language
-ts ${_lang}
${_ts_dir}/${_ts} DEPENDS ${_sources})
-target-language
${_lang}
DEPENDS ${_sources})
if(NOT EXISTS "${_ts_dir}/${_ts}") if(NOT EXISTS "${_ts_dir}/${_ts}")
add_custom_target(${_ts} DEPENDS ${_target}_l10n_${_lang}) add_custom_target(${_ts} DEPENDS ${_target}_l10n_${_lang})
@ -40,16 +37,15 @@ function(qt_translation)
add_custom_target(${_ts} COMMAND echo "Skipping lupdate for ${_ts}") add_custom_target(${_ts} COMMAND echo "Skipping lupdate for ${_ts}")
endif() endif()
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_qm} add_custom_command(
COMMAND ${Qt5_LRELEASE_EXECUTABLE} OUTPUT ${CMAKE_BINARY_DIR}/${_qm}
ARGS COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${_ts_dir}/${_ts} -qm
${_ts_dir}/${_ts} ${CMAKE_BINARY_DIR}/${_qm}
-qm DEPENDS ${_ts} ${_sources})
${CMAKE_BINARY_DIR}/${_qm}
DEPENDS ${_ts} ${_sources})
endforeach() endforeach()
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(${_target}_qrc DEPENDS ${_qrc}) add_custom_target(${_target}_qrc DEPENDS ${_qrc})
add_custom_target(${_target}_l10n DEPENDS ${_l10n_targets}) add_custom_target(${_target}_l10n DEPENDS ${_l10n_targets})

View File

@ -19,7 +19,8 @@ if(NOT CPACK_PACKAGE_CONTACT)
endif() endif()
if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
message(FATAL_ERROR "Required variable CPACK_PACKAGE_DESCRIPTION_SUMMARY is not defined") message(
FATAL_ERROR "Required variable CPACK_PACKAGE_DESCRIPTION_SUMMARY is not defined")
endif() endif()
if(NOT CPACK_DEBIAN_PACKAGE_SECTION) if(NOT CPACK_DEBIAN_PACKAGE_SECTION)

View File

@ -4,9 +4,5 @@ if(NOT TODAY)
else() else()
execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE TODAY) execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE TODAY)
endif() endif()
string(REGEX string(REGEX REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" TODAY ${TODAY})
REPLACE "(..)/(..)/(....).*"
"\\3-\\2-\\1"
TODAY
${TODAY})
endif() endif()

View File

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