From 323dd162f5326b998e1c92ab4cfec8a63574023f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 24 Dec 2018 22:45:38 +0100 Subject: cmake: decruft, disable deprecated Qt functions --- cmake/apple.cmake | 2 +- cmake/linux.cmake | 2 +- cmake/mingw-w64.cmake | 2 +- cmake/opentrack-boilerplate.cmake | 6 +- cmake/opentrack-hier.cmake | 114 ++++++++++++++------------- cmake/opentrack-load-user-settings.cmake | 3 - cmake/opentrack-pkg-config.cmake | 1 - cmake/opentrack-platform.cmake | 130 +++++++++++++------------------ cmake/opentrack-policy.cmake | 17 +++- cmake/opentrack-qt.cmake | 14 +++- 10 files changed, 146 insertions(+), 145 deletions(-) (limited to 'cmake') diff --git a/cmake/apple.cmake b/cmake/apple.cmake index 627ef3c1..f6b83382 100644 --- a/cmake/apple.cmake +++ b/cmake/apple.cmake @@ -3,7 +3,7 @@ set(CMAKE_BUILD_TYPE_INIT RELEASE) set(CMAKE_CXX_FLAGS "-arch x86_64 -stdlib=libc++" CACHE STRING "" FORCE) set(CMAKE_C_FLAGS "-arch x86_64" CACHE STRING "" FORCE) -set(CMAKE_C_FLAGS_RELEASE "-ffast-math -O3 -flto -fvisibility=hidden -g" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE "-ffast-math -O3 -flto -g" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_RELEASE " ${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE) set(cmake-link-common "-stdlib=libc++ -arch x86_64") diff --git a/cmake/linux.cmake b/cmake/linux.cmake index 326c4d4a..5513f511 100644 --- a/cmake/linux.cmake +++ b/cmake/linux.cmake @@ -7,7 +7,7 @@ set(CMAKE_AR "gcc-ar" CACHE STRING "" FORCE) set(CMAKE_NM "gcc-nm" CACHE STRING "" FORCE) set(CMAKE_RANLIB "gcc-ranlib" CACHE STRING "" FORCE) -set(CMAKE_C_FLAGS_RELEASE "-ffast-math -O3 -flto -fuse-linker-plugin -fvisibility=hidden -fPIC" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE "-ffast-math -O3 -flto -fuse-linker-plugin -fPIC" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_RELEASE " ${CMAKE_C_FLAGS_RELEASE} " CACHE STRING "" FORCE) set(cmake-link-common "") diff --git a/cmake/mingw-w64.cmake b/cmake/mingw-w64.cmake index ec552103..b543bbdd 100644 --- a/cmake/mingw-w64.cmake +++ b/cmake/mingw-w64.cmake @@ -81,7 +81,7 @@ if(WARNINGS_ENABLE) set(_CXX_WARNS "${_C_WARNS} ${usual-warns} ${noisy-warns} ${missing-override}") endif() -set(ccflags-common "-fvisibility=hidden -pipe -g3") +set(ccflags-common "-pipe -g3") set(_CXXFLAGS "${ccflags-common} ${_CXX_WARNS}") set(_CFLAGS "${ccflags-common} -std=c11 ${_C_WARNS}") set(_CFLAGS_RELEASE "${cpu} ${fpu} ${lto} ${sections} ${cc}") diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake index 9d72c1af..40f65474 100644 --- a/cmake/opentrack-boilerplate.cmake +++ b/cmake/opentrack-boilerplate.cmake @@ -117,8 +117,6 @@ function(otr_install_pdb_current_project target) endif() endfunction() -include(CMakeParseArguments) - function(otr_module n_) message(STATUS "module ${n_}") cmake_parse_arguments(arg @@ -173,6 +171,10 @@ function(otr_module n_) set_property(TARGET "${n}" PROPERTY PREFIX "") endif() + if(NOT arg_NO-QT) + otr_qt2("${n}") + endif() + set(self "${n}" PARENT_SCOPE) if(NOT arg_RELINK) diff --git a/cmake/opentrack-hier.cmake b/cmake/opentrack-hier.cmake index 2b3159b4..e3eeab11 100644 --- a/cmake/opentrack-hier.cmake +++ b/cmake/opentrack-hier.cmake @@ -1,56 +1,58 @@ -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE -# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL -# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. - -include_guard(GLOBAL) - -set(opentrack-install-rpath "") -if(APPLE) - set(opentrack-hier-pfx ".") - set(opentrack-hier-path "/") # MUST HAVE A TRAILING BACKSLASH - set(opentrack-hier-doc "/") # MUST HAVE A TRAILING BACKSLASH - set(opentrack-hier-str RUNTIME DESTINATION . LIBRARY DESTINATION .) - set(opentrack-doc-pfx "./doc") - set(opentrack-doc-src-pfx "./source-code") - set(opentrack-i18n-pfx "./i18n") - set(opentrack-i18n-path "./i18n") -elseif(WIN32) - set(opentrack-hier-pfx "./modules") - set(opentrack-hier-path "/modules/") # MUST HAVE A TRAILING BACKSLASH - set(opentrack-hier-doc "/doc/") # MUST HAVE A TRAILING BACKSLASH - set(opentrack-doc-pfx "./doc") - set(opentrack-doc-src-pfx "./source-code") - set(opentrack-hier-str RUNTIME DESTINATION ./modules/ LIBRARY DESTINATION ./modules/) - set(opentrack-i18n-pfx "./i18n") - set(opentrack-i18n-path "./i18n") - set(opentrack-hier-debug "./debug") -else() - set(opentrack-hier-pfx "libexec/opentrack") - set(opentrack-hier-path "/../libexec/opentrack/") # MUST HAVE A TRAILING BACKSLASH - set(opentrack-hier-doc "/share/doc/opentrack/") # MUST HAVE A TRAILING BACKSLASH - set(opentrack-doc-pfx "./share/doc/opentrack") - set(opentrack-doc-src-pfx "./share/doc/opentrack/source-code") - set(opentrack-install-rpath "${CMAKE_INSTALL_PREFIX}/${opentrack-hier-pfx}") - set(opentrack-hier-str ARCHIVE DESTINATION share/opentrack LIBRARY DESTINATION ${opentrack-hier-pfx} RUNTIME DESTINATION bin) - set(opentrack-i18n-pfx "./share/opentrack/i18n") - set(opentrack-i18n-path "../share/opentrack/i18n") -endif() - -function(otr_escape_string var str) - string(REGEX REPLACE "([\$\\\"#])" "\\\\\\1" tmp__ "${str}") - set(${var} "${tmp__}" PARENT_SCOPE) -endfunction() - -set(opentrack-contrib-pfx "${opentrack-doc-pfx}/contrib") - -set(opentrack-binary-suffix "") -if(APPLE) - set(opentrack-binary-suffix ".bin") -elseif(WIN32) - set(opentrack-binary-suffix ".exe") -endif() +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +include_guard(GLOBAL) + +set(opentrack-install-rpath "") +if(APPLE) + set(opentrack-hier-pfx ".") + set(opentrack-hier-path "/") # MUST HAVE A TRAILING BACKSLASH + set(opentrack-hier-doc "/") # MUST HAVE A TRAILING BACKSLASH + set(opentrack-hier-str RUNTIME DESTINATION . LIBRARY DESTINATION .) + set(opentrack-doc-pfx "./doc") + set(opentrack-doc-src-pfx "./source-code") + set(opentrack-i18n-pfx "./i18n") + set(opentrack-i18n-path "./i18n") +elseif(WIN32) + set(opentrack-hier-pfx "./modules") + set(opentrack-hier-path "/modules/") # MUST HAVE A TRAILING BACKSLASH + set(opentrack-hier-doc "/doc/") # MUST HAVE A TRAILING BACKSLASH + set(opentrack-doc-pfx "./doc") + set(opentrack-doc-src-pfx "./source-code") + set(opentrack-hier-str RUNTIME DESTINATION ./modules/ LIBRARY DESTINATION ./modules/) + set(opentrack-i18n-pfx "./i18n") + set(opentrack-i18n-path "./i18n") + set(opentrack-hier-debug "./debug") +else() + set(opentrack-hier-pfx "libexec/opentrack") + set(opentrack-hier-path "/../libexec/opentrack/") # MUST HAVE A TRAILING BACKSLASH + set(opentrack-hier-doc "/share/doc/opentrack/") # MUST HAVE A TRAILING BACKSLASH + set(opentrack-doc-pfx "./share/doc/opentrack") + set(opentrack-doc-src-pfx "./share/doc/opentrack/source-code") + set(opentrack-install-rpath "${CMAKE_INSTALL_PREFIX}/${opentrack-hier-pfx}") + set(opentrack-hier-str ARCHIVE DESTINATION share/opentrack LIBRARY DESTINATION ${opentrack-hier-pfx} RUNTIME DESTINATION bin) + set(opentrack-i18n-pfx "./share/opentrack/i18n") + set(opentrack-i18n-path "../share/opentrack/i18n") +endif() + +function(otr_escape_string var str) + string(REGEX REPLACE "([\$\\\"#])" "\\\\\\1" tmp__ "${str}") + set(${var} "${tmp__}" PARENT_SCOPE) +endfunction() + +set(opentrack-contrib-pfx "${opentrack-doc-pfx}/contrib") + +set(opentrack-binary-suffix "") +if(APPLE) + set(opentrack-binary-suffix ".bin") +elseif(WIN32) + set(opentrack-binary-suffix ".exe") +endif() + +set(CMAKE_INSTALL_RPATH "${opentrack-install-rpath}") diff --git a/cmake/opentrack-load-user-settings.cmake b/cmake/opentrack-load-user-settings.cmake index a0284943..0ce6e9b0 100644 --- a/cmake/opentrack-load-user-settings.cmake +++ b/cmake/opentrack-load-user-settings.cmake @@ -20,9 +20,6 @@ else() endif() endif() -include(CMakeDetermineCCompiler) -include(CMakeDetermineCXXCompiler) - if(NOT CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME) set(__sdk_host_os "${CMAKE_HOST_SYSTEM_NAME}-cross-") else() diff --git a/cmake/opentrack-pkg-config.cmake b/cmake/opentrack-pkg-config.cmake index b12b786c..7d70070e 100644 --- a/cmake/opentrack-pkg-config.cmake +++ b/cmake/opentrack-pkg-config.cmake @@ -14,7 +14,6 @@ function(otr_pkgconfig target) set(includes ${includes} ${${k}_INCLUDE_DIRS} ${${k}_INCLUDEDIR}) set(ldflags "${ldflags} ${${k}_LDFLAGS} ") set(libs ${libs} ${${k}_LIBRARIES}) - #message(STATUS "${target} | ${i} | ${cflags} | ${includes} | ${ldflags} | ${libs} | ") else() message(FATAL_ERROR "Can't find '${i}'. Please install development files for this package.") endif() diff --git a/cmake/opentrack-platform.cmake b/cmake/opentrack-platform.cmake index 1df19b2b..32599896 100644 --- a/cmake/opentrack-platform.cmake +++ b/cmake/opentrack-platform.cmake @@ -23,6 +23,10 @@ include_guard(GLOBAL) +if(MSVC AND MSVC_VERSION LESS "1915" AND NOT ".${CMAKE_CXX_COMPILER_ID}" STREQUAL ".Clang") + message(FATAL_ERROR "Visual Studio too old. Use Visual Studio 2017 or newer.") +endif() + if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR NOT CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE) endif() @@ -34,26 +38,28 @@ endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" __build_type) set(CMAKE_BUILD_TYPE "${__build_type}" CACHE STRING "" FORCE) -set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +include_directories("${CMAKE_SOURCE_DIR}") -if (CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*|i[0-9]86.*|x86.*") - set(opentrack-intel TRUE) -else() - set(opentrack-intel FALSE) -endif() +set(opentrack_maintainer-mode FALSE CACHE INTERNAL "Select if developing core code (not modules)") -if(CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8) - set(opentrack-64bit TRUE) -else() - set(opentrack-64bit FALSE) -endif() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_DEFAULT 17) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS FALSE) -if(APPLE AND NOT CMAKE_OSX_ARCHITECTURES) - set(CMAKE_OSX_ARCHITECTURES "x86_64") -endif() +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +set(CMAKE_SKIP_INSTALL_RPATH FALSE) +set(CMAKE_SKIP_RPATH FALSE) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC OFF) +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) -if(MSVC AND MSVC_VERSION LESS "1915" AND NOT ".${CMAKE_CXX_COMPILER_ID}" STREQUAL ".Clang") - message(FATAL_ERROR "Visual Studio too old. Use Visual Studio 2017 or newer.") +set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) + +if(NOT WIN32 AND NOT APPLE) + include(opentrack-pkg-config) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -66,12 +72,39 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_CLANG TRUE) endif() +if(APPLE AND NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES "x86_64") + set(opentrack-intel TRUE) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*|i[0-9]86.*|x86.*") + set(opentrack-intel TRUE) +else() + set(opentrack-intel FALSE) +endif() + +if(CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8) + set(opentrack-64bit TRUE) +else() + set(opentrack-64bit FALSE) +endif() + IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(LINUX TRUE) endif() +if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-cxa-atexit") + # assume binutils + foreach (i SHARED MODULE EXE) + set(CMAKE_${i}_LINKER_FLAGS "-Wl,-z,relro,-z,now,--exclude-libs,ALL ${CMAKE_${i}_LINKER_FLAGS}") + endforeach() +endif() + if(WIN32) - add_definitions(-D_USE_MATH_DEFINES=1) + add_definitions(-D_USE_MATH_DEFINES=1 -DSTRSAFE_NO_DEPRECATE) +endif() + +if(MINGW) + add_definitions(-DMINGW_HAS_SECURE_API) endif() if(MSVC) @@ -85,7 +118,7 @@ if(MSVC) set(__stuff "-permissive- -diagnostics:caret") set(CMAKE_CXX_FLAGS "${__stuff} ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "${__stuff} ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "${__stuff} ${CMAKE_C_FLAGS}") if(opentrack-64bit) set(ent "-HIGHENTROPYVA") @@ -99,67 +132,14 @@ if(MSVC) endforeach() endif() -if(WIN32) - if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_RC_COMPILER_INIT i686-w64-mingw32-windres) - set(CMAKE_RC_COMPILE_OBJECT " --use-temp-file -O coff -i -o ") - endif() - enable_language(RC) -endif() - -if(opentrack-install-rpath) - set(CMAKE_INSTALL_RPATH "${opentrack-install-rpath}") -else() - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}") -endif() - -set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -set(CMAKE_SKIP_INSTALL_RPATH FALSE) -set(CMAKE_SKIP_RPATH FALSE) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC OFF) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -include_directories("${CMAKE_SOURCE_DIR}") - -if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) - set(_common "-fvisibility=hidden") - set(CMAKE_C_FLAGS "${_common} ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${_common} -fuse-cxa-atexit ${CMAKE_CXX_FLAGS}") -endif() - if(APPLE) set(CMAKE_MACOSX_RPATH OFF) - set(apple-frameworks "-stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon") - set(CMAKE_SHARED_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_SHARED_LINKER_FLAGS}") - #set(CMAKE_STATIC_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_STATIC_LINKER_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_EXE_LINKER_FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS " ${apple-frameworks} ${CMAKE_MODULE_LINKER_FLAGS}") + set(apple-frameworks "-framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon") + foreach (k SHARED EXE MODULE) + set(CMAKE_${k}_LINKER_FLAGS "-stdlib=libc++ ${CMAKE_${k}_LINKER_FLAGS} ${apple-frameworks}") + endforeach() set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}") endif() -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_DEFAULT 17) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -set(CMAKE_CXX_EXTENSIONS FALSE) - -foreach(k _RELEASE _DEBUG _RELWITHDEBINFO _MINSIZEREL) - set(CMAKE_C_FLAGS${k} "${CMAKE_C_FLAGS${k}} -UNDEBUG") - set(CMAKE_CXX_FLAGS${k} "${CMAKE_CXX_FLAGS${k}} -UNDEBUG") -endforeach() - -if(MINGW) - add_definitions(-DMINGW_HAS_SECURE_API) - add_definitions(-DSTRSAFE_NO_DEPRECATE) -endif() -# assume binutils -if(UNIX AND NOT APPLE) - foreach (i SHARED MODULE EXE) - set(CMAKE_${i}_LINKER_FLAGS "-Wl,-z,relro,-z,now,--exclude-libs,ALL ${CMAKE_${i}_LINKER_FLAGS}") - endforeach() - include(opentrack-pkg-config) -endif() -set(opentrack_maintainer-mode FALSE CACHE BOOL "Select if developing core code (not modules)") diff --git a/cmake/opentrack-policy.cmake b/cmake/opentrack-policy.cmake index e14bcbf7..209ef529 100644 --- a/cmake/opentrack-policy.cmake +++ b/cmake/opentrack-policy.cmake @@ -1,5 +1,20 @@ include_guard(GLOBAL) -foreach(k CMP0020 CMP0022 CMP0058 CMP0028 CMP0042 CMP0063 CMP0053 CMP0011 CMP0054 CMP0012 CMP0069) + +set(_policies + CMP0020 + CMP0022 + CMP0058 + CMP0028 + CMP0042 + CMP0063 + CMP0053 + CMP0011 + CMP0054 + CMP0012 + CMP0069 + CMP0063 +) +foreach(k ${_policies}) if(POLICY ${k}) cmake_policy(SET ${k} NEW) endif() diff --git a/cmake/opentrack-qt.cmake b/cmake/opentrack-qt.cmake index e90e3250..0e6ca73d 100644 --- a/cmake/opentrack-qt.cmake +++ b/cmake/opentrack-qt.cmake @@ -59,8 +59,14 @@ function(otr_qt n) list(APPEND ${n}-all ${${n}-${i}}) endforeach() set(${n}-all "${${n}-all}" PARENT_SCOPE) - include_directories(SYSTEM ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) - add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS}) - add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) - add_definitions(-DQT_DEPRECATED -DQT_DISABLE_DEPRECATED_BEFORE=-1) +endfunction() + +function(otr_qt2 n) + target_include_directories("${n}" PRIVATE SYSTEM + ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} + ) + target_compile_definitions("${n}" PRIVATE + ${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS} + -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT + ) endfunction() -- cgit v1.2.3