1- cmake_minimum_required (VERSION 3.25 )
1+ cmake_minimum_required (VERSION 3.16 )
22
33project (omodsim
44 VERSION 1.9.0
5+ DESCRIPTION "An Open Source Modbus Slave (Server) Utility"
56 LANGUAGES CXX )
67
78set (CMAKE_AUTOUIC ON )
@@ -10,11 +11,22 @@ set(CMAKE_AUTORCC ON)
1011set (CMAKE_CXX_STANDARD 17)
1112set (CMAKE_CXX_STANDARD_REQUIRED ON )
1213set (PRODUCT_NAME "Open ModSim" )
14+ set (EXECUTABLE_PATH "${CMAKE_INSTALL_PREFIX} /bin/${PROJECT_NAME} " )
15+
16+ # Split version to major, minor, patch
17+ string (REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION} )
18+ list (GET VERSION_LIST 0 VERSION_MAJOR)
19+ list (GET VERSION_LIST 1 VERSION_MINOR)
20+ list (GET VERSION_LIST 2 VERSION_PATCH)
1321
1422# Find Qt6 or fallback to Qt5
1523find_package (Qt6 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Core5Compat Qml Help LinguistTools QUIET )
1624if (NOT Qt6_FOUND)
17- find_package (Qt5 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Qml Help LinguistTools QUIET REQUIRED )
25+ find_package (Qt5 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Qml Help LinguistTools QUIET )
26+ endif ()
27+
28+ if (NOT Qt6_FOUND AND NOT Qt5_FOUND)
29+ message (FATAL_ERROR "One or more Qt development packages not found. Please install Qt5 or Qt6 development packages." )
1830endif ()
1931
2032if (Qt6_FOUND)
@@ -30,6 +42,21 @@ endif()
3042# Define target
3143add_executable (${PROJECT_NAME} )
3244
45+ find_package (Git QUIET )
46+ if (GIT_FOUND)
47+ execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
48+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} /../.git
49+ OUTPUT_VARIABLE GIT_BRANCH
50+ OUTPUT_STRIP_TRAILING_WHITESPACE
51+ ERROR_QUIET )
52+
53+ if (${GIT_BRANCH} MATCHES dev)
54+ set (PROJECT_VERSION ${VERSION_MAJOR} .${VERSION_MINOR} -dev)
55+ endif ()
56+ else ()
57+ message (STATUS "Git not found - skipping branch detection" )
58+ endif ()
59+
3360# Define compile definitions
3461add_compile_definitions (APP_NAME= "${PRODUCT_NAME} " )
3562add_compile_definitions (APP_DESCRIPTION= "${PROJECT_DESCRIPTION} " )
@@ -285,23 +312,18 @@ else()
285312 COMMENT "Updating translation files..."
286313 )
287314 add_custom_target (update_translations ALL DEPENDS ${TS_FILES} )
288-
289315endif ()
290316
291317if (WIN32 )
292- string (REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION} )
293- list (GET VERSION_LIST 0 VERSION_MAJOR)
294- list (GET VERSION_LIST 1 VERSION_MINOR)
295- list (GET VERSION_LIST 2 VERSION_PATCH)
296-
297- set (EXECUTABLE_NAME "omodsim" )
298318 set (ICON_FILE "${CMAKE_CURRENT_SOURCE_DIR} /res/omodsim.ico" )
299- set (RC_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR} /omodsim.rc.in" )
300- set (GENERATED_RC "${CMAKE_BINARY_DIR} /omodsim.rc" )
301319
302- configure_file (${RC_TEMPLATE} ${GENERATED_RC} @ONLY )
320+ configure_file (
321+ "${CMAKE_CURRENT_SOURCE_DIR} /omodsim.rc.in"
322+ "${CMAKE_BINARY_DIR} /omodsim.rc"
323+ @ONLY
324+ )
303325
304- target_sources (${PROJECT_NAME} PRIVATE ${ICON_PATH} ${GENERATED_RC} )
326+ target_sources (${PROJECT_NAME} PRIVATE ${ICON_PATH} " ${CMAKE_BINARY_DIR} /omodsim.rc" )
305327 set_target_properties (${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE ON )
306328endif ()
307329
0 commit comments