Blame view

CMakeLists.txt 4.67 KB
c23204b0   Antonio Carlos Domínguez Brito   CMake common stuf...
1
# CMakeLists.txt file for building project soft_uart
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
2
3
cmake_minimum_required(VERSION 2.8)

c23204b0   Antonio Carlos Domínguez Brito   CMake common stuf...
4
5
include(cmake/build_library.cmake)

ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
6
7
8
set(PORT /dev/ttyACM0 CACHE STRING "uploading serial port")
set(IS_NATIVE_PORT true CACHE STRING "is it the native port? (true), or not? (false)")

c23204b0   Antonio Carlos Domínguez Brito   CMake common stuf...
9
set(CMAKE_TOOLCHAIN_FILE cmake/arduino_due_toolchain.cmake)
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
10
11
12

project(soft_uart C CXX)

c23204b0   Antonio Carlos Domínguez Brito   CMake common stuf...
13
14
15
16
# building Arduino Standard Library
build_library(
  arduino_due_std_lib 
  SRC_PATHS 
5f743fcb   Antonio Carlos Domínguez Brito   CMake files chang...
17
18
19
20
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/cores/arduino
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/cores/arduino/USB
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/variants/arduino_due_x
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/libraries/SPI
c23204b0   Antonio Carlos Domínguez Brito   CMake common stuf...
21
  INCLUDE_PATHS 
5f743fcb   Antonio Carlos Domínguez Brito   CMake files chang...
22
23
24
25
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/cores/arduino
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/cores/arduino/USB
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/variants/arduino_due_x
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/libraries/SPI
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
26
27
)

ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# checking environment variable ARDUINO_IDE_LIBRARY_PATH
if( 
  NOT (DEFINED ENV{ARDUINO_IDE_LIBRARY_PATH})
  OR 
  ($ENV{ARDUINO_IDE_LIBRARY_PATH} EQUAL "")
)

  message(FATAL_ERROR "[ERROR] Environment variable ARDUINO_IDE_LIBRARY_PATH not set!")

else()

  message(STATUS "Environment variable ARDUINO_IDE_LIBRARY_PATH: $ENV{ARDUINO_IDE_LIBRARY_PATH}")

endif()

c23204b0   Antonio Carlos Domínguez Brito   CMake common stuf...
43
44
45
46
47
# build soft_uart library 
build_library(
  soft_uart_lib  
  SRC_PATHS
    $ENV{ARDUINO_IDE_LIBRARY_PATH}/libraries/soft_uart
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
48
49
)

ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
50
51
52
53
54
55
#####################################################################
# soft_uart examples: begin 
#####################################################################

set(
  SOFT_UART_EXAMPLES
f8d7c948   Antonio Carlos Domínguez Brito   project adapte to...
56
  basic_test
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
57
58
59
60
  soft_uart_serial_test
  soft_uart_serial_test_auto
  soft_uart_serial_test_half_duplex
  soft_uart_serial_test_half_duplex_9O2
f8d7c948   Antonio Carlos Domínguez Brito   project adapte to...
61
  soft_uart_serial_test_half_duplex_char
db903a7f   Antonio Carlos Domínguez Brito   New version 3.0.
62
  echo_test
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
63
64
65
66
)

foreach(src_example ${SOFT_UART_EXAMPLES})
  configure_file(
bbdd578c   Antonio Carlos Domínguez Brito   porting soft_uart...
67
    ${PROJECT_SOURCE_DIR}/examples/due/${src_example}/${src_example}.ino
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
68
69
70
71
72
73
    ${src_example}.cpp
    COPYONLY
  )
  add_executable(
    ${src_example}.cpp.elf 
    ${src_example}.cpp
5f743fcb   Antonio Carlos Domínguez Brito   CMake files chang...
74
    $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/cores/arduino/syscalls_sam3.c
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  )
  target_compile_options(
    ${src_example}.cpp.elf PUBLIC 
    -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -std=gnu++11 -mthumb
  )
  
  target_compile_definitions(
    ${src_example}.cpp.elf PUBLIC
    -Dprintf=iprintf -DF_CPU=84000000L -DARDUINO=10605 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due"
  )
  
  target_include_directories(
    ${src_example}.cpp.elf PUBLIC
    $ENV{ARDUINO_IDE_LIBRARY_PATH}/libraries/soft_uart
  )
ab854abc   Antonio Carlos Domínguez Brito   fixed a compiler ...
90

ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
91
92
  target_link_libraries(
    ${src_example}.cpp.elf
5f743fcb   Antonio Carlos Domínguez Brito   CMake files chang...
93
    -Os -Wl,--gc-sections -mcpu=cortex-m3 -T$ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/variants/arduino_due_x/linker_scripts/gcc/flash.ld -Wl,-Map,${src_example}.cpp.map -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group arduino_due_std_lib soft_uart_lib $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/$ENV{ARDUINO_DUE_VERSION}/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a -Wl,--end-group -lm 
ccabe406   Antonio Carlos Domínguez Brito   CMake compiling s...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  )
  
  # bin
  add_custom_command(
    OUTPUT
      ${src_example}.cpp.bin 
    COMMAND 
      ${DUE_OBJCOPY} -O binary ${src_example}.cpp.elf ${src_example}.cpp.bin 
    DEPENDS
      ${src_example}.cpp.elf
  )
  
  # size
  add_custom_command(
    OUTPUT
      ${src_example}.cpp.size
    COMMAND
      ${DUE_SIZE_TOOL} -A ${src_example}.cpp.elf > ${src_example}.cpp.size
    DEPENDS
      ${src_example}.cpp.elf
  )
  
  # target for the custom commands
  add_custom_target(
    ${src_example}  
    ALL
    DEPENDS
      ${src_example}.cpp.size ${src_example}.cpp.bin 
  )
  
  # upload - with avrdude
  get_filename_component(PORT_NAME ${PORT} NAME)
  add_custom_target(
    upload_${src_example} 
    COMMAND
      stty -F ${PORT} 1200\; cat ${CMAKE_CURRENT_LIST_DIR}/dummy > ${PORT}\; sleep 3 
    COMMAND
      ${DUE_BOSSAC} -i -d --port=${PORT_NAME} -U ${IS_NATIVE_PORT} -e -w -v -b ${src_example}.cpp.bin -R 
    DEPENDS ${src_example}.cpp.bin
    COMMENT 
      "Uploading ${src_example}.cpp.bin to uC ATSAM3X8E through ${PORT}" 
  ) 
  
endforeach(src_example)