2011-09-29 06:25:51 +00:00
|
|
|
###| CMAKE Kiibohd Controller Source Configurator |###
|
|
|
|
#
|
2016-07-23 23:16:16 +00:00
|
|
|
# Written by Jacob Alexander in 2011-2016 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
|
|
|
###
|
2016-07-23 23:16:16 +00:00
|
|
|
# CMake Build Env Checking
|
2014-08-15 17:42:12 +00:00
|
|
|
#
|
|
|
|
|
2016-07-23 23:16:16 +00:00
|
|
|
include( buildinfo )
|
2014-08-15 17:42:12 +00:00
|
|
|
|
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
|
|
|
|
#
|
|
|
|
|
2016-07-23 23:16:16 +00:00
|
|
|
find_package ( Ctags ) # Optional
|
|
|
|
|
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
|
|
|
|