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.
This commit is contained in:
Max Paperno
2017-01-08 09:44:33 +01:00
committed by Bertrand Songis
parent 54742fcad9
commit 1f788723f9
15 changed files with 387 additions and 173 deletions
+57 -49
View File
@@ -53,41 +53,39 @@ else()
remove_definitions(-DSIMU_AUDIO)
endif()
find_package(Lupdate)
if(LUPDATE_FOUND)
message("Qt lupdate: " ${LUPDATE_EXECUTABLE})
else()
message("Qt lupdate not found, 'translations' target will not be availabe.")
endif()
add_definitions(-DSIMU)
add_definitions(-DQXT_STATIC)
if (NOT MSVC AND ${CMAKE_VERSION} VERSION_LESS 3.1.0})
message("companion: adding -std=gnu++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
if(NOT MSVC)
set(WARNING_FLAGS "${WARNING_FLAGS} -Wall")
if(WARNINGS_AS_ERRORS)
set(WARNING_FLAGS "${WARNING_FLAGS} -Werror")
endif()
else()
# silence lots of warnings regarding "insecure" use of functions (sprintf, strcpy, etc)
set(WARNING_FLAGS "${WARNING_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
if(WARNINGS_AS_ERRORS)
set(WARNING_FLAGS "${WARNING_FLAGS} /WX")
endif()
endif()
if(WIN32)
include_directories(SYSTEM ${WIN_INCLUDE_DIRS})
if(MSVC)
set(CMAKE_CXX_FLAGS "/EHsc /LD /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /LD /MP")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
message("companion: using MSVC with ${CMAKE_CXX_FLAGS}")
elseif(MINGW)
# struct packing breaks on MinGW w/out -mno-ms-bitfields: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 & http://stackoverflow.com/questions/24015852/struct-packing-and-alignment-with-mingw
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields -mwindows")
message("companion: using MinGW with ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-ms-bitfields")
endif()
else()
set(PTHREAD_LIBRARY pthread)
add_definitions(-Wall)
link_directories(/usr/local/lib)
endif()
set(RADIO_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/radio/src)
set(SIMU_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src/simulation)
set(COMPANION_SRC_DIRECTORY ${PROJECT_SOURCE_DIR}/companion/src)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
include_directories(
${CMAKE_BINARY_DIR}
@@ -101,6 +99,8 @@ include_directories(
${COMPANION_SRC_DIRECTORY}/storage
)
############# Supporting libraries ###############
add_subdirectory(shared)
add_subdirectory(modeledit)
add_subdirectory(generaledit)
@@ -109,6 +109,8 @@ add_subdirectory(storage)
add_subdirectory(thirdparty/qcustomplot)
add_subdirectory(thirdparty/qxtcommandoptions)
############# Common lib ###############
set(common_SRCS
eeprominterface.cpp
firmwares/er9x/er9xeeprom.cpp
@@ -124,6 +126,8 @@ qt5_wrap_cpp(common_SRCS)
add_library(common ${common_SRCS})
qt5_use_modules(common Core Xml Widgets)
############# Companion ###############
set(companion_SRCS
helpers.cpp
helpers_html.cpp
@@ -222,10 +226,7 @@ configure_file(${COMPANION_SRC_DIRECTORY}/companion.desktop.in ${CMAKE_CURRENT_B
configure_file(${COMPANION_SRC_DIRECTORY}/simulator.desktop.in ${CMAKE_CURRENT_BINARY_DIR}/simulator.desktop @ONLY)
if(WIN32)
set(companion_SRCS ${companion_SRCS} icon.rc)
if(NOT MSVC)
set(CMAKE_EXE_LINKER_FLAGS -mwindows)
endif()
list(APPEND companion_SRCS icon.rc)
endif()
include_directories(${CMAKE_BINARY_DIR})
@@ -233,7 +234,7 @@ include_directories(${CMAKE_SOURCE_DIR})
set(LANGUAGES he pl pt ru de fr es it sv cs fi nl cn)
foreach(language ${LANGUAGES})
set(companion_TS ${companion_TS} translations/companion_${language}.ts)
list(APPEND companion_TS translations/companion_${language}.ts)
endforeach(language)
qt5_wrap_ui(companion_SRCS ${companion_UIS})
@@ -251,11 +252,13 @@ qt5_use_modules(${COMPANION_NAME} Core Widgets Network)
target_link_libraries(${COMPANION_NAME} PRIVATE generaledit modeledit simulation common qcustomplot shared storage ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${WIN_LINK_LIBRARIES})
############# Standalone simu ###############
PrintTargetReport("${COMPANION_NAME}")
############# Standalone simulator ###############
set(simu_SRCS
modeledit/node.cpp
modeledit/edge.cpp # TODO not needed
modeledit/edge.cpp
simulator.cpp
)
@@ -266,15 +269,28 @@ set(simu_MOC_HDRS
qt5_wrap_cpp(simu_SRCS ${simu_MOC_HDRS} )
if(WIN32)
set(simu_SRCS ${simu_SRCS} icon.rc)
list(APPEND simu_SRCS icon.rc)
endif()
add_executable(${SIMULATOR_NAME} MACOSX_BUNDLE WIN32 ${simu_SRCS} ${companion_RCC})
add_dependencies(${SIMULATOR_NAME} gen_qrc)
qt5_use_modules(${SIMULATOR_NAME} Core Widgets Multimedia)
# TODO not the same link command than companion?
target_link_libraries(${SIMULATOR_NAME} PRIVATE simulation common storage qxtcommandoptions ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${OPENTX_SIMULATOR_LIBS} ${WIN_LINK_LIBRARIES})
target_link_libraries(${SIMULATOR_NAME} PRIVATE simulation common storage qxtcommandoptions ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${WIN_LINK_LIBRARIES})
############# Translations ####################
find_package(Lupdate)
if(LUPDATE_FOUND)
message(STATUS "Qt lupdate: " ${LUPDATE_EXECUTABLE})
add_custom_target(translations
WORKING_DIRECTORY ${COMPANION_SRC_DIRECTORY}
COMMAND ${LUPDATE_EXECUTABLE} ${CMAKE_SOURCE_DIR} -no-obsolete -ts ${companion_TS}
)
else()
message(STATUS "Qt lupdate not found, 'translations' target will not be availabe.")
endif()
############# Install ####################
@@ -316,11 +332,11 @@ elseif(WIN32)
if(NOT WIN_DO_FULL_INSTALL)
# Just copy supporting DLLs to build folder
set(INSTALL_DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(INSTALL_DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message(STATUS "Partial install to " ${INSTALL_DESTINATION})
else()
# Full Windows installation with all supporting files
set(INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX})
set(INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}")
message(STATUS "Full install to " ${INSTALL_DESTINATION})
# companion & simulator binaries
install(TARGETS ${COMPANION_NAME} DESTINATION ${INSTALL_DESTINATION})
@@ -341,30 +357,33 @@ elseif(WIN32)
install(FILES ${QT_DLL_DIR}/../plugins/platforms/qwindows${INSTALL_TEMP_QTDLL_SFX}.dll DESTINATION ${INSTALL_DESTINATION}/platforms)
# ICU dlls
foreach(tmpfile ${INSTALL_TEMP_ICUDLL_FILES})
# Qt5.7+ doesn't use icu dlls anymore (at least with MinGW), hence optional
# Qt5.7+ doesn't use icu dlls anymore, hence optional
install(FILES ${QT_DLL_DIR}/${tmpfile}.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
endforeach()
# SDL dll
if(SDL_FOUND AND SDL_LIBRARY_PATH AND EXISTS "${SDL_LIBRARY_PATH}/SDL.dll")
set(SDL_DIR ${SDL_LIBRARY_PATH}) # this is also used by NSIS installer script
install(FILES ${SDL_DIR}/SDL.dll DESTINATION ${INSTALL_DESTINATION})
else()
elseif(SDL_FOUND)
message(WARNING "Installer: SDL.dll not found!")
endif()
# C++/system dlls, depends on compiler
if(MSVC)
set(WIN_SYSDIR "$ENV{windir}/SysWOW64") # This would be "system32" for a 64-bit build or on x86... but how to tell?
if(IS_DIRECTORY ${WIN_SYSDIR})
install(FILES ${WIN_SYSDIR}/msvcp140.dll ${WIN_SYSDIR}/vcruntime140.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
string(REPLACE "\\" "/" WIN_SYSDIR "$ENV{windir}")
set(WIN_SYSDIR "${WIN_SYSDIR}/SysWOW64") # This would be "system32" for a 64-bit build or on x86... but how to tell?
if(IS_DIRECTORY "${WIN_SYSDIR}")
install(FILES "${WIN_SYSDIR}/msvcp140.dll" "${WIN_SYSDIR}/vcruntime140.dll" DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
endif()
if(WIN_PTHREAD_DLL)
install(FILES "${WIN_PTHREAD_DLL}" DESTINATION ${INSTALL_DESTINATION})
endif()
install(FILES "${WIN_PTHREAD_BASE_PATH}/lib/pthreadVC2.dll" DESTINATION ${INSTALL_DESTINATION})
elseif(MINGW)
get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH)
if(IS_DIRECTORY ${MINGW_DIR})
install(FILES ${MINGW_DIR}/libgcc_s_dw2-1.dll ${MINGW_DIR}/libstdc++-6.dll ${MINGW_DIR}/libwinpthread-1.dll DESTINATION ${INSTALL_DESTINATION})
install(FILES "${MINGW_DIR}/libgcc_s_dw2-1.dll" "${MINGW_DIR}/libstdc++-6.dll" "${MINGW_DIR}/libwinpthread-1.dll" DESTINATION ${INSTALL_DESTINATION})
set(MINGW_DIR "${MINGW_DIR}/../opt/bin")
# SSL support
install(FILES ${MINGW_DIR}/libeay32.dll ${MINGW_DIR}/ssleay32.dll DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
install(FILES "${MINGW_DIR}/libeay32.dll" "${MINGW_DIR}/ssleay32.dll" DESTINATION ${INSTALL_DESTINATION} OPTIONAL)
endif()
endif()
@@ -410,17 +429,6 @@ if(WIN32)
)
endif()
if(LUPDATE_FOUND)
add_custom_target(translations
WORKING_DIRECTORY ${COMPANION_SRC_DIRECTORY}
COMMAND ${LUPDATE_EXECUTABLE} ${COMPANION_SRC_DIRECTORY} -no-obsolete -ts ${companion_TS}
)
else()
add_custom_target(translations
COMMAND echo "Sorry, QT lupdate was not found."
)
endif()
set(CPACK_PACKAGE_NAME "companion${C9X_NAME_SUFFIX}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Models and settings editor for the OpenTX open source firmware")
string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)