Skip to content

Commit 1cb1953

Browse files
authored
Merge pull request #164 from sparkfun/develop
Move the cmake refactor work into main
2 parents 3d4e875 + 14db4f7 commit 1cb1953

File tree

243 files changed

+421
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+421
-1
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# $id$ FLUX_SDK_PATH/CMakeLists.txt
2+
#
3+
4+
# we are building a "fake" Arduino library so we can compile the code using arduino-cli. This
5+
# requires a library.properties file in the root of the project. This file i
6+
configure_file(library.properties ${PROJECT_FLUX_DIRECTORY} COPYONLY)
7+
8+
# Now just cascade down to src
9+
10+
add_subdirectory(src)

external/flux_sdk_import.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ##################################################################################################
2+
# include/import file for the flux-sdk cmake system
3+
# ##################################################################################################
4+
5+
# we are just using this as a manifest system, so doing the best to bypass the compiler detection
6+
set(CMAKE_C_COMPILER_FORCED TRUE)
7+
set(CMAKE_CXX_COMPILER_FORCED TRUE)
8+
9+
# Where is the flux-sdk directory? This should be in some "include file from the sdk"
10+
11+
if (NOT FLUX_SDK_PATH)
12+
if (DEFINED ENV{FLUX_SDK_PATH})
13+
set(FLUX_SDK_PATH $ENV{FLUX_SDK_PATH})
14+
elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../flux-sdk)
15+
set(FLUX_SDK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../flux-sdk)
16+
endif ()
17+
endif ()
18+
19+
# crawl the flux-sdk directory and add all the subdirectories
20+
include(${FLUX_SDK_PATH}/flux_sdk_init.cmake)

