Sun, 06 Feb 2022 16:52:20 +0100
Initial build and cmake setup
1 | 1 | # CMakeLists.txt is part of bmsapp |
2 | # | |
3 | ||
4 | PROJECT(bmsapp) | |
5 | CMAKE_MINIMUM_REQUIRED( VERSION 3.6 ) | |
6 | SET(bmsapp_EXECUTABLE "bmsapp") | |
7 | MESSAGE( STATUS "Building bmsapp" ) | |
8 | ||
9 | # Version | |
10 | ||
11 | SET( bmsapp_VERSION_MAJOR 0 ) | |
12 | SET( bmsapp_VERSION_MINOR 1 ) | |
13 | SET( bmsapp_VERSION_PATCH 0 ) | |
14 | ||
15 | # Compile flags | |
16 | ||
17 | # Automatically run moc on source files when necessary | |
18 | set(CMAKE_AUTOMOC ON) | |
19 | ||
20 | SET( CMAKE_CXX_FLAGS_RELEASE "-Wall -ansi -pedantic -Wno-long-long -O2 -pipe" ) | |
21 | SET( CMAKE_CXX_FLAGS_DEBUG "-Wall -g3 -pipe" ) | |
22 | ||
23 | #====================================================Set build type===================================================== | |
24 | # We might always to tell the compiler to include debugging information (eg via the -g option on gcc). It makes the | |
25 | # binaries slightly bigger on Linux, but helps greatly in analysing core dumps etc. (In closed-source projects people | |
26 | # sometimes turn it off for release builds to make it harder to reverse engineer the software, but obviously that's not | |
27 | # an issue for us.) | |
28 | # | |
29 | # However, setting CMAKE_BUILD_TYPE to "Debug", also changes other things, such as the default location for config | |
30 | # files, which we don't want on a release build, so we would probably need to set compiler flags directly. | |
31 | # | |
32 | # .:TBD:. Investigate whether setting CMAKE_BUILD_TYPE to "RelWithDebInfo" does what we want. | |
33 | # | |
34 | #IF( ${DO_RELEASE_BUILD} ) | |
35 | # SET(CMAKE_BUILD_TYPE "Release") | |
36 | #ELSE() | |
37 | # SET(CMAKE_BUILD_TYPE "Debug") | |
38 | #ENDIF() | |
39 | ||
40 | #============================Directories======================================= | |
41 | ||
42 | SET(ROOTDIR "${CMAKE_CURRENT_SOURCE_DIR}") | |
43 | SET(SRCDIR "${ROOTDIR}/src") | |
44 | #SET(UIDIR "${ROOTDIR}/ui") | |
45 | #SET(DATADIR "${ROOTDIR}/data") | |
46 | #SET(TRANSLATIONSDIR "${ROOTDIR}/translations") | |
47 | ||
48 | INCLUDE_DIRECTORIES(${SRCDIR}) | |
49 | INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/src") # In case of out-of-source build. | |
50 | ||
51 | #==================================Find Qt5==================================== | |
52 | ||
53 | find_package(Qt5 REQUIRED COMPONENTS Core Widgets) | |
54 | ||
55 | # Network PrintSupport Sql Xml LinguistTools | |
56 | ||
57 | # Some extra files for the "make clean" target. | |
58 | SET_PROPERTY( | |
59 | DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
60 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES | |
61 | cmake_install.cmake | |
62 | compile_commands.json | |
63 | CMakeCache.txt | |
64 | ) | |
65 | ||
66 | #==============================Setup the config.h============================== | |
67 | ||
68 | # Tell cmake where the configure file is and where | |
69 | # to put the output. All variables in config.in written as "${VAR}$ | |
70 | # will be replaced by VAR as determined by cmake in config.h. | |
71 | # Outputs only in the build directory. | |
72 | CONFIGURE_FILE( src/config.in src/config.h ) | |
73 | ||
74 | # ===== Process other CMakeList.txt's ===== | |
75 | ||
76 | set( SOURCE_FILES | |
77 | ${SRCDIR}/main.cpp | |
78 | ) | |
79 | ||
80 | # ===== Build the application ===== | |
81 | ||
82 | add_executable(${bmsapp_EXECUTABLE} ${SOURCE_FILES}) | |
83 | target_link_libraries(${bmsapp_EXECUTABLE} Qt5::Core Qt5::Widgets) | |
84 |