1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-13 03:19:53 +03:00
opentx/cmake/Macros.cmake
Max Paperno 1f788723f9 Build system updates, including -Werror on TravisCI (#4202)
* [TravisCI] Build using avr-gcc 4.9.2 (up from 4.8.2). Relies on https://github.com/opentx/opentx/pull/4169 . Fixes all linker warnings, makes clean build.

* [build] Add ARM/AVR compiler version check/display and a workaround for avr-gcc linker warnings when using WARNINGS_AS_ERRORS=true.

* [TravisCI] Enable -Werror on all build targets (WARNINGS_AS_ERRORS=true).

* [build] CMake script updates:
  Enable WARNINGS_AS_ERRORS option for all targets (not just firmware);
  Consolidate some C/CXX flag settings for firmware target, avoid duplication/redundancy;
  All warning flags are now passed to linker (GCC only);
  Add a "build report" for each main target showing compiler, flags, and defines, with verbosity controlled by new VERBOSE_CMAKELISTS option;
  Added properties to PCB, TRANSLATIONS, and a few other options (makes option selector lists in cmake-gui);
  Add macro for conditionally adding C++11 flag;
  Silence CMake >3.0 warnings about CMP0054 policy not being set;
  Reverts AVR linker -Werror workaround;
  Misc. cleanup/consolidation.

* [build] More CMakeLists updates:
  Silence superfluous "CRT_SECURE" series MSVC warnings;
  Formalize finding pthread lib/dll on MSVC builds and fix some issues with install target script;
  Add property string lists to more options;
  Quotes some paths with possible spaces, & other minor cosmetics.

* [build] firmware/bootloader: Remove remaining CMake default compiler flags and add FIRMWARE_C[XX}_FLAGS[_DEBUG] options for user to specify additional flags. Also move ASM language call to silence CMake warning w/MSVC.

* [build] Workaround bogus "uninitialized" warnings from AVR linker.

* [tests] Add custom printer for less verbose gtest output (use --verbose option to revert to gtest default).

* [build] Use less verbose CMake output for TravisCI builds. Formalize search for gtest code and enable gtests target on WIN32-GCC. Minor language fix.
2017-01-08 09:44:33 +01:00

71 lines
2.7 KiB
CMake

macro(today RESULT)
if(WIN32)
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(..)/(..)/(....).*" "\\1.\\2.\\3" ${RESULT} ${${RESULT}})
string(SUBSTRING ${${RESULT}} 0 10 ${RESULT})
elseif(UNIX)
execute_process(COMMAND "date" "+%Y-%m-%d" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(....)-(..)-(..).*" "\\1-\\2-\\3" ${RESULT} ${${RESULT}})
else(WIN32)
message(SEND_ERROR "date not implemented")
set(${RESULT} 00.00.0000)
endif(WIN32)
endmacro(today)
macro(now RESULT)
if(WIN32)
execute_process(COMMAND "cmd" " /C time /T" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(..):(..).*" "\\1:\\2:00" ${RESULT} ${${RESULT}})
elseif(UNIX)
execute_process(COMMAND "date" "+%H:%M:%S" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(..):(..):(..).*" "\\1:\\2:\\3" ${RESULT} ${${RESULT}})
else(WIN32)
message(SEND_ERROR "time not implemented")
set(${RESULT} 00:00:00)
endif(WIN32)
endmacro(now)
macro(git_id RESULT)
if(WIN32)
execute_process(COMMAND "cmd" " /C git --git-dir=${PROJECT_SOURCE_DIR}/.git rev-parse --short=8 HEAD" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(.*)\n" "\\1" ${RESULT} ${${RESULT}})
elseif(UNIX)
execute_process(COMMAND "git" "--git-dir=${PROJECT_SOURCE_DIR}/.git" "rev-parse" "--short=8" "HEAD" OUTPUT_VARIABLE ${RESULT})
string(REGEX REPLACE "(.*)\n" "\\1" ${RESULT} ${${RESULT}})
else(WIN32)
message(SEND_ERROR "Git ID implemented")
set(${RESULT} 0)
endif(WIN32)
endmacro(git_id)
macro(use_cxx11)
if (CMAKE_VERSION VERSION_LESS "3.1" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}")
endif ()
endmacro(use_cxx11)
macro(PrintTargetReport targetName)
if(CMAKE_CXX_COMPILER MATCHES "/cl\\.exe$")
set(cpp_version ${MSVC_VERSION})
else()
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE cpp_version)
endif()
if(cpp_version)
string(STRIP "v${cpp_version}" cpp_version)
else()
set(cpp_version "WARNING: COMPILER NOT FOUND!")
endif()
message("TARGET ${targetName}: cpp compiler ${CMAKE_CXX_COMPILER} ${cpp_version}")
if(VERBOSE_CMAKELISTS)
get_directory_property(DirOpts COMPILE_OPTIONS)
get_directory_property(DirDefs COMPILE_DEFINITIONS)
string(REPLACE ";" " " DirOpts "${DirOpts}")
string(REPLACE ";" "; " DirDefs "${DirDefs}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
message("\twith cpp flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}} ${DirOpts}")
message("\twith link flags: ${CMAKE_EXE_LINKER_FLAGS}")
message("\twith defs: ${DirDefs}")
message("--------------")
endif()
endmacro(PrintTargetReport)