diff --git a/MyxCMake/MyxCMakeConfig.cmake b/MyxCMake/MyxCMakeConfig.cmake index f5eb5d8..d450020 100644 --- a/MyxCMake/MyxCMakeConfig.cmake +++ b/MyxCMake/MyxCMakeConfig.cmake @@ -28,16 +28,20 @@ include(CMakeDependentOption) include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake) +include(${MYX_CMAKE_LIB_DIR}/macro/CheckEnableCxxCompilerFlag.cmake) +include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake) include(${MYX_CMAKE_LIB_DIR}/PopulateCMakeBinaryDir.cmake) include(${MYX_CMAKE_LIB_DIR}/CurrentDate.cmake) -include(${MYX_CMAKE_LIB_DIR}/ColoredMessages.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake) include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake) include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake) include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake) include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake) +include(${MYX_CMAKE_LIB_DIR}/LSBInfo.cmake) +include(${MYX_CMAKE_LIB_DIR}/Toolchain.cmake) +include(${MYX_CMAKE_LIB_DIR}/CompilerFlags.cmake) include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake) include(${MYX_CMAKE_LIB_DIR}/AddLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake) diff --git a/MyxCMake/MyxCMakeConfigVersion.cmake b/MyxCMake/MyxCMakeConfigVersion.cmake index 38b71d2..9f96b0f 100644 --- a/MyxCMake/MyxCMakeConfigVersion.cmake +++ b/MyxCMake/MyxCMakeConfigVersion.cmake @@ -1,4 +1,4 @@ -set(MYX_CMAKE_PACKAGE_VERSION "2.0.3") +set(MYX_CMAKE_PACKAGE_VERSION "2.0.4") if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() diff --git a/MyxCMake/lib/CompilerFlags.cmake b/MyxCMake/lib/CompilerFlags.cmake new file mode 100644 index 0000000..29fb84e --- /dev/null +++ b/MyxCMake/lib/CompilerFlags.cmake @@ -0,0 +1,45 @@ +include_guard(GLOBAL) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +# cmake-format: off + if((MYX_CMAKE_LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE") AND + (MYX_CMAKE_LSB_CODENAME STREQUAL "smolensk") AND + (MYX_CMAKE_LSB_RELEASE_VERSION STREQUAL "1.5")) +# cmake-format: on + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_EXTENSIONS ON) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k") + set(CMAKE_CXX_STANDARD 14) + set(CMAKE_CXX_EXTENSIONS ON) + add_compile_options(-Wno-invalid-offsetof) + list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/e2k-linux-gnu") + endif() + if(CMAKE_COLOR_MAKEFILE) + check_enable_cxx_compiler_flag(-fdiagnostics-color=auto) + endif() +endif() + +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_COLOR_MAKEFILE) + check_enable_cxx_compiler_flag(-fcolor-diagnostics) + endif() +endif() + +option(MYX_CMAKE_WARNINGS_NORMAL "Normal level" ON) +cmake_dependent_option(MYX_CMAKE_WARNINGS_VERBOSE "Verbose level" OFF "MYX_CMAKE_WARNINGS_NORMAL" OFF) + +if(MYX_CMAKE_WARNINGS_NORMAL) + if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR + (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) + check_enable_cxx_compiler_flag(-Wall) + check_enable_cxx_compiler_flag(-Wextra) + endif() +endif() + +if(MYX_CMAKE_WARNINGS_VERBOSE) + if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR + (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) + check_enable_cxx_compiler_flag(-Wpedantic) + check_enable_cxx_compiler_flag(-Wnoexcept) + endif() +endif() diff --git a/MyxCMake/lib/LSBInfo.cmake b/MyxCMake/lib/LSBInfo.cmake new file mode 100644 index 0000000..0f15d86 --- /dev/null +++ b/MyxCMake/lib/LSBInfo.cmake @@ -0,0 +1,34 @@ +include_guard(GLOBAL) + +if(CMAKE_SYSTEM_NAME STREQUAL Linux) + set(MYX_CMAKE_LSB_DISTRIBUTOR_ID "unknown") + set(MYX_CMAKE_LSB_CODENAME "unknown") + set(MYX_CMAKE_LSB_RELEASE_VERSION "unknown") + + if(CMAKE_CROSSCOMPILING) + return() + endif() + + if(EXISTS /etc/mcst_version) + set(MYX_CMAKE_LSB_DISTRIBUTOR_ID "ElbrusD") + set(MYX_CMAKE_LSB_CODENAME "Jessie") + execute_process(COMMAND cat /etc/mcst_version + OUTPUT_VARIABLE MYX_CMAKE_LSB_RELEASE_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + find_program(LSB_RELEASE_EXECUTABLE lsb_release) + # cmake-format: off + if(LSB_RELEASE_EXECUTABLE) + execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si + OUTPUT_VARIABLE MYX_CMAKE_LSB_DISTRIBUTOR_ID + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sc + OUTPUT_VARIABLE MYX_CMAKE_LSB_CODENAME + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sr + OUTPUT_VARIABLE MYX_CMAKE_LSB_RELEASE_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() + # cmake-format: on + endif() +endif() diff --git a/MyxCMake/lib/Toolchain.cmake b/MyxCMake/lib/Toolchain.cmake new file mode 100644 index 0000000..817a113 --- /dev/null +++ b/MyxCMake/lib/Toolchain.cmake @@ -0,0 +1,35 @@ +include_guard(GLOBAL) + +# Предпочтительные пути к утилитам для компоновки +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +# cmake-format: off + # Astra Linux Smolensk 1.5 + if((MYX_CMAKE_LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE") AND + (MYX_CMAKE_LSB_CODENAME STREQUAL "smolensk") AND + (MYX_CMAKE_LSB_RELEASE_VERSION STREQUAL "1.5")) + find_program(CMAKE_GCC_AR NAMES "/usr/bin/x86_64-linux-gnu-gcc-ar-4.7") + find_program(CMAKE_GCC_NM NAMES "/usr/bin/x86_64-linux-gnu-gcc-nm-4.7") + find_program(CMAKE_GCC_RANLIB NAMES "/usr/bin/x86_64-linux-gnu-gcc-ranlib-4.7") + # Elbrus E2K + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k") + find_program(CMAKE_GCC_AR NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/ar") + find_program(CMAKE_GCC_NM NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/nm") + find_program(CMAKE_GCC_RANLIB NAMES "/usr/${CMAKE_SYSTEM_PROCESSOR}-linux/bin/ranlib") + # Другие версии Linux + else() + find_program(CMAKE_GCC_AR NAMES "gcc-ar" "ar") + find_program(CMAKE_GCC_NM NAMES "gcc-nm" "nm") + find_program(CMAKE_GCC_RANLIB NAMES "gcc-ranlib" "ranlib") + endif() +# cmake-format: on + + if(CMAKE_GCC_AR) + set(CMAKE_AR ${CMAKE_GCC_AR} CACHE STRING "" FORCE) + endif() + if(CMAKE_GCC_NM) + set(CMAKE_NM ${CMAKE_GCC_NM} CACHE STRING "" FORCE) + endif() + if(CMAKE_GCC_RANLIB) + set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE STRING "" FORCE) + endif() +endif() diff --git a/MyxCMake/lib/macro/CheckEnableCxxCompilerFlag.cmake b/MyxCMake/lib/macro/CheckEnableCxxCompilerFlag.cmake new file mode 100644 index 0000000..bc94984 --- /dev/null +++ b/MyxCMake/lib/macro/CheckEnableCxxCompilerFlag.cmake @@ -0,0 +1,34 @@ +include_guard(GLOBAL) + +# based on https://github.com/bluescarni/yacma + +include(CheckCXXCompilerFlag) + +macro(check_enable_cxx_compiler_flag flag) + set(options) + set(oneValueArgs TARGET) + set(multiValueArgs) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(cmake_required_quiet TRUE) + check_cxx_compiler_flag("${flag}" check_cxx_flag) + unset(cmake_required_quiet) + + if(check_cxx_flag) + if(ARG_TARGET) + target_compile_options(${ARG_TARGET} PUBLIC ${flag}) + else() + add_compile_options(${flag}) + endif() + endif() + + unset(check_cxx_flag CACHE) + foreach(iter IN LISTS oneValueArgs multiValueArgs) + unset(ARG_${iter}) + endforeach() + unset(ARG_UNPARSED_ARGUMENTS) + unset(multiValueArgs) + unset(oneValueArgs) + unset(options) +endmacro() + diff --git a/MyxCMake/lib/macro/FindPackages.cmake b/MyxCMake/lib/macro/FindPackages.cmake index 9727195..4d933d4 100644 --- a/MyxCMake/lib/macro/FindPackages.cmake +++ b/MyxCMake/lib/macro/FindPackages.cmake @@ -4,7 +4,6 @@ macro(myx_find_packages) set(options) set(oneValueArgs) set(multiValueArgs PACKAGES Boost Qt5 Qt5Private) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) foreach(iter ${ARG_PACKAGES}) diff --git a/README.md b/README.md index 3afd056..cc1277f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Установка В корневом каталоге проекта создать каталог `cmake` и распаковать в него -[архив](../../../releases/download/2.0.3/myx-cmake-local-2.0.3.tar.xz ). +[архив](../../../releases/download/2.0.4/myx-cmake-local-2.0.4.tar.xz ). ## Использование diff --git a/VERSION b/VERSION index 50ffc5a..2165f8f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.3 +2.0.4 diff --git a/debian/CMakeLists.txt b/debian/CMakeLists.txt index 87f1c0a..a3bf449 100644 --- a/debian/CMakeLists.txt +++ b/debian/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.6 FATAL_ERROR) -project(myx-cmake VERSION 2.0.3 LANGUAGES) +project(myx-cmake VERSION 2.0.4 LANGUAGES) include(GNUInstallDirs) file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake diff --git a/debian/changelog b/debian/changelog index b3ba04a..f6f672b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -myx-cmake (2.0.3) unstable; urgency=medium +myx-cmake (2.0.4) unstable; urgency=medium * New version. diff --git a/myx_setup.cmake b/myx_setup.cmake index 609b998..101b720 100644 --- a/myx_setup.cmake +++ b/myx_setup.cmake @@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR}) set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR}) endif() if(MYX_CMAKE_DIR) - find_package(MyxCMake 2.0.3 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) + find_package(MyxCMake 2.0.4 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") else() if(MYX_CMAKE_USE_SYSTEM) - find_package(MyxCMake 2.0.3 REQUIRED) + find_package(MyxCMake 2.0.4 REQUIRED) myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===") else() include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)