mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Add CATCH_VERSION_* defines for external use
I wonder how much use they will actually see, but their cost is fairly minor. Closes #1131
This commit is contained in:
		| @@ -106,6 +106,20 @@ int main( int argc, char* argv[] ) | |||||||
|  |  | ||||||
| See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details. | See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details. | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ## Version detection | ||||||
|  |  | ||||||
|  | Catch provides a triplet of macros providing the header's version,  | ||||||
|  |  | ||||||
|  | * `CATCH_VERSION_MAJOR` | ||||||
|  | * `CATCH_VERSION_MINOR` | ||||||
|  | * `CATCH_VERSION_PATCH` | ||||||
|  |  | ||||||
|  | these macros expand into a single number, that corresponds to the appropriate | ||||||
|  | part of the version. As an example, given single header version v2.3.4, | ||||||
|  | the macros would expand into `2`, `3`, and `4` respectively. | ||||||
|  |  | ||||||
|  |  | ||||||
| --- | --- | ||||||
|  |  | ||||||
| [Home](Readme.md#top) | [Home](Readme.md#top) | ||||||
|   | |||||||
| @@ -9,6 +9,9 @@ | |||||||
| #ifndef TWOBLUECUBES_CATCH_HPP_INCLUDED | #ifndef TWOBLUECUBES_CATCH_HPP_INCLUDED | ||||||
| #define TWOBLUECUBES_CATCH_HPP_INCLUDED | #define TWOBLUECUBES_CATCH_HPP_INCLUDED | ||||||
|  |  | ||||||
|  | #define CATCH_VERSION_MAJOR 2 | ||||||
|  | #define CATCH_VERSION_MINOR 1 | ||||||
|  | #define CATCH_VERSION_PATCH 1 | ||||||
|  |  | ||||||
| #ifdef __clang__ | #ifdef __clang__ | ||||||
| #    pragma clang system_header | #    pragma clang system_header | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ from scriptCommon import catchPath | |||||||
| versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' ) | versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' ) | ||||||
| rootPath = os.path.join( catchPath, 'include/' ) | rootPath = os.path.join( catchPath, 'include/' ) | ||||||
| versionPath = os.path.join( rootPath, "internal/catch_version.cpp" ) | versionPath = os.path.join( rootPath, "internal/catch_version.cpp" ) | ||||||
|  | definePath = os.path.join(rootPath, 'catch.hpp') | ||||||
| readmePath = os.path.join( catchPath, "README.md" ) | readmePath = os.path.join( catchPath, "README.md" ) | ||||||
| conanPath = os.path.join(catchPath, 'conanfile.py') | conanPath = os.path.join(catchPath, 'conanfile.py') | ||||||
| conanTestPath = os.path.join(catchPath, 'test_package', 'conanfile.py') | conanTestPath = os.path.join(catchPath, 'test_package', 'conanfile.py') | ||||||
| @@ -137,10 +138,27 @@ def updateCmakeFile(version): | |||||||
|             else: |             else: | ||||||
|                 file.write(line) |                 file.write(line) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def updateVersionDefine(version): | ||||||
|  |     with open(definePath, 'r') as file: | ||||||
|  |         lines = file.readlines() | ||||||
|  |     with open(definePath, 'w') as file: | ||||||
|  |         for line in lines: | ||||||
|  |             if '#define CATCH_VERSION_MAJOR' in line: | ||||||
|  |                 file.write('#define CATCH_VERSION_MAJOR {}\n'.format(version.majorVersion)) | ||||||
|  |             elif '#define CATCH_VERSION_MINOR' in line: | ||||||
|  |                 file.write('#define CATCH_VERSION_MINOR {}\n'.format(version.minorVersion)) | ||||||
|  |             elif '#define CATCH_VERSION_PATCH' in line: | ||||||
|  |                 file.write('#define CATCH_VERSION_PATCH {}\n'.format(version.patchNumber)) | ||||||
|  |             else: | ||||||
|  |                 file.write(line) | ||||||
|  |  | ||||||
|  |  | ||||||
| def performUpdates(version): | def performUpdates(version): | ||||||
|     # First update version file, so we can regenerate single header and |     # First update version file, so we can regenerate single header and | ||||||
|     # have it ready for upload to wandbox, when updating readme |     # have it ready for upload to wandbox, when updating readme | ||||||
|     version.updateVersionFile() |     version.updateVersionFile() | ||||||
|  |     updateVersionDefine(version) | ||||||
|  |  | ||||||
|     import generateSingleHeader |     import generateSingleHeader | ||||||
|     generateSingleHeader.generate(version) |     generateSingleHeader.generate(version) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský