CMakeLists.txt

Sun, 06 Feb 2022 16:52:20 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 06 Feb 2022 16:52:20 +0100
changeset 1
d38df7b58026
child 2
a1e435907f3a
permissions
-rw-r--r--

Initial build and cmake setup

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
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 # Version
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)
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 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
21 SET( CMAKE_CXX_FLAGS_DEBUG "-Wall -g3 -pipe" )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #====================================================Set build type=====================================================
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 # 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
25 # 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
26 # 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
27 # an issue for us.)
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 # 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
30 # 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
31 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 # .: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
33 #
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 #IF( ${DO_RELEASE_BUILD} )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 # SET(CMAKE_BUILD_TYPE "Release")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 #ELSE()
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 # SET(CMAKE_BUILD_TYPE "Debug")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 #ENDIF()
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 #============================Directories=======================================
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 SET(ROOTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 SET(SRCDIR "${ROOTDIR}/src")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 #SET(UIDIR "${ROOTDIR}/ui")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 #SET(DATADIR "${ROOTDIR}/data")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #SET(TRANSLATIONSDIR "${ROOTDIR}/translations")
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 INCLUDE_DIRECTORIES(${SRCDIR})
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 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
50
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 #==================================Find Qt5====================================
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 # Network PrintSupport Sql Xml LinguistTools
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 # Some extra files for the "make clean" target.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 SET_PROPERTY(
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 cmake_install.cmake
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 compile_commands.json
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 CMakeCache.txt
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
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 #==============================Setup the config.h==============================
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 # Tell cmake where the configure file is and where
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 # 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
70 # 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
71 # Outputs only in the build directory.
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 CONFIGURE_FILE( src/config.in src/config.h )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 # ===== Process other CMakeList.txt's =====
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 set( SOURCE_FILES
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 ${SRCDIR}/main.cpp
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 )
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 # ===== Build the application =====
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 add_executable(${bmsapp_EXECUTABLE} ${SOURCE_FILES})
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 target_link_libraries(${bmsapp_EXECUTABLE} Qt5::Core Qt5::Widgets)
d38df7b58026 Initial build and cmake setup
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84

mercurial