WSL/SLF GitLab Repository

Commit 8a8bc565 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Better cmake support with various compilation profiles and targets

parent 29a37b57
......@@ -8,11 +8,13 @@ CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/main/config.h.in ${PROJECT_SOURCE_DIR}/
# Set language compatibility and qt tools
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
INCLUDE("${CMAKE_SOURCE_DIR}/tools/cmake/SetCompilerOptions.cmake")
SET_COMPILER_OPTIONS()
# Specific QT settings
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
IF(CMAKE_VERSION VERSION_LESS "3.7.0")
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
ENDIF()
......@@ -20,6 +22,18 @@ ENDIF()
FIND_PACKAGE(Qt5 COMPONENTS Widgets Xml XmlPatterns REQUIRED)
SET(QT5_LIBRARIES Qt5::Widgets Qt5::Xml Qt5::XmlPatterns)
#finally, SET compile flags
SET(CMAKE_CXX_FLAGS "${ARCH} ${EXTRA}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_RELEASE "${OPTIM}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_DEBUG "${DEBUG} ${WARNINGS} ${EXTRA_WARNINGS}" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS_CXXFLAGS "$ENV{CXXFLAGS}" CACHE STRING "" FORCE)
MARK_AS_ADVANCED(FORCE CMAKE_CXX_FLAGS_CXXFLAGS)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "release" CACHE STRING "Choose the type of build, options are: debug release coverage cxxflags" FORCE)
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})
ENDIF(NOT CMAKE_BUILD_TYPE)
SET(EXTRA_LIBS_SRC ./lib/tinyexpr.c)
SET(RESOURCES resources/inishell.qrc)
INCLUDE("${PROJECT_SOURCE_DIR}/src/CMakeLists.txt")
......
#SPDX-License-Identifier: LGPL-3.0-or-later
#building version number in variable _versionString
MACRO (GETDATE TODAY)
IF(CMAKE_VERSION VERSION_GREATER 2.8.11)
STRING(TIMESTAMP TODAY "%Y%m%d")
ELSE(CMAKE_VERSION VERSION_GREATER 2.8.11)
IF (WIN32)
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${TODAY})
STRING(REGEX REPLACE "(..)/(..)/(....) .*\n" "\\3\\2\\1" ${TODAY} ${${TODAY}}) #US format
STRING(REGEX REPLACE "(..)-(..)-(....) .*\n" "\\3\\2\\1" ${TODAY} ${${TODAY}}) #UK format
STRING(REGEX REPLACE "(..)\\.(..)\\.(....) .*\n" "\\3\\2\\1" ${TODAY} ${${TODAY}}) #CH format
ELSEIF(UNIX)
EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d" OUTPUT_VARIABLE ${TODAY})
string(REGEX REPLACE "(....)-(..)-(..).*" "\\1\\2\\3" ${TODAY} ${${TODAY}})
ELSE (WIN32)
MESSAGE(SEND_ERROR "date not implemented")
SET(${TODAY} 000000)
ENDIF (WIN32)
ENDIF(CMAKE_VERSION VERSION_GREATER 2.8.11)
ENDMACRO (GETDATE)
MACRO(BuildVersionSVN)
FIND_PACKAGE(Subversion)
IF(Subversion_FOUND)
SET(VERSION_FROM_SVN OFF CACHE BOOL "Retrieve software version from Subversion")
IF(VERSION_FROM_SVN)
Subversion_WC_INFO(${PROJECT_SOURCE_DIR} project) #HACK: if not an svn tree, it does not work
GETDATE(TODAY)
SET(_versionString "${TODAY}.${project_WC_REVISION}")
ELSE(VERSION_FROM_SVN)
SET(_versionString "${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_PATCH}")
ENDIF(VERSION_FROM_SVN)
ELSE(Subversion_FOUND)
SET(_versionString "${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_PATCH}")
ENDIF(Subversion_FOUND)
ENDMACRO(BuildVersionSVN)
MACRO(BuildVersionGIT)
FIND_PACKAGE(Git)
IF(GIT_FOUND)
SET(VERSION_FROM_GIT OFF CACHE BOOL "Retrieve software version from Git")
IF(VERSION_FROM_GIT)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY "${local_dir}"
OUTPUT_VARIABLE project_WC_REVISION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
GETDATE(TODAY)
SET(_versionString "${TODAY}.${project_WC_REVISION}")
ELSE(VERSION_FROM_GIT)
SET(_versionString "${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_PATCH}")
ENDIF(VERSION_FROM_GIT)
ELSE(GIT_FOUND)
SET(_versionString "${VERSION_MAJOR}.${VERSION_MINOR}${VERSION_PATCH}")
ENDIF(GIT_FOUND)
ENDMACRO(BuildVersionGIT)
#SPDX-License-Identifier: LGPL-3.0-or-later
#Set different variables according to the detected compiler and processor
#based on $CMAKE_CXX_COMPILER_ID it sets the following variables:
# WARNINGS, EXTRA_WARNINGS, EXTRA, OPTIM, ARCH, DEBUG, _VERSION, PROFILING
# It can also edit CMAKE_SHARED_LINKER_FLAGS and CMAKE_EXE_LINKER_FLAGS
MACRO (SET_COMPILER_OPTIONS)
SET(USER_COMPILER_OPTIONS "" CACHE STRING "Provide some extra compiler options")
MARK_AS_ADVANCED(FORCE USER_COMPILER_OPTIONS)
SET(EXTRA "${EXTRA} ${USER_COMPILER_OPTIONS}")
###########################################################
IF(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
IF(DEBUG_ARITHM)
SET(EXTRA "${EXTRA} /EHa")
ENDIF(DEBUG_ARITHM)
#SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "limited configs" FORCE)
SET(WARNINGS "/W4 /D_CRT_SECURE_NO_WARNINGS /EHsc") #Za: strict ansi EHsc: handle c++ exceptions /w35045: inform about Spectre mitigation
#SET(EXTRA_WARNINGS "/Wp64") #/Wall
SET(WARNINGS "${WARNINGS} /experimental:external /external:I c:/Windows /external:W0")
SET(OPTIM "/O2 /DNDEBUG /DEBUG:FASTLINK /MD /DNOSAFECHECKS")
SET(ARCH_OPTIM "/arch:AVX2")
SET(ARCH_SAFE "")
SET(DEBUG "/Z7 /Od /D__DEBUG /MDd")
###########################################################
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL Intel)
SET(WARNINGS_OFF "-Wno-long-long -Wno-unknown-pragmas -wd2015,11071")
SET(WARNINGS "-Wall -Wswitch ${WARNINGS_OFF}")
SET(DEEP_WARNINGS "-Wshadow -Wpointer-arith -Wconversion -Winline -Wdisabled-optimization") #-Wfloat-equal -Wpadded
SET(EXTRA_WARNINGS "-Wextra -pedantic ${DEEP_WARNINGS}")
SET(OPTIM "-g -O3 -DNDEBUG -DNOSAFECHECKS")
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
SET(ARCH_SAFE "-march=nocona -mtune=nocona")
SET(ARCH_OPTIM "-march=native -mtune=native")
ENDIF()
SET(DEBUG "-g3 -O0 -D__DEBUG")
###########################################################
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL Cray)
SET(WARNINGS "-hlist=m -h negmsgs -h msglevel_3 -h nomessage=870") #870: accept multibyte chars
#SET(EXTRA_WARNINGS "-h msglevel_2")
SET(OPTIM "-O3 -hfp3 -h msglevel_4 -DNDEBUG -DNOSAFECHECKS")
IF($ENV{CRAY_CPU_TARGET} MATCHES "^$")
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
SET(ARCH_SAFE "-h cpu=x86-64")
MESSAGE("No CRAY_CPU_TARGET set, setting it to x86-64; please consider loading the proper target module.")
ELSE()
MESSAGE("No CRAY_CPU_TARGET set; please consider loading the proper target module.")
ENDIF()
ENDIF()
SET(DEBUG "-g -D__DEBUG")
###########################################################
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "^GNU$")
#we consider that all other compilers support "-" options and silently ignore what they don't know
SET(WARNINGS "-Wall -Wno-long-long -Wswitch") #-Wno-unknown-pragmas
SET(DEEP_WARNINGS "-Wunused-value -Wshadow -Wpointer-arith -Wconversion -Winline -Wdisabled-optimization -Wctor-dtor-privacy") #-Wfloat-equal -Wpadded
SET(EXTRA_WARNINGS "-Wextra -pedantic ${DEEP_WARNINGS}") #-Weffc++
SET(OPTIM "-g -O3 -DNDEBUG -DNOSAFECHECKS")
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
SET(ARCH_SAFE "-march=nocona -mtune=nocona")
ENDIF()
SET(DEBUG "-g3 -O0 -D__DEBUG")
SET(PROFILING "-pg -fprofile-arcs") #add ${PROFILING} to the CFLAGS when necessary
SET(EXTRA_WARNINGS "${EXTRA_WARNINGS} -Wunsafe-loop-optimizations -Wwrite-strings")
IF(NOT ANDROID)
SET(EXTRA_WARNINGS "${EXTRA_WARNINGS} -ansi")
IF(WIN32) #for gcc on windows
SET(CMAKE_SHARED_LINKER_FLAGS "--enable-auto-import")
SET(CMAKE_EXE_LINKER_FLAGS "--enable-auto-import")
#SET(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
ENDIF(WIN32)
ENDIF(NOT ANDROID)
EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
IF(GCC_VERSION VERSION_GREATER 4.2 OR GCC_VERSION VERSION_EQUAL 4.2)
SET(ARCH_OPTIM "-march=native -mtune=native")
ENDIF()
IF(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8)
SET(EXTRA_WARNINGS "${EXTRA_WARNINGS} -Wvector-operation-performance") #for gcc>=4.7.0
IF(NOT WIN32)
#for gcc>4.5, but first implementations were slow, so it is safe to enforce 4.8
FIND_PROGRAM(CMAKE_GCC_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX} 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)
SET(USE_LTO_OPTIMIZATIONS ON CACHE BOOL "Use Link Time Optmizations when compiling (memory heavy while compiling)")
MARK_AS_ADVANCED(FORCE USE_LTO_OPTIMIZATIONS)
IF(USE_LTO_OPTIMIZATIONS)
SET(OPTIM "${OPTIM} -flto")
ENDIF()
SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -fno-fat-lto-objects" )
SET( CMAKE_AR "${CMAKE_GCC_AR}" )
SET( CMAKE_NM "${CMAKE_GCC_NM}" )
SET( CMAKE_RANLIB "${CMAKE_GCC_RANLIB}" )
ELSE()
MESSAGE( WARNING "GCC indicates LTO support, but binutils wrappers could not be found. Disabling LTO." )
ENDIF()
ENDIF(NOT WIN32)
#if set to ON, all binaries depending on the library have to be compiled the same way.
#Then, do an "export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4" and run with "ASAN_OPTIONS=symbolize=1"
SET(LEAKS_CHECK OFF CACHE BOOL "Set to ON to dynamically check for memory corruption (and do the same for applications linked with MeteoIO)")
IF (LEAKS_CHECK)
SET(EXTRA "${EXTRA} -fsanitize=address -fno-omit-frame-pointer")
ENDIF(LEAKS_CHECK)
ENDIF()
###########################################################
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(WARNINGS_OFF "-Wno-long-long -Wno-float-equal -Wno-documentation -Wno-documentation-unknown-command -Wno-old-style-cast -Wno-padded -Wno-missing-noreturn -Wno-weak-vtables -Wno-switch-enum -Wno-covered-switch-default -Wno-global-constructors -Wno-exit-time-destructors -Wno-unknown-pragmas -Wno-format-nonliteral -Wno-date-time -Wno-unused-template -Wno-disabled-macro-expansion -Wno-c++98-compat -Wno-c++98-compat-pedantic")
SET(WARNINGS "-Wall -Wswitch -Weverything ${WARNINGS_OFF}") #obviously, we should try to fix the warnings! Keeping in mind that some of these W are half buggy...
SET(DEEP_WARNINGS "-Wunused-value -Wshadow -Wpointer-arith -Wconversion -Winline -Wdisabled-optimization -Wctor-dtor-privacy") #-Rpass=.* for static analysis
SET(EXTRA_WARNINGS "-Wextra -pedantic ${DEEP_WARNINGS}") #-Weffc++
SET(OPTIM "-g -O3 -DNDEBUG -DNOSAFECHECKS -flto")
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
SET(ARCH_SAFE "-march=nocona -mtune=nocona")
ENDIF()
SET(DEBUG "-g3 -O0 -D__DEBUG")
SET(PROFILING "-pg") #add ${PROFILING} to the CFLAGS when necessary
SET(EXTRA "${EXTRA} -fcolor-diagnostics") #-fapple-pragma-pack does not seems necessary; -ftrapv should be replaced by sanitize=integer
SET(LEAKS_CHECK OFF CACHE BOOL "Set to ON to dynamically check for memory corruption (and do the same for applications linked with MeteoIO)")
IF (LEAKS_CHECK)
SET(EXTRA "${EXTRA} -ftrapv -fno-omit-frame-pointer") #-fsanitize=address,undefined,integer,undefined-trap but this is currently not supported by Apple
ENDIF(LEAKS_CHECK)
SET(ARCH_OPTIM "-march=native")
ENDIF()
###########################################################
#targets providing SETs of compiler options
IF(NOT DEST)
SET(DEST "safe" CACHE STRING "Choose safe or optimized" FORCE)
ENDIF(NOT DEST)
IF (DEST STREQUAL "safe")
SET(ARCH "${ARCH_SAFE}")
ENDIF(DEST STREQUAL "safe")
IF(DEST STREQUAL "optimized")
SET(ARCH "${ARCH_OPTIM}")
ENDIF(DEST STREQUAL "optimized")
ENDMACRO (SET_COMPILER_OPTIONS)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment