Skip to content

Commit 23c817b

Browse files
committed
Add a check to ensure GIT_INDEX EXISTS before attempting to build build-info.cpp
1 parent ce32060 commit 23c817b

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

common/CMakeLists.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ else()
2525
set(GIT_INDEX "")
2626
endif()
2727

28-
# Add a custom command to rebuild build-info.cpp when .git/index changes
29-
add_custom_command(
30-
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp"
31-
COMMENT "Generating build details from Git"
32-
COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION}
33-
-DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME}
34-
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -P "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen-build-info-cpp.cmake"
35-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
36-
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp.in" ${GIT_INDEX}
37-
VERBATIM
38-
)
39-
set(TARGET build_info)
40-
add_library(${TARGET} OBJECT build-info.cpp)
28+
if (EXISTS GIT_INDEX)
29+
# Add a custom command to rebuild build-info.cpp when .git/index changes
30+
add_custom_command(
31+
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp"
32+
COMMENT "Generating build details from Git"
33+
COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION}
34+
-DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME}
35+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -P "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen-build-info-cpp.cmake"
36+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
37+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp.in" ${GIT_INDEX}
38+
VERBATIM
39+
)
40+
set(TARGET build_info)
41+
add_library(${TARGET} OBJECT build-info.cpp)
42+
endif()
43+
4144
if (BUILD_SHARED_LIBS)
4245
set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
4346
endif()

0 commit comments

Comments
 (0)