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