Форматирование с помощью https://github.com/cheshirekow/cmake_format

This commit is contained in:
Andrei Astafev 2019-10-07 13:52:50 +03:00
parent fc5bbbd4c1
commit 97ccbf69ac
28 changed files with 461 additions and 228 deletions

151
.cmake-format Normal file
View File

@ -0,0 +1,151 @@
# --------------------------
# General Formatting Options
# --------------------------
# How wide to allow formatted cmake files
line_width = 100
# How many spaces to tab for indent
tab_size = 2
# If arglists are longer than this, break them always
max_subargs_per_line = 3
# If true, separate flow control names from their parentheses with a space
separate_ctrl_name_with_space = False
# If true, separate function names from parentheses with a space
separate_fn_name_with_space = False
# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on it's own line
dangle_parens = False
# If the statement spelling length (including space and parenthesis is larger
# than the tab width by more than this amoung, then force reject un-nested
# layouts.
max_prefix_chars = 2
# If a candidate layout is wrapped horizontally but it exceeds this many lines,
# then reject the layout.
max_lines_hwrap = 2
# What style line endings to use in the output.
line_ending = 'unix'
# Format command names consistently as 'lower' or 'upper' case
command_case = 'canonical'
# Format keywords consistently as 'lower' or 'upper' case
keyword_case = 'upper'
# Specify structure for custom cmake functions
additional_commands = {
"foo": {
"flags": [
"BAR",
"BAZ"
],
"kwargs": {
"HEADERS": "*",
"SOURCES": "*",
"DEPENDS": "*"
}
},
"pvs_studio_add_target" : {
"flags": [
"COMPILE_COMMANDS",
"OUTPUT",
"HIDE_HELP"
],
"kwargs": {
"TARGET": "*",
"DEPENDS": "*",
"FORMAT": "*",
"CONFIG": "*",
"ARGS": "*",
"MODE": "*"
}
},
"write_compiler_detection_header" : {
"flags": [ ],
"kwargs": {
"FILE": "*",
"PREFIX": "*",
"COMPILERS": "*",
"FEATURES": "*"
}
}
}
# A list of command names which should always be wrapped
always_wrap = []
# Specify the order of wrapping algorithms during successive reflow attempts
algorithm_order = [0, 1, 2, 3, 4]
# If true, the argument lists which are known to be sortable will be sorted
# lexicographicall
enable_sort = True
# If true, the parsers may infer whether or not an argument list is sortable
# (without annotation).
autosort = False
# If a comment line starts with at least this many consecutive hash characters,
# then don't lstrip() them off. This allows for lazy hash rulers where the first
# hash char is not separated by space
hashruler_min_length = 10
# A dictionary containing any per-command configuration overrides. Currently
# only `command_case` is supported.
per_command = {}
# --------------------------
# Comment Formatting Options
# --------------------------
# What character to use for bulleted lists
bullet_char = '*'
# What character to use as punctuation after numerals in an enumerated list
enum_char = '.'
# enable comment markup parsing and reflow
enable_markup = False
# If comment markup is enabled, don't reflow the first comment block in each
# listfile. Use this to preserve formatting of your copyright/license
# statements.
first_comment_is_literal = False
# If comment markup is enabled, don't reflow any comment block which matches
# this (regex) pattern. Default is `None` (disabled).
literal_comment_pattern = None
# Regular expression to match preformat fences in comments
# default=r'^\s*([`~]{3}[`~]*)(.*)$'
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
# Regular expression to match rulers in comments
# default=r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
# If true, then insert a space between the first hash char and remaining hash
# chars in a hash ruler, and normalize it's length to fill the column
canonicalize_hashrulers = True
# ---------------------------------
# Miscellaneous Options
# ---------------------------------
# If true, emit the unicode byte-order mark (BOM) at the start of the file
emit_byteorder_mark = False
# Specify the encoding of the input file. Defaults to utf-8.
input_encoding = 'utf-8'
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
# only claims to support utf-8 so be careful when using anything else
output_encoding = 'utf-8'

View File

