-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
79 lines (64 loc) · 2.86 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Set minimum required version of CMake
cmake_minimum_required(VERSION 3.12)
# Include build functions from Pico SDK
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
# Set name of project (as PROJECT_NAME) and C/C standards
project(settings C CXX ASM)
set(CMAKE_C_STANDARD 11)
# Include the Pico SDK (specific for Raspberry Pi Pico projects)
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
# if PICOTOOL_OVERRIDE_DIR system environment variable is set,
# then use that as the folder for the picotool executable
if (DEFINED ENV{PICOTOOL_OVERRIDE_DIR})
message("PICOTOOL_OVERRIDE_DIR env var is set to '$ENV{PICOTOOL_OVERRIDE_DIR}'")
add_executable(picotool IMPORTED GLOBAL)
set_property(TARGET picotool PROPERTY IMPORTED_LOCATION $ENV{PICOTOOL_OVERRIDE_DIR}/picotool)
# check the picotool version:
execute_process(COMMAND $ENV{PICOTOOL_OVERRIDE_DIR}/picotool version
OUTPUT_VARIABLE PICOTOOL_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "^picotool v${picotool_VERSION_REQUIRED}" PICOTOOL_VERSION_MATCH ${PICOTOOL_VERSION})
if (NOT PICOTOOL_VERSION_MATCH)
message("picotool version response was: ${PICOTOOL_VERSION}")
message(FATAL_ERROR "PICOTOOL_OVERRIDE_DIR is set to '$ENV{PICOTOOL_OVERRIDE_DIR}', but the version of picotool found is not ${picotool_VERSION_REQUIRED}")
endif()
endif ()
# Initialize the SDK
pico_sdk_init()
# Add subdirectories
add_subdirectory(src) # Source directory containing the core library or settings
add_subdirectory(examples) # Example programs that demonstrate usage of the src files
# Optionally, set some global properties or flags for the whole project
set(CMAKE_C_STANDARD 11)
# Global flags (optimization, warnings, etc.)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall")
# Enable clang-tidy (you need to have clang-tidy installed on your system)
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
if(CLANG_TIDY_EXE)
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_EXE}")
message(STATUS "Found clang-tidy: ${CLANG_TIDY_EXE}")
else()
message(WARNING "clang-tidy not found, skipping linting")
endif()
# Find clang-format executable
find_program(CLANG_FORMAT_BIN NAMES clang-format)
if(CLANG_FORMAT_BIN)
message(STATUS "Found clang-format: ${CLANG_FORMAT_BIN}")
# Add a custom target to run clang-format on all source files
file(GLOB_RECURSE ALL_CXX_SOURCE_FILES
"${CMAKE_SOURCE_DIR}/src/*.c"
"${CMAKE_SOURCE_DIR}/src/*.h"
"${CMAKE_SOURCE_DIR}/examples/*.c"
)
add_custom_target(clang-format
COMMAND ${CLANG_FORMAT_BIN}
-i
-style=file
${ALL_CXX_SOURCE_FILES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Running clang-format on the source code..."
VERBATIM
)
else()
message(WARNING "clang-format not found!")
endif()