Re: [PATCH v4 7/8] cmake: support for building git on windows with msvc and clang
- From
Øystein Walle <oystwa@gmail.com>
- Date
- Jun 15, 2020, 14:04 UTC
- Message-ID
- <20200615140442.1847-1-oystwa@gmail.com>
- In-Reply-To
- <f85ea0ac0ca5160a23a0a4ea26b7090638bcaf11.1591986566.git.gitgitgadget@gmail.com>
> +#Force all visual studio outputs to CMAKE_BINARY_DIR
What is the reasoning for this? AFAIK this makes it impossible to customize it from the outside by doing `cmake -DFOO=bar ...`.
Show 24 quoted lines
> 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