Re: [PATCH v4 7/8] cmake: support for building git on windows with msvc and clang
From: Sibi Siddharthan <hidden>
Date: 2020-06-15 19:56:48
On Mon, Jun 15, 2020 at 7:34 PM Øystein Walle [off-list ref] wrote:
quoted
+#Force all visual studio outputs to CMAKE_BINARY_DIRWhat is the reasoning for this? AFAIK this makes it impossible to customize it from the outside by doing `cmake -DFOO=bar ...`.
When you test git, the test system expects the binaries to be in a particular directory relative to a bunch of miscellaneous scripts(wrappers,etc). Since Visual Studio is multi config generator the binaries go into CMAKE_BINARY_DIR/(Debug|Release|RelWithDebInfo...). By doing it this way it is a bit easier to handle, along with the other generators like Makefile or Ninja.
quoted
if(WIN32) - add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res - COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR} - -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION="\\\"${PROJECT_VERSION}.GIT\\\"" - -i ${CMAKE_SOURCE_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - VERBATIM) + if(NOT MSVC)#use windres when compiling with gcc and clang + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res + COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR} + -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION="\\\"${PROJECT_VERSION}.GIT\\\"" + -i ${CMAKE_SOURCE_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM) + else()#MSVC use rc + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res + COMMAND ${CMAKE_RC_COMPILER} /d MAJOR=${PROJECT_VERSION_MAJOR} /d MINOR=${PROJECT_VERSION_MINOR} + /d MICRO=${PROJECT_VERSION_PATCH} /d PATCHLEVEL=0 /d GIT_VERSION="${PROJECT_VERSION}.GIT" + /fo ${CMAKE_BINARY_DIR}/git.res ${CMAKE_SOURCE_DIR}/git.rc + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + VERBATIM) + endif() add_custom_target(git-rc DEPENDS ${CMAKE_BINARY_DIR}/git.res) endif()If you list a .rc in the call to add_executable() then CMake knows how to handle it and will invoke the resource compiler on it. I am not 100% sure how to provide additional arguments right now, but I believe it will lead to simpler code than using add_custom_command() and add_custom_target(). Øsse
CMake does know how to handle rc commands including defines. The issue here is the conflicting redefinition of GIT_VERSION which is used in the source files. And CMake uses llvm-rc(completely broken as of llvm 9.0) for the rc compiler. Hence the above monstrocity. Thank You, Sibi Siddharthan