|
| 1 | +# This CMake script should be used to create a new Midas module. Requires CMake v2.8.3+ |
| 2 | +# Call as |
| 3 | +# cmake -P NewModule.cmake modulename |
| 4 | +# Where modulename is the name of your module. It should have no spaces in it. |
| 5 | +# |
| 6 | +if(NOT DEFINED CMAKE_ARGV3) |
| 7 | + message(FATAL_ERROR "Must pass in module name as an argument: cmake -P NewModule.cmake mymodule") |
| 8 | +endif() |
| 9 | + |
| 10 | +set(moduleName "${CMAKE_ARGV3}") |
| 11 | +set(templateRoot "${CMAKE_CURRENT_LIST_DIR}/moduleTemplate") |
| 12 | +string(SUBSTRING "${moduleName}" 0 1 firstChar) |
| 13 | +string(SUBSTRING "${moduleName}" 1 -1 restOfString) |
| 14 | +string(TOUPPER ${firstChar} firstChar) |
| 15 | +string(TOLOWER "${restOfString}" restOfString) |
| 16 | +string(TOLOWER "${moduleName}" MN) |
| 17 | +set(MN_CAP "${firstChar}${restOfString}") |
| 18 | +set(moduleRoot "${CMAKE_CURRENT_LIST_DIR}/../modules/${MN}") |
| 19 | + |
| 20 | +message("Creating skeleton module at ${moduleRoot}") |
| 21 | +if(EXISTS "${moduleRoot}") |
| 22 | + message(FATAL_ERROR "File or directory already exists: ${moduleRoot}") |
| 23 | +endif() |
| 24 | + |
| 25 | +file(MAKE_DIRECTORY "${moduleRoot}") |
| 26 | +file(GLOB_RECURSE templateFiles RELATIVE "${templateRoot}" "${templateRoot}/*") |
| 27 | +foreach(templateFile ${templateFiles}) |
| 28 | + set(fullPath "${templateRoot}/${templateFile}") |
| 29 | + if(IS_DIRECTORY "${fullPath}") |
| 30 | + file(MAKE_DIRECTORY "${moduleRoot}/${templateFile}") |
| 31 | + else() |
| 32 | + configure_file("${fullPath}" "${moduleRoot}/${templateFile}" @ONLY) |
| 33 | + endif() |
| 34 | +endforeach() |
| 35 | +message("Done") |
0 commit comments