2011-09-29 06:25:51 +00:00
|
|
|
###| CMAKE Kiibohd Controller Source Configurator |###
|
|
|
|
#
|
2015-03-01 06:13:17 +00:00
|
|
|
# Written by Jacob Alexander in 2011-2015 for the Kiibohd Controller
|
2011-09-29 06:25:51 +00:00
|
|
|
#
|
|
|
|
# Released into the Public Domain
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
|
2014-06-28 20:48:49 +00:00
|
|
|
###
|
|
|
|
# CMake Custom Modules Path
|
|
|
|
#
|
|
|
|
|
|
|
|
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/Lib/CMake/" )
|
|
|
|
|
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2013-01-15 02:31:50 +00:00
|
|
|
###
|
|
|
|
# Module Overrides (Used in the buildall.bash script)
|
|
|
|
#
|
2013-02-02 02:19:31 +00:00
|
|
|
if ( ( DEFINED ScanModuleOverride ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
|
2013-01-15 02:31:50 +00:00
|
|
|
set( ScanModule ${ScanModuleOverride} )
|
2013-02-02 02:19:31 +00:00
|
|
|
endif ()
|
2013-01-15 02:31:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-26 01:53:48 +00:00
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
###
|
|
|
|
# Path Setup
|
2014-01-20 00:40:36 +00:00
|
|
|
#
|
2014-03-22 21:32:06 +00:00
|
|
|
set( ScanModulePath "Scan/${ScanModule}" )
|
|
|
|
set( MacroModulePath "Macro/${MacroModule}" )
|
2014-01-20 00:40:36 +00:00
|
|
|
set( OutputModulePath "Output/${OutputModule}" )
|
2014-03-22 21:32:06 +00:00
|
|
|
set( DebugModulePath "Debug/${DebugModule}" )
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2011-09-29 22:30:24 +00:00
|
|
|
#| Top-level directory adjustment
|
2013-01-26 09:34:33 +00:00
|
|
|
set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )
|
2011-09-29 22:30:24 +00:00
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
|
2013-01-30 23:13:49 +00:00
|
|
|
###
|
|
|
|
# Module Check Function
|
|
|
|
#
|
|
|
|
|
2015-01-26 01:53:48 +00:00
|
|
|
function ( ModuleCompatibility ModulePath )
|
|
|
|
foreach ( mod_var ${ARGN} )
|
2013-01-30 23:13:49 +00:00
|
|
|
if ( ${mod_var} STREQUAL ${COMPILER_FAMILY} )
|
|
|
|
# Module found, no need to scan further
|
|
|
|
return()
|
2013-02-02 04:35:12 +00:00
|
|
|
endif ()
|
2015-01-26 01:53:48 +00:00
|
|
|
endforeach ()
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2015-01-26 01:53:48 +00:00
|
|
|
message ( FATAL_ERROR "${ModulePath} does not support the ${COMPILER_FAMILY} family..." )
|
|
|
|
endfunction ()
|
2011-09-29 22:30:24 +00:00
|
|
|
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Module Processing
|
|
|
|
#
|
|
|
|
|
|
|
|
#| Go through lists of sources and append paths
|
|
|
|
#| Usage:
|
|
|
|
#| PathPrepend( OutputListOfSources <Prepend Path> <InputListOfSources> )
|
2015-01-26 01:53:48 +00:00
|
|
|
macro ( PathPrepend Output SourcesPath )
|
|
|
|
unset ( tmpSource )
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
# Loop through items
|
2015-01-26 01:53:48 +00:00
|
|
|
foreach ( item ${ARGN} )
|
2011-11-13 10:04:44 +00:00
|
|
|
# Set the path
|
2015-01-26 01:53:48 +00:00
|
|
|
set ( tmpSource ${tmpSource} "${SourcesPath}/${item}" )
|
|
|
|
endforeach ()
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
# Finalize by writing the new list back over the old one
|
2015-01-26 01:53:48 +00:00
|
|
|
set ( ${Output} ${tmpSource} )
|
|
|
|
endmacro ()
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-26 01:53:48 +00:00
|
|
|
###
|
|
|
|
# Add Module Macro
|
|
|
|
#
|
|
|
|
# Optional Arg 1: Main Module Check, set to True/1 if adding a main module
|
|
|
|
|
|
|
|
function ( AddModule ModuleType ModuleName )
|
|
|
|
# Module path
|
|
|
|
set ( ModulePath ${ModuleType}/${ModuleName} )
|
|
|
|
set ( ModuleFullPath ${HEAD_DIR}/${ModuleType}/${ModuleName} )
|
|
|
|
|
|
|
|
# Include setup.cmake file
|
|
|
|
include ( ${ModuleFullPath}/setup.cmake )
|
|
|
|
|
|
|
|
# Check if this is a main module add
|
|
|
|
foreach ( extraArg ${ARGN} )
|
|
|
|
# Make sure this isn't a submodule
|
|
|
|
if ( DEFINED SubModule )
|
|
|
|
message ( FATAL_ERROR
|
|
|
|
"The '${ModuleName}' module is not a stand-alone module, and requires further setup."
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
# PathPrepend to give proper paths to each of the source files
|
|
|
|
PathPrepend ( Module_SRCS ${ModulePath} ${Module_SRCS} )
|
|
|
|
|
|
|
|
# Check the current scope to see if a sub-module added some source files
|
|
|
|
# Append each of the sources to each type of module srcs list
|
2015-03-01 06:13:17 +00:00
|
|
|
set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} ${Module_SRCS} )
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2015-01-26 01:53:48 +00:00
|
|
|
# Add .h files
|
|
|
|
add_definitions ( -I${ModuleFullPath} )
|
|
|
|
|
|
|
|
# Check module compatibility
|
|
|
|
ModuleCompatibility( ${ModulePath} ${ModuleCompatibility} )
|
|
|
|
|
|
|
|
# Check if this is a main module add
|
|
|
|
foreach ( extraArg ${ARGN} )
|
|
|
|
# Display detected source files
|
|
|
|
if ( NOT DEFINED SubModule )
|
|
|
|
message ( STATUS "Detected ${ModuleType} Module Source Files:" )
|
|
|
|
message ( "${${ModuleType}_SRCS}" )
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2015-03-01 06:13:17 +00:00
|
|
|
# Check for any capabilities.kll files in the Module
|
|
|
|
set ( kll_capabilities_file "${ModuleFullPath}/capabilities.kll" )
|
|
|
|
if ( EXISTS ${kll_capabilities_file} )
|
|
|
|
# Add the kll file and any submodule kll files to the running list
|
|
|
|
set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} ${kll_capabilities_file} )
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
# Finally, add the sources and kll files to the parent scope (i.e. return)
|
2015-01-26 01:53:48 +00:00
|
|
|
set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} PARENT_SCOPE )
|
2015-03-01 06:13:17 +00:00
|
|
|
set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} PARENT_SCOPE )
|
2015-01-26 01:53:48 +00:00
|
|
|
endfunction ()
|
2011-09-29 06:25:51 +00:00
|
|
|
|
|
|
|
|
2015-01-26 01:53:48 +00:00
|
|
|
#| Add main modules
|
|
|
|
AddModule ( Scan ${ScanModule} 1 )
|
|
|
|
AddModule ( Macro ${MacroModule} 1 )
|
|
|
|
AddModule ( Output ${OutputModule} 1 )
|
|
|
|
AddModule ( Debug ${DebugModule} 1 )
|
2011-09-29 06:25:51 +00:00
|
|
|
|
2013-02-02 01:02:55 +00:00
|
|
|
|
|
|
|
|
2014-08-15 17:42:12 +00:00
|
|
|
###
|
|
|
|
# CMake Module Checking
|
|
|
|
#
|
2015-01-26 01:53:48 +00:00
|
|
|
find_package ( Git REQUIRED )
|
|
|
|
find_package ( Ctags ) # Optional
|
2014-08-15 17:42:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-02 01:02:55 +00:00
|
|
|
###
|
|
|
|
# Generate USB Defines
|
|
|
|
#
|
|
|
|
|
|
|
|
#| Manufacturer name
|
2015-03-01 07:50:13 +00:00
|
|
|
set ( MANUFACTURER "Kiibohd" )
|
2013-02-02 01:02:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
#| Serial Number
|
|
|
|
#| Attempt to call Git to get the branch, last commit date, and whether code modified since last commit
|
|
|
|
|
|
|
|
#| Modified
|
2013-02-02 04:35:12 +00:00
|
|
|
#| Takes a bit of work to extract the "M " using CMake, and not using it if there are no modifications
|
2015-03-01 07:50:13 +00:00
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} status -s -uno --porcelain
|
2013-02-02 01:02:55 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Modified_INFO
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2015-03-01 07:50:13 +00:00
|
|
|
string ( LENGTH "${Git_Modified_INFO}" Git_Modified_LENGTH )
|
|
|
|
set ( Git_Modified_Status "Clean" )
|
2013-02-02 01:02:55 +00:00
|
|
|
if ( ${Git_Modified_LENGTH} GREATER 2 )
|
2015-03-01 07:50:13 +00:00
|
|
|
string ( SUBSTRING "${Git_Modified_INFO}" 1 2 Git_Modified_Flag_INFO )
|
|
|
|
set ( Git_Modified_Status "Dirty" )
|
2013-02-02 02:19:31 +00:00
|
|
|
endif ()
|
2013-02-02 01:02:55 +00:00
|
|
|
|
2015-03-01 07:50:13 +00:00
|
|
|
#| List of modified files
|
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Modified_Files
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
string ( REGEX REPLACE "\n" "\\\\r\\\\n\\\\t" Git_Modified_Files "${Git_Modified_Files}" )
|
|
|
|
set ( Git_Modified_Files "\\r\\n\\t${Git_Modified_Files}" )
|
|
|
|
|
2013-02-02 01:02:55 +00:00
|
|
|
#| Branch
|
2014-09-14 22:51:36 +00:00
|
|
|
execute_process( COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
2013-02-02 01:02:55 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Branch_INFO
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
#| Date
|
2015-03-01 07:50:13 +00:00
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} show -s --format=%ci
|
2013-02-02 01:02:55 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Date_INFO
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2014-01-23 10:01:12 +00:00
|
|
|
#| Commit Author and Email
|
2015-03-01 07:50:13 +00:00
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} show -s --format="%cn <%ce>"
|
2014-01-23 10:01:12 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Commit_Author
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
#| Commit Revision
|
2015-03-01 07:50:13 +00:00
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} show -s --format=%H
|
2014-01-23 10:01:12 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Commit_Revision
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
#| Origin URL
|
2015-03-01 07:50:13 +00:00
|
|
|
execute_process ( COMMAND ${GIT_EXECUTABLE} config --get remote.origin.url
|
2014-01-23 10:01:12 +00:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE Git_Origin_URL
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2014-04-10 03:06:19 +00:00
|
|
|
#| Build Date
|
2015-03-01 07:50:13 +00:00
|
|
|
execute_process ( COMMAND "date" "+%Y-%m-%d %T %z"
|
2014-04-13 03:52:32 +00:00
|
|
|
OUTPUT_VARIABLE Build_Date
|
|
|
|
ERROR_QUIET
|
2014-04-10 03:06:19 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2013-02-02 01:02:55 +00:00
|
|
|
|
2014-04-10 03:06:19 +00:00
|
|
|
#| Last Commit Date
|
2015-03-01 07:50:13 +00:00
|
|
|
set ( GitLastCommitDate "${Git_Modified_Status} ${Git_Branch_INFO} - ${Git_Date_INFO}" )
|
2013-02-02 01:02:55 +00:00
|
|
|
|
|
|
|
#| Uses CMake variables to include as defines
|
|
|
|
#| Primarily for USB configuration
|
2015-03-01 07:50:13 +00:00
|
|
|
configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/Lib/_buildvars.h buildvars.h )
|
2013-02-02 01:02:55 +00:00
|
|
|
|
2014-04-19 05:57:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
# Source Defines
|
|
|
|
#
|
2015-03-01 07:50:13 +00:00
|
|
|
set ( SRCS
|
2014-04-19 05:57:14 +00:00
|
|
|
${MAIN_SRCS}
|
|
|
|
${COMPILER_SRCS}
|
2015-01-26 01:53:48 +00:00
|
|
|
${Scan_SRCS}
|
|
|
|
${Macro_SRCS}
|
|
|
|
${Output_SRCS}
|
|
|
|
${Debug_SRCS}
|
2014-04-19 05:57:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#| Directories to include by default
|
2015-03-01 07:50:13 +00:00
|
|
|
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
|
2014-04-19 05:57:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-28 20:48:49 +00:00
|
|
|
###
|
|
|
|
# ctag Generation
|
|
|
|
#
|
|
|
|
|
2015-03-01 07:50:13 +00:00
|
|
|
if ( CTAGS_EXECUTABLE )
|
2014-06-28 20:48:49 +00:00
|
|
|
# Populate list of directories for ctags to parse
|
|
|
|
# NOTE: Doesn't support dots in the folder names...
|
2015-03-01 07:50:13 +00:00
|
|
|
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 ()
|
2014-06-28 20:48:49 +00:00
|
|
|
|
|
|
|
# Generate the ctags
|
2015-10-15 07:16:36 +00:00
|
|
|
execute_process ( COMMAND ctags --fields=+l ${CTAG_PATHS}
|
2014-06-28 20:48:49 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
2015-03-01 07:50:13 +00:00
|
|
|
endif ()
|
2014-06-28 20:48:49 +00:00
|
|
|
|