cmake : fix build-info.h on MSVC (#3309)

This commit is contained in:
DAN™ 2023-09-25 18:45:33 -04:00 committed by GitHub
parent 1726f9626f
commit 99115f3fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 34 deletions

View File

@ -118,7 +118,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
add_custom_command( add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h" OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h"
COMMENT "Generating build details from Git" COMMENT "Generating build details from Git"
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake" COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION} -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS "${GIT_DIR}/index" DEPENDS "${GIT_DIR}/index"
VERBATIM VERBATIM

View File

@ -8,16 +8,12 @@ set(BUILD_TARGET "unknown")
# Look for git # Look for git
find_package(Git) find_package(Git)
if(NOT Git_FOUND) if(NOT Git_FOUND)
execute_process( find_program(GIT_EXECUTABLE NAMES git git.exe)
COMMAND which git if(GIT_EXECUTABLE)
OUTPUT_VARIABLE GIT_EXECUTABLE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_EXECUTABLE STREQUAL "")
set(Git_FOUND TRUE) set(Git_FOUND TRUE)
message(STATUS "Found Git using 'which': ${GIT_EXECUTABLE}") message(STATUS "Found Git: ${GIT_EXECUTABLE}")
else() else()
message(WARNING "Git not found using 'find_package' or 'which'. Build info will not be accurate. Consider installing Git or ensuring it is in the PATH.") message(WARNING "Git not found. Build info will not be accurate.")
endif() endif()
endif() endif()
@ -28,43 +24,32 @@ if(Git_FOUND)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE HEAD OUTPUT_VARIABLE HEAD
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_HEAD_RESULT
) )
execute_process( execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE COUNT OUTPUT_VARIABLE COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_COUNT_RESULT
) )
if(GIT_HEAD_RESULT EQUAL 0 AND GIT_COUNT_RESULT EQUAL 0)
set(BUILD_COMMIT ${HEAD})
set(BUILD_NUMBER ${COUNT})
endif()
endif()
if(GIT_HEAD_RESULT EQUAL 0 AND GIT_COUNT_RESULT EQUAL 0)
set(BUILD_COMMIT ${HEAD}) set(BUILD_COMMIT ${HEAD})
set(BUILD_NUMBER ${COUNT}) set(BUILD_NUMBER ${COUNT})
endif() endif()
execute_process( if(MSVC)
COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER} set(BUILD_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}")
OUTPUT_VARIABLE OUT set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME})
OUTPUT_STRIP_TRAILING_WHITESPACE else()
RESULT_VARIABLE RES execute_process(
) COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}
if (RES EQUAL 0) OUTPUT_VARIABLE OUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(BUILD_COMPILER ${OUT}) set(BUILD_COMPILER ${OUT})
endif() execute_process(
COMMAND ${CMAKE_C_COMPILER} -dumpmachine
execute_process( OUTPUT_VARIABLE OUT
COMMAND ${CMAKE_C_COMPILER} -dumpmachine OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE OUT )
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RES
)
if (RES EQUAL 0)
set(BUILD_TARGET ${OUT}) set(BUILD_TARGET ${OUT})
endif() endif()