@ -6,7 +6,13 @@ if(CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Profile) list(APPEND CMAKE_CONFIGURATION_TYPES Profile)
endif() endif()
else() else()
set(_allowed_build_types None Debug Release Profile RelWithDebInfo MinSizeRel) set(_allowed_build_types
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)
@ -23,7 +29,9 @@ if(CMAKE_BUILD_TYPE STREQUAL Profile)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -g -p" CACHE STRING "") set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -g -p" CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "")
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE}" CACHE STRING "") set(CMAKE_STATIC_LINKER_FLAGS_PROFILE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE}" CACHE STRING "")
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -g -p" CACHE STRING "") set(CMAKE_MODULE_LINKER_FLAGS_PROFILE
"${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -g -p"
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)
@ -46,4 +54,3 @@ elseif(CMAKE_BUILD_TYPE STREQUAL None)
# 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

@ -3,9 +3,6 @@ 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 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CPACK_IGNORE_FILE})
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

@ -20,7 +20,12 @@ function(add_clang_analyze_check)
endif() endif()
add_custom_target(clang-analyze-check-${_target} add_custom_target(clang-analyze-check-${_target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CLANG_CHECK_EXE} -analyze -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources}) COMMAND ${CLANG_CHECK_EXE}
-analyze
-extra-arg="-Wno-unknown-warning-option"
-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()
@ -28,4 +33,3 @@ function(add_clang_analyze_check)
message(STATUS " Clang-Check analyzer is not found") message(STATUS " Clang-Check analyzer is not found")
endif() endif()
endfunction() endfunction()

View File

@ -20,7 +20,11 @@ function(add_clang_tidy_check)
endif() endif()
add_custom_target(clang-tidy-check-${_target} add_custom_target(clang-tidy-check-${_target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CLANG_TIDY_EXE} -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources}) COMMAND ${CLANG_TIDY_EXE}
-extra-arg="-Wno-unknown-warning-option"
-p
${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()
@ -28,4 +32,3 @@ function(add_clang_tidy_check)
message(STATUS " ClangTidy analyzer is not found") message(STATUS " ClangTidy analyzer is not found")
endif() endif()
endfunction() endfunction()

View File

@ -3,15 +3,19 @@ function(add_clazy_check)
set(_sources ${ARGN}) set(_sources ${ARGN})
list(REMOVE_AT _sources 0) list(REMOVE_AT _sources 0)
find_program(CLAZY_EXE find_program(CLAZY_EXE NAMES clazy-standalone)
NAMES clazy-standalone)
if(CLAZY_EXE) if(CLAZY_EXE)
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(clazy-check-${_target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CLAZY_EXE} -checks=level2 -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources}) COMMAND ${CLAZY_EXE}
-checks=level2
-extra-arg="-Wno-unknown-warning-option"
-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()
@ -19,4 +23,3 @@ function(add_clazy_check)
message(STATUS " Clazy analyzer is not found") message(STATUS " Clazy analyzer is not found")
endif() endif()
endfunction() endfunction()

View File

