Skip to content

Commit

Permalink
Let CMake generate version.h
Browse files Browse the repository at this point in the history
  • Loading branch information
tstenner authored and MKleusberg committed Aug 21, 2021
1 parent c4ebc20 commit 38907cc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 56 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ src/sqlitebrowser
src/Makefile*
src/debug
src/release
src/gen_version.h

# ignore compiled translation files
src/translations/*.qm
Expand Down
87 changes: 48 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ OPTION(sqlcipher "Build with SQLCipher library" OFF)
# used by the nightly version to add the date of the build.
string(TIMESTAMP BUILD_VERSION "%Y%m%d")

add_definitions(-std=c++14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

if(APPLE)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE)
elseif(WIN32)
add_executable(${PROJECT_NAME} WIN32)
else()
add_executable(${PROJECT_NAME})
endif()

if(NOT BUILD_STABLE_VERSION)
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_VERSION=${BUILD_VERSION})
endif()

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")

# BUILD_VERSION is the current date in YYYYMMDD format. It is only
# used by the nightly version to add the date of the build.
string(TIMESTAMP BUILD_VERSION "%Y%m%d")

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")

if(NOT CMAKE_BUILD_TYPE)
Expand All @@ -26,10 +51,6 @@ if(NOT BUILD_STABLE_VERSION)
add_definitions(-DBUILD_VERSION=${BUILD_VERSION})
endif()

add_definitions(-std=c++14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
Expand Down Expand Up @@ -96,7 +117,7 @@ if(FORCE_INTERNAL_QHEXEDIT)
else()
find_package(QHexEdit)
endif()
set(JSON_DIR libs/json)
include_directories(${CMAKE_CURRENT_LIST_DIR}/libs/json)

if(NOT QSCINTILLA_FOUND)
set(QSCINTILLA_DIR libs/qscintilla/Qt4Qt5)
Expand All @@ -111,17 +132,18 @@ if(NOT QCustomPlot_FOUND)
set(QCustomPlot_DIR libs/qcustomplot-source)
add_subdirectory(${QCustomPlot_DIR})
endif()
add_subdirectory(${JSON_DIR})

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

if(ENABLE_TESTING)
enable_testing()
endif()

set(SQLB_HDR
src/version.h
# generate file with version information
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/version.h
)

target_sources(${PROJECT_NAME}
PRIVATE
src/sql/sqlitetypes.h
src/sql/Query.h
src/sql/ObjectIdentifier.h
Expand All @@ -135,7 +157,8 @@ set(SQLB_HDR
src/sql/parser/sqlite3_parser.hpp
)

set(SQLB_MOC_HDR
target_sources(${PROJECT_NAME}
PRIVATE
src/sqlitedb.h
src/AboutDialog.h
src/EditIndexDialog.h
Expand Down Expand Up @@ -190,7 +213,8 @@ set(SQLB_MOC_HDR
src/TableBrowserDock.h
)

set(SQLB_SRC
target_sources(${PROJECT_NAME}
PRIVATE
src/AboutDialog.cpp
src/EditIndexDialog.cpp
src/EditDialog.cpp
Expand Down Expand Up @@ -367,12 +391,12 @@ if(WIN32)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o"
COMMAND windres "-I${CMAKE_CURRENT_SOURCE_DIR}" "-i${CMAKE_CURRENT_SOURCE_DIR}/src/winapp.rc" -o "${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o" VERBATIM
)
set(SQLB_SRC ${SQLB_SRC} "${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o")
target_sources(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/sqlbicon.o")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-subsystem,windows")
set(WIN32_STATIC_LINK -Wl,-Bstatic -lssl -lcrypto -lws2_32)
set(ADDITIONAL_LIBS lzma)
else()
set(SQLB_SRC ${SQLB_SRC} "${CMAKE_CURRENT_SOURCE_DIR}/src/winapp.rc")
target_sources(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/winapp.rc")
endif()
else()
set(LPTHREAD pthread)
Expand Down Expand Up @@ -410,12 +434,11 @@ if(WIN32 AND MSVC)
include_directories(${SQLITE3_INCLUDE_DIR})
endif()

include_directories(
"${CMAKE_CURRENT_BINARY_DIR}"
${JSON_DIR}
target_include_directories(${PROJECT_NAME} PRIVATE
${ADDITIONAL_INCLUDE_PATHS}
src
)

if(QHexEdit_FOUND)
include_directories(${QHexEdit_INCLUDE_DIR})
else()
Expand All @@ -432,27 +455,13 @@ else()
include_directories(${QSCINTILLA_DIR})
endif()

if(NOT APPLE)
add_executable(${PROJECT_NAME}
${SQLB_HDR}
${SQLB_SRC}
${SQLB_FORM_HDR}
${SQLB_MOC}
${SQLB_MOC_HDR}
${SQLB_RESOURCES_RCC}
${SQLB_MISC}
)
else()
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
${SQLB_HDR}
${SQLB_SRC}
${SQLB_FORM_HDR}
${SQLB_MOC}
${SQLB_MOC_HDR}
${SQLB_RESOURCES_RCC}
${SQLB_MISC}
)
endif()
target_sources(${PROJECT_NAME}
PRIVATE
${SQLB_FORM_HDR}
${SQLB_MOC}
${SQLB_RESOURCES_RCC}
${SQLB_MISC}
)

# Warnings
if(ALL_WARNINGS AND CMAKE_COMPILER_IS_GNUCC)
Expand Down
16 changes: 0 additions & 16 deletions src/version.h

This file was deleted.

15 changes: 15 additions & 0 deletions src/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// version file to be preprocessed by CMake
#ifndef GEN_VERSION_H
#define GEN_VERSION_H
#define MAJOR_VERSION @PROJECT_VERSION_MAJOR@
#define MINOR_VERSION @PROJECT_VERSION_MINOR@
#define PATCH_VERSION @PROJECT_VERSION_PATCH@

#define APP_VERSION "@PROJECT_VERSION@"

// If it is defined by the compiler, then it is a nightly build, and in the YYYYMMDD format.
#ifndef BUILD_VERSION
#define BUILD_VERSION 0
#endif

#endif

0 comments on commit 38907cc

Please sign in to comment.