@@ -8,6 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
8
8
add_subdirectory (fmt-11.1.1 )
9
9
10
10
include (CheckCXXCompilerFlag )
11
+ include (GNUInstallDirs )
11
12
12
13
set (VERSION 0.9 )
13
14
@@ -61,6 +62,44 @@ else()
61
62
set (DSOAL_LINK_FLAGS ${DSOAL_LINK_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state" )
62
63
endif (MSVC )
63
64
65
+
66
+ find_package (Git )
67
+ option (DSOAL_UPDATE_BUILD_VERSION "Update git build version info" ON )
68
+ if (DSOAL_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${dsoal_SOURCE_DIR} /.git" )
69
+ set (GIT_DIR "${dsoal_SOURCE_DIR} /.git" )
70
+
71
+ # Check if this is a submodule, if it is then find the .git directory
72
+ if (NOT IS_DIRECTORY "${dsoal_SOURCE_DIR} /.git" )
73
+ file (READ ${GIT_DIR} submodule )
74
+ string (REGEX REPLACE "gitdir: (.*)$" "\\ 1" GIT_DIR_RELATIVE ${submodule} )
75
+ string (STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE )
76
+ get_filename_component (SUBMODULE_DIR ${GIT_DIR} PATH )
77
+ get_filename_component (GIT_DIR ${SUBMODULE_DIR} /${GIT_DIR_RELATIVE} ABSOLUTE )
78
+ endif ()
79
+
80
+ # Get the current working branch and its latest abbreviated commit hash
81
+ add_custom_command (OUTPUT "${dsoal_BINARY_DIR} /version_witness.txt"
82
+ BYPRODUCTS "${dsoal_BINARY_DIR} /version.h"
83
+ COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${VERSION}
84
+ -D SRC=${dsoal_SOURCE_DIR}/version.h.in -D DST=${dsoal_BINARY_DIR}/version.h
85
+ -P ${dsoal_SOURCE_DIR} /version.cmake
86
+ COMMAND ${CMAKE_COMMAND} -E touch "${dsoal_BINARY_DIR} /version_witness.txt"
87
+ WORKING_DIRECTORY "${dsoal_SOURCE_DIR} "
88
+ MAIN_DEPENDENCY "${dsoal_SOURCE_DIR} /version.h.in"
89
+ DEPENDS "${GIT_DIR} /index" "${dsoal_SOURCE_DIR} /version.cmake"
90
+ VERBATIM
91
+ )
92
+
93
+ add_custom_target (dsoal.build_version DEPENDS "${dsoal_BINARY_DIR} /version_witness.txt" )
94
+ else ()
95
+ set (GIT_BRANCH "UNKNOWN" )
96
+ set (GIT_COMMIT_HASH "unknown" )
97
+ configure_file (
98
+ "${dsoal_SOURCE_DIR} /version.h.in"
99
+ "${dsoal_BINARY_DIR} /version.h" )
100
+ endif ()
101
+
102
+
64
103
if (MINGW )
65
104
set (CMAKE_RC_COMPILER_INIT windres )
66
105
set (CMAKE_RC_COMPILE_OBJECT
@@ -108,16 +147,20 @@ set(TXT_FILES
108
147
add_library (dsound SHARED ${SRC_OBJS} version .rc ${DEF_FILE} ${TXT_FILES} )
109
148
set_target_properties (dsound PROPERTIES PREFIX "" )
110
149
target_link_libraries (dsound PRIVATE dsoal::fmt ${DSOAL_LINK_FLAGS} )
150
+ target_include_directories (dsound PRIVATE ${dsoal_BINARY_DIR} )
111
151
target_compile_definitions (dsound PRIVATE DSOAL_LIBRARY ${DSOAL_CPPDEFS} )
112
152
target_compile_options (dsound PRIVATE ${DSOAL_CFLAGS} )
153
+ if (TARGET dsoal.build_version )
154
+ add_dependencies (dsound dsoal.build_version )
155
+ endif ()
113
156
114
157
install (TARGETS dsound
115
158
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
116
159
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
117
160
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
118
- if (EXISTS "${DSOAL_BINARY_DIR } /dsoal-aldrv.dll" )
161
+ if (EXISTS "${dsoal_BINARY_DIR } /dsoal-aldrv.dll" )
119
162
install (FILES
120
- "${DSOAL_BINARY_DIR } /dsoal-aldrv.dll"
163
+ "${dsoal_BINARY_DIR } /dsoal-aldrv.dll"
121
164
DESTINATION ${CMAKE_INSTALL_BINDIR} )
122
165
endif ()
123
166
0 commit comments