@ -10,12 +10,13 @@ function(add_pvs_check)
endif() endif()
pvs_studio_add_target(TARGET pvs-check-${_target} pvs_studio_add_target(TARGET pvs-check-${_target}
DEPENDS ${_target} DEPENDS ${_target}
COMPILE_COMMANDS COMPILE_COMMANDS HIDE_HELP OUTPUT
HIDE_HELP FORMAT errorfile
OUTPUT FORMAT errorfile
CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${_target}.cfg" CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${_target}.cfg"
ARGS --analysis-mode 29 ARGS --analysis-mode
--exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${_target}_autogen 29
--exclude-path
${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()
@ -24,7 +25,7 @@ function(add_pvs_check)
endif() endif()
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " Option CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.") message(
STATUS " Option CMAKE_EXPORT_COMPILE_COMMANDS is not set. PVS checks will be disabled.")
endif() endif()
endfunction() endfunction()

View File

@ -46,4 +46,3 @@ include(CMLibToday)
include(CMLibConfigHPPGenerate) include(CMLibConfigHPPGenerate)
include(CMLibCPackSources) include(CMLibCPackSources)
include(CMLibUninstall) include(CMLibUninstall)

View File

@ -4,7 +4,11 @@ function(add_common_library)
set(oneValueArgs TARGET OUTPUT_NAME) set(oneValueArgs TARGET OUTPUT_NAME)
set(multiValueArgs SOURCES) set(multiValueArgs SOURCES)
cmake_parse_arguments(_LOCAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_LOCAL
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})
set(LIBNAME ${_LOCAL_TARGET}) set(LIBNAME ${_LOCAL_TARGET})
set(SOURCES ${_LOCAL_SOURCES}) set(SOURCES ${_LOCAL_SOURCES})
@ -15,8 +19,7 @@ function(add_common_library)
endif() endif()
add_library(${LIBNAME} OBJECT ${SOURCES}) add_library(${LIBNAME} OBJECT ${SOURCES})
target_include_directories( target_include_directories(${LIBNAME}
${LIBNAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> 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}>)
@ -25,24 +28,27 @@ function(add_common_library)
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(${LIBNAME}_shared
PROPERTIES PROPERTIES VERSION
VERSION ${PROJECT_VERSION} ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR} SOVERSION
OUTPUT_NAME ${OUTNAME} ${PROJECT_VERSION_MAJOR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) OUTPUT_NAME
${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(${LIBNAME}_static
PROPERTIES PROPERTIES OUTPUT_NAME
OUTPUT_NAME ${OUTNAME} ${OUTNAME}
ARCHIVE_OUTPUT_DIRECTORY ${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,8 +12,7 @@ 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( target_include_directories(${Name}
${Name}
PUBLIC $<INSTALL_INTERFACE:include> 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}>
@ -26,7 +25,11 @@ 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} 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)
@ -44,4 +47,3 @@ function(common_target_properties Name)
endif() endif()
endfunction() endfunction()

View File

@ -1,8 +1,7 @@
# 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" elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR 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,12 +12,10 @@ 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" elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR 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)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_COMPILER_IS_MSVC ON) set(CMAKE_CXX_COMPILER_IS_MSVC ON)
endif() endif()

View File

@ -1,11 +1,12 @@
include(WriteCompilerDetectionHeader) include(WriteCompilerDetectionHeader)
write_compiler_detection_header( write_compiler_detection_header(FILE include/compiler_features.hpp
FILE include/compiler_features.hpp
PREFIX ${CMLIB_PROJECT_NAME_CANONICAL} PREFIX ${CMLIB_PROJECT_NAME_CANONICAL}
COMPILERS GNU Clang MSVC Intel COMPILERS GNU
FEATURES Clang
cxx_nullptr MSVC
Intel
FEATURES cxx_nullptr
cxx_override cxx_override
cxx_alignas cxx_alignas
cxx_alignof cxx_alignof
@ -13,6 +14,4 @@ write_compiler_detection_header(
cxx_auto_type cxx_auto_type
cxx_constexpr cxx_constexpr
cxx_digit_separators cxx_digit_separators
cxx_range_for cxx_range_for)
)

View File

@ -18,9 +18,7 @@ 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 if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_INTEL OR CMAKE_CXX_COMPILER_IS_GCC)
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)
@ -91,9 +89,15 @@ if(CMAKE_CXX_COMPILER_IS_CLANG
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 NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) find_program(CMAKE_GCC_AR
find_program(CMAKE_GCC_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX}
find_program(CMAKE_GCC_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_GCC_NM
NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm
HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_GCC_RANLIB
NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib
HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(CMAKE_GCC_AR AND CMAKE_GCC_NM AND CMAKE_GCC_RANLIB) 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)
@ -103,7 +107,9 @@ if(CMAKE_CXX_COMPILER_IS_CLANG
set(CMAKE_NM "${CMAKE_GCC_NM}") set(CMAKE_NM "${CMAKE_GCC_NM}")
set(CMAKE_RANLIB "${CMAKE_GCC_RANLIB}") set(CMAKE_RANLIB "${CMAKE_GCC_RANLIB}")
else() else()
message(WARNING "GCC indicates LTO support, but binutils wrappers could not be found. Disabling LTO.") message(
WARNING
"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)
@ -136,4 +142,3 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
add_definitions(-DQT_NO_VERSION_TAGGING) add_definitions(-DQT_NO_VERSION_TAGGING)
list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/e2k-linux-gnu") list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/e2k-linux-gnu")
endif() endif()

View File

@ -17,11 +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 ${_dir}/CMakeFiles file(REMOVE_RECURSE
${_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

@ -2,7 +2,8 @@ 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 AND NOT CMAKE_${LANG}_COMPILER MATCHES ".*/distcc$") if(NOT DEFINED CMAKE_${LANG}_COMPILER_LAUNCHER
AND NOT CMAKE_${LANG}_COMPILER MATCHES ".*/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()

View File

@ -1,16 +1,31 @@
set(BREATHE_FOUND AUTO CACHE STRING "Enable Breathe documentation generator") set(BREATHE_FOUND AUTO CACHE STRING "Enable Breathe documentation generator")
set_property(CACHE BREATHE_FOUND PROPERTY STRINGS ON OFF AUTO) set_property(CACHE BREATHE_FOUND
PROPERTY STRINGS
ON
OFF
AUTO)
find_package(Doxygen) find_package(Doxygen)
find_package(Perl) find_package(Perl)
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4 3.3 3.2) set(Python_ADDITIONAL_VERSIONS
3.7
3.6
3.5
3.4
3.3
3.2)
find_package(PythonInterp) find_package(PythonInterp)
if(PYTHONINTERP_FOUND) if(PYTHONINTERP_FOUND)
find_package(Sphinx) find_package(Sphinx)
include(FindPythonModule) include(FindPythonModule)
find_python_module(breathe) find_python_module(breathe)
find_python_module(recommonmark) find_python_module(recommonmark)
if(DOXYGEN_FOUND AND PERL_FOUND AND PYTHONINTERP_FOUND AND SPHINX_EXECUTABLE AND breathe AND recommonmark) if(DOXYGEN_FOUND
AND PERL_FOUND
AND PYTHONINTERP_FOUND
AND SPHINX_EXECUTABLE
AND breathe
AND recommonmark)
set(BREATHE_FOUND ON CACHE STRING "Breathe documentation generator enabled" FORCE) set(BREATHE_FOUND ON CACHE STRING "Breathe documentation generator enabled" FORCE)
else() else()
set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE)
@ -19,13 +34,24 @@ else()
set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE)
endif() endif()
function(add_breathe_target) function(add_breathe_target)
set(options) set(options)
set(oneValueArgs SOURCE_DIR BUILD_DIR CACHE_DIR HTML_DIR DOXY_FILE CONF_FILE TARGET_NAME COMMENT) set(oneValueArgs
SOURCE_DIR
BUILD_DIR
CACHE_DIR
HTML_DIR
DOXY_FILE
CONF_FILE
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(BREATHE_DOCS_BUILD_DIR ${_BREATHE_BUILD_DIR}) set(BREATHE_DOCS_BUILD_DIR ${_BREATHE_BUILD_DIR})
set(GENERATE_XML YES) set(GENERATE_XML YES)
@ -37,12 +63,17 @@ function(add_breathe_target)
configure_file(${_BREATHE_DOXY_FILE} ${_BREATHE_BUILD_DIR}/Doxyfile @ONLY) configure_file(${_BREATHE_DOXY_FILE} ${_BREATHE_BUILD_DIR}/Doxyfile @ONLY)
add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM
COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${_BREATHE_BUILD_DIR} COMMAND ${SPHINX_EXECUTABLE}
-d ${_BREATHE_CACHE_DIR} -q
-b
html
-c
${_BREATHE_BUILD_DIR}
-d
${_BREATHE_CACHE_DIR}
${_BREATHE_SOURCE_DIR} ${_BREATHE_SOURCE_DIR}
${_BREATHE_HTML_DIR} ${_BREATHE_HTML_DIR}
COMMENT "Building ${_BREATHE_TARGET_NAME} documentation with Breathe" COMMENT "Building ${_BREATHE_TARGET_NAME} documentation with Breathe")
)
else() else()
add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM
COMMENT "Breathe is not found. Skipping target ${_BREATHE_TARGET_NAME} build") COMMENT "Breathe is not found. Skipping target ${_BREATHE_TARGET_NAME} build")

View File

@ -1,5 +1,9 @@
set(DOXYGEN_FOUND AUTO CACHE STRING "Enable Doxygen documentation generator") set(DOXYGEN_FOUND AUTO CACHE STRING "Enable Doxygen documentation generator")
set_property(CACHE DOXYGEN_FOUND PROPERTY STRINGS ON OFF AUTO) set_property(CACHE DOXYGEN_FOUND
PROPERTY STRINGS
ON
OFF
AUTO)
find_package(Doxygen) find_package(Doxygen)
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
@ -8,13 +12,21 @@ else()
set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE) set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
endif() endif()
function(add_doxygen_target) function(add_doxygen_target)
set(options) set(options)
set(oneValueArgs TARGET_NAME DOXY_FILE OUTPUT_DIRECTORY LATEX HTML) set(oneValueArgs
TARGET_NAME
DOXY_FILE
OUTPUT_DIRECTORY
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)

