22# Copyright 2019, Jonas Kvinge <jonas@jkvinge.net>
33
44project (sqlrestore)
5- cmake_minimum_required (VERSION 3.0 )
6- if (CMAKE_VERSION VERSION_GREATER 3.0)
7- cmake_policy (SET CMP0054 NEW )
8- endif ()
5+ cmake_minimum_required (VERSION 3.1 )
6+ cmake_policy (SET CMP0054 NEW )
97
108include (CheckCXXCompilerFlag )
119include (CheckIncludeFiles )
1210include (FindPkgConfig )
1311include (FindPackageHandleStandardArgs )
1412include (cmake/Version.cmake )
15- if ( ${ CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
13+ if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
1614 include (cmake/Rpm.cmake )
1715 include (cmake/Deb.cmake )
1816endif ()
1917
2018set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR} /cmake)
19+
20+ option (BUILD_WERROR "Build with -Werror" OFF )
21+
22+ if (WIN32 )
23+ option (ENABLE_WIN32_CONSOLE "Show the windows console even outside Debug mode" OFF )
24+ endif ()
25+
26+ if (MSVC )
27+ set (CMAKE_C_STANDARD 99)
28+ else ()
29+ set (CMAKE_C_STANDARD 11)
30+ endif ()
31+
2132set (CMAKE_CXX_STANDARD 17)
2233set (CMAKE_CXX_STANDARD_REQUIRED ON )
2334
24- list (APPEND COMPILE_OPTIONS
25- $<$<COMPILE_LANGUAGE :C >:-std =c99 >
26- $<$<COMPILE_LANGUAGE :CXX >:-std =c ++17>
27- -Wall
28- -Wextra
29- -Wpedantic
30- -Wunused
31- -Wuninitialized
32- -Wredundant-decls
33- -Wcast-align
34- -Winit-self
35- -Wmissing-include -dirs
36- -Wmissing-declarations
37- -Wstrict-overflow=2
38- -Wunused-parameter
39- -Wformat=2
40- -Wdisabled-optimization
41- -Wno-sign-conversion
42- $<$<COMPILE_LANGUAGE :CXX >:-Woverloaded -virtual >
43- $<$<COMPILE_LANGUAGE :CXX >:-Wno -old -style -cast >
44- $<$<COMPILE_LANGUAGE :CXX >:-fpermissive >
45- )
46-
47- if (APPLE )
48- list (APPEND COMPILE_OPTIONS -Wno-unused-parameter)
49- endif ()
50-
51- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
52- list (APPEND COMPILE_OPTIONS -Wno-language-extension-token)
35+ if (MSVC )
36+ list (APPEND COMPILE_OPTIONS /std:c++17)
37+ else ()
38+ list (APPEND COMPILE_OPTIONS
39+ $<$<COMPILE_LANGUAGE :C >:-std =c11 >
40+ $<$<COMPILE_LANGUAGE :CXX >:-std =c ++17>
41+ -Wall
42+ -Wextra
43+ -Wpedantic
44+ -Wunused
45+ -Wuninitialized
46+ -Wredundant-decls
47+ -Wcast-align
48+ -Winit-self
49+ -Wmissing-include -dirs
50+ -Wmissing-declarations
51+ -Wstrict-overflow=2
52+ -Wunused-parameter
53+ -Wformat=2
54+ -Wdisabled-optimization
55+ -Wno-sign-conversion
56+ $<$<COMPILE_LANGUAGE :CXX >:-Woverloaded -virtual >
57+ $<$<COMPILE_LANGUAGE :CXX >:-Wold -style -cast >
58+ )
5359endif ()
5460
55- option (BUILD_WERROR "Build with -Werror" ON )
56- if (BUILD_WERROR)
57- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" )
58- endif (BUILD_WERROR )
61+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
62+ list (APPEND COMPILE_OPTIONS -Wno-language-extension-token)
63+ endif ()
5964
60- add_compile_options (${COMPILE_OPTIONS} )
65+ if (NOT MSVC AND BUILD_WERROR)
66+ list (APPEND COMPILE_OPTIONS -Werror)
67+ endif ()
6168
62- if (${CMAKE_BUILD_TYPE} MATCHES "Release" )
63- add_definitions (-DNDEBUG )
64- add_definitions (-DQT_NO_DEBUG_OUTPUT )
65- #add_definitions(-DQT_NO_WARNING_OUTPUT)
69+ if (COMPILE_OPTIONS)
70+ add_compile_options (${COMPILE_OPTIONS} )
6671endif ()
6772
6873find_program (CCACHE_EXECUTABLE NAMES ccache )
@@ -75,7 +80,7 @@ endif()
7580find_package (PkgConfig REQUIRED )
7681find_package (Threads REQUIRED )
7782find_package (Boost REQUIRED )
78- find_package (Backtrace QUIET )
83+ find_package (Backtrace )
7984if (Backtrace_FOUND)
8085 set (HAVE_BACKTRACE ON )
8186endif ()
@@ -89,11 +94,7 @@ if(GLIB_FOUND)
8994endif ()
9095
9196# QT
92-
93- if (NOT QT_DEFAULT_MAJOR_VERSION)
94- set (QT_DEFAULT_MAJOR_VERSION 5)
95- endif ()
96- set (QT_MAJOR_VERSION ${QT_DEFAULT_MAJOR_VERSION} CACHE STRING "Qt version to use (5 or 6), defaults to ${QT_DEFAULT_MAJOR_VERSION} " )
97+ set (QT_MAJOR_VERSION 6 CACHE STRING "Qt version to use (5 or 6), defaults to 6" )
9798
9899option (BUILD_WITH_QT5 "Use Qt 5" OFF )
99100option (BUILD_WITH_QT6 "Use Qt 6" OFF )
@@ -108,15 +109,17 @@ else()
108109 elseif (QT_MAJOR_VERSION EQUAL 6)
109110 set (BUILD_WITH_QT6 ON )
110111 else ()
111- set (BUILD_WITH_QT5 ON )
112- set (QT_MAJOR_VERSION 5 )
112+ set (BUILD_WITH_QT6 ON )
113+ set (QT_MAJOR_VERSION 6 )
113114 endif ()
114115endif ()
115116
117+ set (QT_DEFAULT_MAJOR_VERSION ${QT_MAJOR_VERSION} )
118+
116119set (QT_COMPONENTS Core Concurrent Network Sql Gui Widgets)
117120
118121if (QT_MAJOR_VERSION EQUAL 5)
119- set (QT_MIN_VERSION 5.9 )
122+ set (QT_MIN_VERSION 5.12 )
120123endif ()
121124
122125find_package (Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED COMPONENTS ${QT_COMPONENTS} )
@@ -127,30 +130,44 @@ set(QtGui_LIBRARIES Qt${QT_MAJOR_VERSION}::Gui)
127130set (QtWidgets_LIBRARIES Qt${QT_MAJOR_VERSION} ::Widgets)
128131set (QtNetwork_LIBRARIES Qt${QT_MAJOR_VERSION} ::Network)
129132set (QtSql_LIBRARIES Qt${QT_MAJOR_VERSION} ::Sql)
130- set (QT_LIBRARIES Qt${QT_MAJOR_VERSION} ::Core Qt${QT_MAJOR_VERSION} ::Concurrent Qt${QT_MAJOR_VERSION} ::Gui Qt${QT_MAJOR_VERSION} ::Widgets Qt${QT_MAJOR_VERSION} ::Network Qt${QT_MAJOR_VERSION} ::Sql)
131133
132134# QUAZIP
133135find_package (QuaZip-Qt6 REQUIRED )
134136
137+ if (BUILD_WITH_QT5 AND Qt5Core_VERSION VERSION_LESS 5.15.0)
138+ macro (qt_add_resources )
139+ qt5_add_resources (${ARGN} )
140+ endmacro ()
141+ macro (qt_wrap_cpp )
142+ qt5_wrap_cpp (${ARGN} )
143+ endmacro ()
144+ macro (qt_wrap_ui )
145+ qt5_wrap_ui (${ARGN} )
146+ endmacro ()
147+ endif ()
148+
135149# QODBC - Build a modified QODBC driver that works with FreeTDS on UNIX renamed QODBCX
136150if (UNIX AND _Qt5Core_PRIVATE_DIRS_EXIST AND _Qt5Sql_PRIVATE_DIRS_EXIST AND Qt5Sql_VERSION VERSION_GREATER_EQUAL 5.14.1 AND NOT APPLE )
137151 set (HAVE_QSQLODBCX ON )
138152 add_subdirectory (3rdparty/qsqlodbc )
139153 include_directories (3rdparty/qsqlodbc )
140154endif ()
141155
142- if (WIN32 )
156+ if (WIN32 AND NOT MSVC )
143157 # RC compiler
144158 string (REPLACE "gcc" "windres" CMAKE_RC_COMPILER_INIT ${CMAKE_C_COMPILER} )
145159 enable_language (RC )
146160 SET (CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff -o <OBJECT> <SOURCE> -I ${CMAKE_SOURCE_DIR} /dist/windows" )
147- endif (WIN32 )
161+ endif ()
148162
149- # Optional bits
150- if ( WIN32 )
151- option ( ENABLE_WIN32_CONSOLE "Show the windows console even outside Debug mode" OFF )
152- endif (WIN32 )
163+ if ( CMAKE_BUILD_TYPE MATCHES "Release" )
164+ add_definitions ( -DNDEBUG )
165+ add_definitions ( -DQT_NO_DEBUG_OUTPUT )
166+ endif ()
153167
168+ if (WIN32 )
169+ add_definitions (-DUNICODE )
170+ endif ()
154171
155172# Subdirectories
156173add_subdirectory (src )
0 commit comments