]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Lib/CMake/modules.cmake
Adding convenience loader scripts for DFU based microcontrollers
[kiibohd-controller.git] / Lib / CMake / modules.cmake
index f39e1c9fc184d996ab1d88ce6c86ac8bf24c0f95..fc8685b429344fff9fdc398de9625cf0d43ed745 100644 (file)
@@ -7,6 +7,13 @@
 ###
 
 
+###
+# CMake Custom Modules Path
+#
+
+set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/Lib/CMake/" )
+
+
 
 ###
 # Module Overrides (Used in the buildall.bash script)
@@ -105,11 +112,6 @@ include    (           "${DebugModulePath}/setup.cmake"  )
 PathPrepend( DEBUG_SRCS ${DebugModulePath} ${DEBUG_SRCS} )
 
 
-#| Default Map
-# TODO Add support for different defaultMaps
-configure_file( "${ScanModulePath}/defaultMap.h" defaultMap.h )
-
-
 #| Print list of all module sources
 message( STATUS "Detected Scan Module Source Files:" )
 message( "${SCAN_SRCS}" )
@@ -122,6 +124,14 @@ message( "${DEBUG_SRCS}" )
 
 
 
+###
+# CMake Module Checking
+#
+find_package( Git REQUIRED )
+find_package( Ctags ) # Optional
+
+
+
 ###
 # Generate USB Defines
 #
@@ -135,7 +145,7 @@ set( MANUFACTURER "Kiibohd" )
 
 #| Modified
 #| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
-execute_process( COMMAND git status -s -uno --porcelain
+execute_process( COMMAND ${GIT_EXECUTABLE} status -s -uno --porcelain
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        OUTPUT_VARIABLE Git_Modified_INFO
        ERROR_QUIET
@@ -149,7 +159,7 @@ if ( ${Git_Modified_LENGTH} GREATER 2 )
 endif ()
 
 #| Branch
-execute_process( COMMAND git rev-parse --abbrev-ref HEAD
+execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        OUTPUT_VARIABLE Git_Branch_INFO
        ERROR_QUIET
@@ -157,7 +167,7 @@ execute_process( COMMAND git rev-parse --abbrev-ref HEAD
 )
 
 #| Date
-execute_process( COMMAND git show -s --format=%ci
+execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%ci
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        OUTPUT_VARIABLE Git_Date_INFO
        ERROR_QUIET
@@ -165,7 +175,7 @@ execute_process( COMMAND git show -s --format=%ci
 )
 
 #| Commit Author and Email
-execute_process( COMMAND git show -s --format="%cn <%ce>"
+execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format="%cn <%ce>"
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        OUTPUT_VARIABLE Git_Commit_Author
        ERROR_QUIET
@@ -173,7 +183,7 @@ execute_process( COMMAND git show -s --format="%cn <%ce>"
 )
 
 #| Commit Revision
-execute_process( COMMAND git show -s --format=%H
+execute_process( COMMAND ${GIT_EXECUTABLE} show -s --format=%H
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        OUTPUT_VARIABLE Git_Commit_Revision
        ERROR_QUIET
@@ -181,7 +191,7 @@ execute_process( COMMAND git show -s --format=%H
 )
 
 #| Origin URL
-execute_process( COMMAND git config --get remote.origin.url
+execute_process( COMMAND ${GIT_EXECUTABLE} config --get remote.origin.url
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
        OUTPUT_VARIABLE Git_Origin_URL
        ERROR_QUIET
@@ -234,84 +244,23 @@ ModuleCompatibility( ${DebugModulePath}  ${DebugModuleCompatibility}  )
 
 
 ###
-# CMake Module Checking
-#
-find_package( Git REQUIRED )
-
-
-###
-# Build Targets
-#
-
-#| Create the .ELF file
-set( TARGET_ELF ${TARGET}.elf )
-add_executable( ${TARGET_ELF} ${SRCS} )
-
-
-#| .ELF Properties
-set_target_properties( ${TARGET_ELF} PROPERTIES
-       LINK_FLAGS ${LINKER_FLAGS}
-       SUFFIX ""                               # XXX Force Windows to keep the .exe off
-)
-
-
-#| Convert the .ELF into a .HEX to load onto the Teensy
-set( TARGET_HEX ${TARGET}.hex )
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND ${CMAKE_OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
-       COMMENT "Creating iHex file to load:    ${TARGET_HEX}"
-)
-
-
-#| Generate the Extended .LSS
-set( TARGET_LSS ${TARGET}.lss )
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
-       COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
-)
-
-
-#| Generate the Symbol Table .SYM
-set( TARGET_SYM ${TARGET}.sym )
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
-       COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
-)
-
-
-#| Compiler Selection Record
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/writer compiler ${COMPILER_FAMILY}
-)
-
-
-
-###
-# Size Information
-#
-
-#| After Changes Size Information
-add_custom_target( SizeAfter ALL
-       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
-       COMMAND ${CMAKE_SOURCE_DIR}/Lib/CMake/sizeCalculator ${CMAKE_SIZE} ${FORMAT} ${TARGET_HEX} ${SIZE_FLASH} "Flash"
-       DEPENDS ${TARGET_ELF}
-       COMMENT "Chip usage for ${CHIP}"
-)
-
-
-
-###
-# Setup Loader Script and Program
+# ctag Generation
 #
 
+if( CTAGS_EXECUTABLE )
+       # Populate list of directories for ctags to parse
+       # NOTE: Doesn't support dots in the folder names...
+       foreach( filename ${SRCS} )
+               string( REGEX REPLACE "/[a-zA-Z0-9_-]+.c$" "" pathglob ${filename} )
+               file( GLOB filenames "${pathglob}/*.c" )
+               set( CTAG_PATHS ${CTAG_PATHS} ${filenames} )
+               file( GLOB filenames "${pathglob}/*.h" )
+               set( CTAG_PATHS ${CTAG_PATHS} ${filenames} )
+       endforeach()
 
-#| Provides the user with the correct teensy-loader-cli command for the built .HEX file
-#| Windows
-if( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-       configure_file( LoadFile/winload load NEWLINE_STYLE UNIX )
-#| Default
-else()
-       configure_file( LoadFile/load load NEWLINE_STYLE UNIX )
+       # Generate the ctags
+       execute_process( COMMAND ctags ${CTAG_PATHS}
+               WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+       )
 endif()
 
-