View File

@ -10,8 +10,7 @@ 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} set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
endif() endif()
endmacro() endmacro()
@ -23,7 +22,10 @@ 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 _target _file _flag) macro(remove_flag_from_file
_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)
@ -41,19 +43,21 @@ 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} get_source_file_property(_source_file_cxx_flags ${_source_file} COMPILE_FLAGS)
COMPILE_FLAGS)
if(_source_file_cxx_flags) if(_source_file_cxx_flags)
separate_arguments(_source_file_cxx_flags UNIX_COMMAND separate_arguments(_source_file_cxx_flags UNIX_COMMAND ${_source_file_cxx_flags})
${_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 string(REPLACE ";"
" "
_source_file_cxx_flags_string
"${_source_file_cxx_flags}") "${_source_file_cxx_flags}")
set_source_files_properties(${_source_file} PROPERTIES COMPILE_FLAGS set_source_files_properties(${_source_file}
PROPERTIES
COMPILE_FLAGS
"${_source_file_cxx_flags_string}") "${_source_file_cxx_flags_string}")
endforeach() endforeach()
endif() endif()
@ -63,18 +67,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 separate_arguments(_source_file_cxx_flags UNIX_COMMAND ${_source_file_cxx_flags})
${_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 ";" " " _cached_${_target}_${_file}_cxx_flags_string string(REPLACE ";"
" "
_cached_${_target}_${_file}_cxx_flags_string
"${_cached_${_target}_${_file}_cxx_flags}") "${_cached_${_target}_${_file}_cxx_flags}")
set_source_files_properties( set_source_files_properties(${_file}
${_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

@ -8,12 +8,14 @@ function(add_uncrustify_format)
if(NOT TARGET uncrustify-format) if(NOT TARGET uncrustify-format)
add_custom_target(uncrustify-format) add_custom_target(uncrustify-format)
endif() endif()
list(APPEND OPTS -lCPP --replace --no-backup) list(APPEND OPTS
-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 OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) list(APPEND OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
endif() endif()
add_custom_target(uncrustify-format-${_target} add_custom_target(uncrustify-format-${_target} COMMAND ${UNCRUSTIFY_EXE} ${OPTS} ${_sources})
COMMAND ${UNCRUSTIFY_EXE} ${OPTS} ${_sources})
add_dependencies(uncrustify-format uncrustify-format-${_target}) add_dependencies(uncrustify-format uncrustify-format-${_target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")

View File

@ -1,6 +1,10 @@
# CMLIB_PROJECT_NAME_CANONICAL # CMLIB_PROJECT_NAME_CANONICAL
string(TOUPPER ${PROJECT_NAME} _project_name_uppercase) string(TOUPPER ${PROJECT_NAME} _project_name_uppercase)
string(REGEX REPLACE "[ -]" "_" _project_name_fixed ${_project_name_uppercase}) string(REGEX
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
@ -19,4 +23,3 @@ if(IS_DIRECTORY "${CMLIB_MODULE_DIR}")
else() else()
message(FATAL_ERROR "CMLib directory not found.") message(FATAL_ERROR "CMLib directory not found.")
endif() endif()

View File

@ -32,4 +32,3 @@ else()
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
endif() endif()
endif() endif()

View File

@ -51,57 +51,53 @@
include(CheckTypeSize) include(CheckTypeSize)
MACRO(cmlib_test_large_files VARIABLE) macro(cmlib_test_large_files VARIABLE)
IF(NOT DEFINED ${VARIABLE}) if(NOT DEFINED ${VARIABLE})
# On most platforms it is probably overkill to first test the flags for 64-bit off_t, # On most platforms it is probably overkill to first test the flags for 64-bit off_t,
# and then separately fseeko. However, in the future we might have 128-bit filesystems # and then separately fseeko. However, in the future we might have 128-bit filesystems
# (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64. # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
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}" try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c")
"${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}" try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
"${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64") 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}" try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
"${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_LARGE_FILES") 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}" try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
"${CMLIB_MODULE_DIR}/tests/TestFileOffsetBits.c"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE") 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()
if(NOT FILE64_OK) if(NOT FILE64_OK)
MESSAGE(STATUS "Checking for 64-bit off_t - not present") message(STATUS "Checking for 64-bit off_t - not present")
else() else()
# 64-bit off_t found. Now check that ftello/fseeko is available. # 64-bit off_t found. Now check that ftello/fseeko is available.
@ -109,21 +105,21 @@ MACRO(cmlib_test_large_files VARIABLE)
configure_file("${CMLIB_MODULE_DIR}/tests/TestLargeFiles.c.in" configure_file("${CMLIB_MODULE_DIR}/tests/TestLargeFiles.c.in"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c") "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
MESSAGE(STATUS "Checking for fseeko/ftello") message(STATUS "Checking for fseeko/ftello")
# Test if ftello/fseeko are available # Test if ftello/fseeko are available
TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}" try_compile(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c") "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
if(FSEEKO_COMPILE_OK) if(FSEEKO_COMPILE_OK)
MESSAGE(STATUS "Checking for fseeko/ftello - present") message(STATUS "Checking for fseeko/ftello - present")
endif() endif()
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(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE") 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)
@ -134,29 +130,27 @@ 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}" try_compile(FILE64_OK "${CMAKE_BINARY_DIR}" "${CMLIB_MODULE_DIR}/tests/TestWindowsFSeek.c")
"${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} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" 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} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" 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()
endif() endif()
ENDIF() endif()
ENDMACRO(cmlib_test_large_files VARIABLE) endmacro(cmlib_test_large_files VARIABLE)

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 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_organization_file})
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 "^([0-9A-Za-z ,.]+)\n" _ ${_org}) string(REGEX MATCH
"^([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

@ -3,8 +3,8 @@ function(set_project_version)
message(FATAL_ERROR "Please set project version in X.Y.Z format") message(FATAL_ERROR "Please set project version in X.Y.Z format")
endif() endif()
math(EXPR _version_int math(
EXPR _version_int
"(${PROJECT_VERSION_MAJOR} << 16) + (${PROJECT_VERSION_MINOR} << 8) + ${PROJECT_VERSION_PATCH}") "(${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

@ -5,7 +5,11 @@ function(qt_translation)
set(oneValueArgs TARGET TS_DIR) set(oneValueArgs TARGET TS_DIR)
set(multiValueArgs LANGUAGES) set(multiValueArgs LANGUAGES)
cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_QTTR
"${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})
@ -22,7 +26,12 @@ function(qt_translation)
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(${_target}_l10n_${_lang}
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_sources} -ts ${_ts_dir}/${_ts} -target-language ${_lang} COMMAND ${Qt5_LUPDATE_EXECUTABLE}
${_sources}
-ts
${_ts_dir}/${_ts}
-target-language
${_lang}
DEPENDS ${_sources}) DEPENDS ${_sources})
if(NOT EXISTS "${_ts_dir}/${_ts}") if(NOT EXISTS "${_ts_dir}/${_ts}")
@ -33,12 +42,14 @@ function(qt_translation)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_qm} add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${_qm}
COMMAND ${Qt5_LRELEASE_EXECUTABLE} COMMAND ${Qt5_LRELEASE_EXECUTABLE}
ARGS ${_ts_dir}/${_ts} -qm ${CMAKE_BINARY_DIR}/${_qm} ARGS
${_ts_dir}/${_ts}
-qm
${CMAKE_BINARY_DIR}/${_qm}
DEPENDS ${_ts} ${_sources}) DEPENDS ${_ts} ${_sources})
endforeach() endforeach()
configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc)
${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})
@ -50,4 +61,3 @@ function(qt_translation)
add_dependencies(${_target} ${_target}_qrc) add_dependencies(${_target} ${_target}_qrc)
target_sources(${_target} PUBLIC ${_qrc}) target_sources(${_target} PUBLIC ${_qrc})
endfunction() endfunction()

View File

@ -10,4 +10,3 @@ if(IS_DIRECTORY "${CMLIB_MODULE_DIR}")
else() else()
message(FATAL_ERROR "CMLib directory not found.") message(FATAL_ERROR "CMLib directory not found.")
endif() endif()

View File

@ -4,5 +4,9 @@ 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 REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" TODAY ${TODAY}) string(REGEX
REPLACE "(..)/(..)/(....).*"
"\\3-\\2-\\1"
TODAY
${TODAY})
endif() endif()

View File

@ -1,8 +1,8 @@
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" 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()