CMakeLists.txt

Fri, 11 Feb 2022 12:02:09 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 11 Feb 2022 12:02:09 +0100
changeset 3
4b95e33ee476
parent 2
a1e435907f3a
child 4
fe106c497b75
permissions
-rw-r--r--

We have a mainscreen!

1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 # CMakeLists.txt is part of bmsapp
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 PROJECT(bmsapp)
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 CMAKE_MINIMUM_REQUIRED( VERSION 3.6 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 SET(bmsapp_EXECUTABLE "bmsapp")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 MESSAGE( STATUS "Building bmsapp" )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
9 # ===== Set application version =====
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 SET( bmsapp_VERSION_MAJOR 0 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 SET( bmsapp_VERSION_MINOR 1 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 SET( bmsapp_VERSION_PATCH 0 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 # Compile flags
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 # Automatically run moc on source files when necessary
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 set(CMAKE_AUTOMOC ON)
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
19 set(CMAKE_AUTOUIC ON)
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
20 set(CMAKE_AUTORCC ON)
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 SET( CMAKE_CXX_FLAGS_RELEASE "-Wall -ansi -pedantic -Wno-long-long -O2 -pipe" )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 SET( CMAKE_CXX_FLAGS_DEBUG "-Wall -g3 -pipe" )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 #====================================================Set build type=====================================================
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 # We might always to tell the compiler to include debugging information (eg via the -g option on gcc). It makes the
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 # binaries slightly bigger on Linux, but helps greatly in analysing core dumps etc. (In closed-source projects people
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 # sometimes turn it off for release builds to make it harder to reverse engineer the software, but obviously that's not
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 # an issue for us.)
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 # However, setting CMAKE_BUILD_TYPE to "Debug", also changes other things, such as the default location for config
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 # files, which we don't want on a release build, so we would probably need to set compiler flags directly.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 # .:TBD:. Investigate whether setting CMAKE_BUILD_TYPE to "RelWithDebInfo" does what we want.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #IF( ${DO_RELEASE_BUILD} )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 # SET(CMAKE_BUILD_TYPE "Release")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #ELSE()
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 # SET(CMAKE_BUILD_TYPE "Debug")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 #ENDIF()
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
42 # ===== Directories =====
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
43
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
44 IF( NOT EXEC_PREFIX )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
45 SET( EXEC_PREFIX ${CMAKE_INSTALL_PREFIX} )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
46 ENDIF()
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
47
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
48 SET( DATAROOTDIR "${EXEC_PREFIX}/share" )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
49 SET( BINDIR "${EXEC_PREFIX}/bin" )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
50 IF( NOT DOCDIR )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
51 SET( DOCDIR "${DATAROOTDIR}/doc/${CMAKE_PROJECT_NAME}" )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
52 ENDIF()
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
53
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
54 SET( DATAPATH "${DATAROOTDIR}/${CMAKE_PROJECT_NAME}" )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
55 SET( TARGETPATH ${BINDIR} )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
56 SET( DOCPATH ${DOCDIR} )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
57
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 SET(ROOTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 SET(SRCDIR "${ROOTDIR}/src")
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
61 SET(UIDIR "${ROOTDIR}/ui")
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
62 SET(DATADIR "${ROOTDIR}/data")
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 #SET(TRANSLATIONSDIR "${ROOTDIR}/translations")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 INCLUDE_DIRECTORIES(${SRCDIR})
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/src") # In case of out-of-source build.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
68 # ===== Find Qt5 =====
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
70 # Minimum versio 5.13 for debug messages.
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
71 find_package(Qt5 5.13 REQUIRED COMPONENTS Core Widgets Network Sql)
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
73 # PrintSupport Xml LinguistTools
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 # Some extra files for the "make clean" target.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 SET_PROPERTY(
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 cmake_install.cmake
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 compile_commands.json
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 CMakeCache.txt
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
84 # ===== Setup the config.h =====
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
85
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
86 SET( CONFIGDATADIR "${DATAPATH}/" )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
87 SET( CONFIGDOCDIR "${DOCPATH}/" )
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 # Tell cmake where the configure file is and where
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 # to put the output. All variables in config.in written as "${VAR}$
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 # will be replaced by VAR as determined by cmake in config.h.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 # Outputs only in the build directory.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 CONFIGURE_FILE( src/config.in src/config.h )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
95 # ===== All sources =====
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
96
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
97 set( SRCS
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
98 ${SRCDIR}/main.cpp
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
99 ${SRCDIR}/bmsapp.cpp
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
100 ${SRCDIR}/MainWindow.cpp
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
101 ${SRCDIR}/database/database.cpp
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
102 )
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
103
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
104 set( HDRS
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
105 ${SRCDIR}/bmsapp.h
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
106 ${SRCDIR}/MainWindow.h
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
107 ${SRCDIR}/database/database.h
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
108 )
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
109
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
110 set( UIS
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
111 ${UIDIR}/MainWindow.ui
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
112 )
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 set( SOURCE_FILES
2
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
115 ${SRCS}
a1e435907f3a Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
116 ${HDRS}
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
117 ${UIS}
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
118 resources/icons.qrc
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 # ===== Build the application =====
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 add_executable(${bmsapp_EXECUTABLE} ${SOURCE_FILES})
3
4b95e33ee476 We have a mainscreen!
Michiel Broek <mbroek@mbse.eu>
parents: 2
diff changeset
124 target_link_libraries(${bmsapp_EXECUTABLE} Qt5::Core Qt5::Widgets Qt5::Network Qt5::Sql)
1
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125

mercurial