Skip to content

Commit

Permalink
Improve Version.h handling
Browse files Browse the repository at this point in the history
Always check for version changes when building. Version.h is only
updated if actually changed.
  • Loading branch information
realthunder authored and wwmayer committed Aug 17, 2019
1 parent bd2f519 commit a59caf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/App/CMakeLists.txt
Expand Up @@ -288,6 +288,8 @@ add_library(FreeCADApp SHARED ${FreeCADApp_SRCS})

target_link_libraries(FreeCADApp ${FreeCADApp_LIBS})

add_dependencies(FreeCADApp fc_version)

SET_BIN_DIR(FreeCADApp FreeCADApp)

if(WIN32)
Expand Down
41 changes: 21 additions & 20 deletions src/Build/CMakeLists.txt
Expand Up @@ -6,25 +6,26 @@ set(PACKAGE_WCURL "$WCURL$")
# If the sources don't include a Version.h then create one
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Version.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/Version.h.in
)

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/SubWCRev.py
--srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)

fc_copy_file_if_different(
"${CMAKE_CURRENT_BINARY_DIR}/Version.h.out"
"${CMAKE_CURRENT_BINARY_DIR}/Version.h"
)

# as fallback if Version.h isn't created for any reason
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/Version.h)
set(PACKAGE_WCREF ${PACKAGE_VERSION_PATCH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Version.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/Version.h
)
endif (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/Version.h)
${CMAKE_CURRENT_BINARY_DIR}/Version.h.in)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Version.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/Version.h.out
${CMAKE_CURRENT_BINARY_DIR}/Version.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS version_check)

add_custom_command(
OUTPUT version_check
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/SubWCRev.py
--srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

ADD_CUSTOM_TARGET(fc_version DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Version.h)

else (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)

This comment has been minimized.

Copy link
@jakoch

jakoch Feb 11, 2024

seems like an superfluous else block, the if starts with
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)


ADD_CUSTOM_TARGET(fc_version DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)

endif (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)

0 comments on commit a59caf4

Please sign in to comment.