flux_sdk_init.cmake

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# @file: flux_sdk_init.cmake
2+
3+
# ##################################################################################################
4+
# flux_sdk_version()
5+
include(${CMAKE_CURRENT_LIST_DIR}/flux_sdk_version.cmake)
6+
7+
# ##################################################################################################
8+
# flux_sdk_set_platform()
9+
#
10+
# Set the platform for the SDK - what hardware stack is this used on?
11+
#
12+
macro (flux_sdk_set_platform platform)
13+
set(FLUX_SDK_PLATFORM ${platform})
14+
message("Platform:\t${FLUX_SDK_PLATFORM}")
15+
endmacro ()
16+
17+
# ##################################################################################################
18+
# flux_sdk_set_project_directory()
19+
#
20+
macro (flux_sdk_set_project_directory project_directory)
21+
22+
set(PROJECT_FLUX_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${project_directory}/SparkFun_Flux)
23+
24+
if (NOT EXISTS ${PROJECT_FLUX_DIRECTORY})
25+
message(STATUS "Creating directory: ${PROJECT_FLUX_DIRECTORY}")
26+
file(MAKE_DIRECTORY ${PROJECT_FLUX_DIRECTORY})
27+
endif ()
28+
if (NOT EXISTS ${PROJECT_FLUX_DIRECTORY}/src)
29+
file(MAKE_DIRECTORY ${PROJECT_FLUX_DIRECTORY}/src)
30+
endif ()
31+
if (NOT EXISTS ${PROJECT_FLUX_DIRECTORY}/src/Flux)
32+
file(MAKE_DIRECTORY ${PROJECT_FLUX_DIRECTORY}/src/Flux)
33+
endif ()
34+
35+
endmacro ()
36+
# ##################################################################################################
37+
# flux_sdk_add_module()
38+
#
39+
# macro to add "modules" to our list of modules to add to the build
40+
macro (flux_sdk_add_module)
41+
set(list_var "${ARGN}")
42+
foreach (arg IN LISTS list_var)
43+
list(APPEND FLUX_MODULES_TO_ADD ${arg})
44+
endforeach ()
45+
endmacro ()
46+
47+
function (flux_sdk_get_directory_name result_name)
48+
get_filename_component(THIS_MODULE ${CMAKE_CURRENT_SOURCE_DIR} NAME)
49+
set(${result_name}
50+
${THIS_MODULE}
51+
PARENT_SCOPE)
52+
endfunction ()
53+
54+
# ##################################################################################################
55+
# flux_sdk_add_source_files()
56+
#
57+
# Macro to add a file to our build system file list
58+
macro (flux_sdk_add_source_files)
59+
set(list_var "${ARGN}")
60+
foreach (arg IN LISTS list_var)
61+
configure_file(${arg} ${PROJECT_FLUX_DIRECTORY}/src/Flux COPYONLY)
62+
endforeach ()
63+
endmacro ()
64+
65+
# ##################################################################################################
66+
# flux_sdk_is_module_enabled()
67+
#
68+
# Define a function that will check if a module is enabled in the list of enabled modules
69+
70+
function (flux_sdk_is_module_enabled module_name result)
71+
if (${module_name} IN_LIST FLUX_MODULES_TO_ADD)
72+
set(${result}
73+
TRUE
74+
PARENT_SCOPE)
75+
else ()
76+
set(${result}
77+
FALSE
78+
PARENT_SCOPE)
79+
endif ()
80+
endfunction ()
81+
82+
# ##################################################################################################
83+
# flux_sdk_process_subdirectories()
84+
#
85+
# Define a function that will cacade down subdirectories if that directory is a module desired, and
86+
# has a CMakeLists.txt file.
87+
#
88+
# Note: If the <directory>_all_modules flag is set, then all submodules of that directory will be
89+
# processed
90+
91+
function (flux_sdk_process_subdirectories)
92+
93+
# get our place in the SDK - print a value
94+
file(RELATIVE_PATH local_path ${FLUX_SDK_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
95+
message("Processing:\t\$FLUX_SDK/${local_path}")
96+
97+
# Get the name of the current directory - basename. We use this to build our "all submodules"
98+
# flag for this directory
99+
get_filename_component(CurrentDir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
100+
set(all_modules_flag "${CurrentDir}_all_modules")
101+
102+
# is the flag set?
103+
flux_sdk_is_module_enabled(${all_modules_flag} process_all_submodules)
104+
105+
# is everything enabled?
106+
flux_sdk_is_module_enabled(flux_all_modules process_all_modules)
107+
108+
message("Module flag:\t${all_modules_flag} = ${process_all_submodules}")
109+
110+
# are we loading all submodules?
111+
if (process_all_submodules OR process_all_modules)
112+
set(load_all_modules TRUE)
113+
endif ()
114+
115+
# Get all the children of this directory
116+
file(
117+
GLOB children
118+
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
119+
${CMAKE_CURRENT_SOURCE_DIR}/*)
120+
121+
# Iterate over all the children
122+
foreach (child ${children})
123+
124+
# Sanity check
125+
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child}
126+
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${child}/CMakeLists.txt)
127+
128+
# add this module - in list, or all devices flag set
129+
if (load_all_modules OR ${child} IN_LIST FLUX_MODULES_TO_ADD)
130+
message(STATUS "Adding: ${child}")
131+
add_subdirectory(${child})
132+
endif ()
133+
endif ()
134+
endforeach ()
135+
message("")
136+
endfunction ()
137+
138+
# ##################################################################################################
139+
# flux_sdk_init()
140+
#
141+
# Called to start the SDK build process. This should be called after the flux_sdk import cmake file
142+
# is loaded (of course)
143+
macro (flux_sdk_init)
144+
if (NOT CMAKE_PROJECT_NAME)
145+
message(WARNING "flux_sdk_init() should be called after the project is created")
146+
endif ()
147+
148+
# write some info!
149+
message("\n-----------------------------------------------------")
150+
message("SparkFun Flux SDK - Version: ${FLUX_SDK_VERSION}")
151+
message("-----------------------------------------------------\n")
152+
message("SDK Path:\t${FLUX_SDK_PATH}")
153+
message("Project Name:\t${CMAKE_PROJECT_NAME}")
154+
message("Destination:\t${PROJECT_FLUX_DIRECTORY}")
155+
message("")
156+
157+
# is everything enabled?
158+
flux_sdk_is_module_enabled(flux_all_modules process_all_modules)
159+
message("Module flag:\tflux_all_modules = ${process_all_modules}")
160+
161+
if (NOT DEFINED FLUX_SDK_PLATFORM)
162+
message(
163+
FATAL_ERROR
164+
"No platform specified. Set the target platform using `flux_sdk_set_platform()` in your projects CMakeLists.txt file"
165+
)
166+
endif ()
167+
message("Platform:\t${FLUX_SDK_PLATFORM}")
168+
169+
string(TIMESTAMP COMPILE_TIME "%Y-%m-%d %H:%M:%S")
170+
message("Build Time:\t${COMPILE_TIME}")
171+
message("")
172+
173+
# load the root directory of the SDK
174+
add_subdirectory(${FLUX_SDK_PATH} flux-sdk)
175+
176+
endmacro ()

flux_sdk_version.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# define a version for the SDK
2+
3+
set(FLUX_SDK_VERSION_MAJOR 1)
4+
set(FLUX_SDK_VERSION_MINOR 3)
5+
set(FLUX_SDK_VERSION_PATCH 0)
6+
set(FLUX_SDK_VERSION_TITLE "In Development")
7+
set(FLUX_SDK_VERSION
8+
"${FLUX_SDK_VERSION_MAJOR}.${FLUX_SDK_VERSION_MINOR}.${FLUX_SDK_VERSION_PATCH} - ${FLUX_SDK_VERSION_TITLE}"
9+
)

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# just add our subdirectories -- recurse down the tree
2+
add_subdirectory(core)
3+
add_subdirectory(device)
4+
add_subdirectory(iot)
5+
add_subdirectory(net)
6+
add_subdirectory(platform)

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Process all sub-modules
2+
flux_sdk_process_subdirectories()

src/core/flux_base/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Add the source files for this directory
2+
flux_sdk_add_source_files(
3+
flxBusI2C.cpp
4+
flxBusI2C.h
5+
flxBusSPI.cpp
6+
flxBusSPI.h
7+
flxCore.cpp
8+
flxCore.h
9+
flxCoreDevice.cpp
10+
flxCoreDevice.h
11+
flxCoreEvent.h
12+
flxCoreEvent.cpp
13+
flxCoreEventID.h
14+
flxCoreInterface.h
15+
flxCoreJobs.cpp
16+
flxCoreJobs.h
17+
flxCoreLog.cpp
18+
flxCoreLog.h
19+
flxCoreMsg.cpp
20+
flxCoreMsg.h
21+
flxCoreParam.h
22+
flxCoreProps.h
23+
flxCoreTypes.h
24+
flxDevice.h
25+
flxFlux.h
26+
flxSerial.cpp
27+
flxSerial.h
28+
flxTimer.h
29+
flxUtils.cpp
30+
flxUtils.h
31+
spSpark.cpp)
32+
33+
# the flux include file is special - its our hook for the Arduino "library" being created
34+
configure_file(Flux.h ${PROJECT_FLUX_DIRECTORY}/src COPYONLY)

src/Flux.h renamed to src/core/flux_base/Flux.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818

1919
#include "Flux/flxCore.h"
2020
#include "Flux/flxDevice.h"
21-
2221
#include "Flux/flxFlux.h"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)