diff options
-rw-r--r-- | build_files/cmake/macros.cmake | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index b84950c47aa..007c147ccef 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -332,35 +332,39 @@ macro(ADD_CHECK_CXX_COMPILER_FLAG endmacro() macro(get_blender_version) - file(READ ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h CONTENT) - string(REGEX REPLACE "\n" ";" CONTENT "${CONTENT}") - string(REGEX REPLACE "\t" ";" CONTENT "${CONTENT}") - string(REGEX REPLACE " " ";" CONTENT "${CONTENT}") - - foreach(ITEM ${CONTENT}) - if(LASTITEM MATCHES "^BLENDER_VERSION$") - MATH(EXPR BLENDER_VERSION_MAJOR "${ITEM} / 100") - MATH(EXPR BLENDER_VERSION_MINOR "${ITEM} % 100") - set(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}") - endif() + # So cmake depends on BKE_blender.h, beware of inf-loops! + CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done) - if(LASTITEM MATCHES "^BLENDER_SUBVERSION$") - set(BLENDER_SUBVERSION ${ITEM}) - endif() + file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$") - if(LASTITEM MATCHES "^BLENDER_MINVERSION$") - MATH(EXPR BLENDER_MINVERSION_MAJOR "${ITEM} / 100") - MATH(EXPR BLENDER_MINVERSION_MINOR "${ITEM} % 100") - set(BLENDER_MINVERSION "${BLENDER_MINVERSION_MAJOR}.${BLENDER_MINVERSION_MINOR}") - endif() + string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}") + string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}") + string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}") + string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}") - if(LASTITEM MATCHES "^BLENDER_MINSUBVERSION$") - set(BLENDER_MINSUBVERSION ${ITEM}) - endif() + if(NOT ${_out_version} MATCHES "[0-9]+") + message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION") + endif() - set(LASTITEM ${ITEM}) - endforeach() + if(NOT ${_out_subversion} MATCHES "[0-9]+") + message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION") + endif() + + if(NOT ${_out_version_char} MATCHES "[a-z]+") + message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR") + endif() + + if(NOT ${_out_version_cycle} MATCHES "[a-z]+") + message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE") + endif() + + MATH(EXPR BLENDER_VERSION_MAJOR "${_out_version} / 100") + MATH(EXPR BLENDER_VERSION_MINOR "${_out_version} % 100") + set(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}") + + set(BLENDER_SUBVERSION ${_out_subversion}) + set(BLENDER_VERSION_CHAR ${_out_version_char}) + set(BLENDER_VERSION_CYCLE ${_out_version_cycle}) - # message(STATUS "Version major: ${BLENDER_VERSION_MAJOR}, Version minor: ${BLENDER_VERSION_MINOR}, Subversion: ${BLENDER_SUBVERSION}, Version: ${BLENDER_VERSION}") - # message(STATUS "Minversion major: ${BLENDER_MINVERSION_MAJOR}, Minversion minor: ${BLENDER_MINVERSION_MINOR}, MinSubversion: ${BLENDER_MINSUBVERSION}, Minversion: ${BLENDER_MINVERSION}") + # message(STATUS "Version (Internal): ${BLENDER_VERSION}.${BLENDER_SUBVERSION}, Version (external): ${BLENDER_VERSION}${BLENDER_VERSION_CHAR}-${BLENDER_VERSION_CYCLE}") endmacro() |