[12] | 1 | @echo off
|
---|
| 2 | setlocal ENABLEDELAYEDEXPANSION
|
---|
| 3 |
|
---|
[13] | 4 | set DebugOutput=0
|
---|
[12] | 5 | set ExampleComponent=ExampleComponent
|
---|
| 6 |
|
---|
| 7 | :argc
|
---|
| 8 | set argc=0
|
---|
| 9 | for %%x in (%*) do set /A argc+=1
|
---|
| 10 |
|
---|
| 11 | :usage
|
---|
| 12 | if %argC% lss 1 (
|
---|
| 13 | echo Usage:
|
---|
| 14 | echo %0 ^<componentName^>
|
---|
| 15 | goto:EOF
|
---|
| 16 | )
|
---|
| 17 |
|
---|
| 18 | :args
|
---|
| 19 | set _componentName=%1
|
---|
| 20 | set _componentDir=%_componentName%Component
|
---|
| 21 | call :UCase _componentDir _componentDirCaps
|
---|
| 22 | if %DebugOutput%==1 (
|
---|
| 23 | echo _componentName=%_componentName%
|
---|
| 24 | echo _componentDir=%_componentDir%
|
---|
| 25 | echo _componentDirCaps=%_componentDirCaps%
|
---|
| 26 | )
|
---|
| 27 |
|
---|
| 28 | :cmake
|
---|
| 29 | ::cmake %ExampleComponent% -DCOMPONENT_NAME:STRING=%_componentName%
|
---|
| 30 | ::if %ERRORLEVEL% GEQ 1 (
|
---|
| 31 | :: echo CMake must be installed and added to PATH
|
---|
| 32 | :: goto:EOF
|
---|
| 33 | ::)
|
---|
| 34 | ::goto:EOF
|
---|
| 35 |
|
---|
| 36 | :dir
|
---|
| 37 | if exist %_componentDir% (
|
---|
| 38 | echo Directory %_componentDir% exists already!
|
---|
| 39 | echo Please delete it first and retry.
|
---|
| 40 | goto:EOF
|
---|
| 41 | )
|
---|
| 42 | mkdir %_componentDir%
|
---|
| 43 | if not exist %_componentDir% (
|
---|
| 44 | echo Directory %_componentDir% could not be created!
|
---|
| 45 | goto:EOF
|
---|
| 46 | )
|
---|
| 47 |
|
---|
| 48 | :copy
|
---|
| 49 | ::xcopy /S %ExampleComponent% %_componentDir%
|
---|
| 50 | copy %ExampleComponent%\CMakeLists.txt %_componentDir%\CMakeLists.txt
|
---|
| 51 | copy %ExampleComponent%\%ExampleComponent%.cpp %_componentDir%\%_componentDir%.cpp
|
---|
| 52 | copy %ExampleComponent%\%ExampleComponent%.h %_componentDir%\%_componentDir%.h
|
---|
| 53 | copy %ExampleComponent%\%ExampleComponent%Config.h %_componentDir%\%_componentDir%Config.h
|
---|
| 54 |
|
---|
| 55 | :substitute
|
---|
| 56 | set SedFile=NewComponent.sed
|
---|
| 57 | set _currentDate=%DATE%
|
---|
| 58 | :: escape / character
|
---|
| 59 | set _currentDate=!_currentDate:/=\/!
|
---|
| 60 | :: take first 8 characters (without milliseconds)
|
---|
| 61 | set _currentTime=%TIME:~0,8%
|
---|
| 62 | set _userName=%USERNAME%
|
---|
| 63 |
|
---|
| 64 | echo s/${^<PROJECT_NAME^>}/%_componentDir%/g > %SedFile%
|
---|
| 65 | echo s/${^<PROJECT_NAME_CAPS^>}/%_componentDirCaps%/g >> %SedFile%
|
---|
| 66 | echo s/${^<CURRENT_DATE^>}/%_currentDate%/g >> %SedFile%
|
---|
| 67 | echo s/${^<CURRENT_TIME^>}/%_currentTime%/g >> %SedFile%
|
---|
| 68 | echo s/${^<CURRENT_DATETIME^>}/%_currentDate% %_currentTime%/g >> %SedFile%
|
---|
| 69 | echo s/${^<USERNAME^>}/%_userName%/g >> %SedFile%
|
---|
| 70 |
|
---|
| 71 | for /r . %%f in (%_componentDir%\*) do (
|
---|
| 72 | if %DebugOutput%==1 (
|
---|
| 73 | echo %%f
|
---|
| 74 | )
|
---|
| 75 | sed -f %SedFile% %%f > %%f.tmp
|
---|
| 76 | )
|
---|
| 77 |
|
---|
| 78 | for /r . %%f in (%_componentDir%\*.tmp) do (
|
---|
| 79 | if %DebugOutput%==1 (
|
---|
| 80 | echo %%f
|
---|
| 81 | )
|
---|
| 82 | mv %%f %%~pnf
|
---|
| 83 | )
|
---|
| 84 |
|
---|
[13] | 85 | ::cmake-manual-changes
|
---|
| 86 | echo NOTE:
|
---|
| 87 | echo You have to add line:
|
---|
| 88 | echo add_subdirectory(%_componentDir%)
|
---|
| 89 | echo to the root CMakeLists.txt.
|
---|
| 90 |
|
---|
[12] | 91 | goto:EOF
|
---|
| 92 |
|
---|
| 93 | :LCase
|
---|
| 94 | :UCase
|
---|
| 95 | :: Converts to upper/lower case variable contents
|
---|
| 96 | :: Syntax: CALL :UCase _VAR1 _VAR2
|
---|
| 97 | :: Syntax: CALL :LCase _VAR1 _VAR2
|
---|
| 98 | :: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
|
---|
| 99 | :: _VAR2 = NAME of variable to hold the converted value
|
---|
| 100 | :: Note: Use variable NAMES in the CALL, not values (pass "by reference")
|
---|
| 101 |
|
---|
[13] | 102 | set _UCase=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
|
---|
| 103 | set _LCase=a b c d e f g h i j k l m n o p q r s t u v w x y z
|
---|
| 104 | set _Lib_UCase_Tmp=!%1!
|
---|
| 105 | if /I "%0"==":UCase" (
|
---|
| 106 | set _Abet=%_UCase%
|
---|
[12] | 107 | )
|
---|
[13] | 108 | if /I "%0"==":LCase" (
|
---|
| 109 | set _Abet=%_LCase%
|
---|
| 110 | )
|
---|
| 111 | for %%Z in (%_Abet%) do (
|
---|
| 112 | set _Lib_UCase_Tmp=!_Lib_UCase_Tmp:%%Z=%%Z!
|
---|
| 113 | )
|
---|
| 114 | set %2=%_Lib_UCase_Tmp%
|
---|
| 115 | goto:EOF
|
---|