CMakeLists.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. cmake_minimum_required(VERSION 3.15)
  2. include(cmake/Utilities.cmake)
  3. include(cmake/GetGitRevisionDescription.cmake)
  4. SET(PROJECT_VERSION_SUFFIX
  5. "<auto>"
  6. CACHE
  7. STRING
  8. "Full version suffix to be shown on the info screen in settings (e.g. full_version=4.0.3-BETA+1035.PR111.B4, suffix=-BETA+1035.PR111.B4). Defaults to '+<commit sha>.<dirty?>.<debug?>' if set to '<auto>'."
  9. )
  10. SET(PROJECT_VERSION_SUFFIX_SHORT
  11. "<auto>"
  12. CACHE
  13. STRING
  14. "Short version suffix to be shown on splash screen. Defaults to '+<BUILD_NUMBER>' if set to '<auto>'."
  15. )
  16. SET(BUILD_NUMBER
  17. ""
  18. CACHE STRING "Build number of the firmware. Resolved automatically if not specified."
  19. )
  20. INCLUDE(cmake/ProjectVersion.cmake)
  21. resolve_version_variables()
  22. SET(PROJECT_VERSION_FLAVOUR "" CACHE STRING "Firmware flavour to build - DEBUG, DEVEL, APLHA, BETA or RC")
  23. SET(PROJECT_VERSION_FLAVOUR_REVISION "" CACHE STRING "Firmware flavour version, e.g. 1 for RC1, etc")
  24. IF( NOT PROJECT_VERSION_FLAVOUR STREQUAL "")
  25. SET(PROJECT_VERSION "${PROJECT_VERSION}-${PROJECT_VERSION_FLAVOUR}")
  26. add_compile_definitions(FW_FLAVOR=${PROJECT_VERSION_FLAVOUR})
  27. IF( NOT PROJECT_VERSION_FLAVOUR_REVISION STREQUAL "")
  28. SET(PROJECT_VERSION "${PROJECT_VERSION}${PROJECT_VERSION_FLAVOUR_REVISION}")
  29. add_compile_definitions(FW_FLAVERSION=${PROJECT_VERSION_FLAVOUR_REVISION})
  30. ENDIF()
  31. ENDIF()
  32. # Inform user about the resolved settings
  33. MESSAGE(STATUS "Project version: ${PROJECT_VERSION}")
  34. MESSAGE(
  35. STATUS "Project version with short suffix: ${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX_SHORT}"
  36. )
  37. SET(FN_PREFIX "FW${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX_SHORT}")
  38. MESSAGE(WARNING "
  39. ***************** YOUR ATTENTION PLEASE *****************
  40. CMake support is experimental. There is no guarantee at this time. If you have problems you are encouraged to fall back to the tried-and-true methods.
  41. *********************** THANK YOU **********************
  42. We now return to your regularly scheduled Firmware Build."
  43. )
  44. OPTION(SECONDARY_LANGUAGES "Secondary language support in the firmware" ON)
  45. SET(MAIN_LANGUAGES cs de es fr it pl CACHE STRING "The list of 'main' languages to be included, in the correct order")
  46. SET(COMMUNITY_LANGUAGES nl ro hu hr sk sv no CACHE STRING "The list of community languages to be included, in the correct order")
  47. SET(SELECTED_LANGUAGES ${MAIN_LANGUAGES} ${COMMUNITY_LANGUAGES})
  48. get_dependency_directory(prusa3dboards PRUSA_BOARDS_DIR)
  49. project(Prusa-Firmware)
  50. add_subdirectory(lib)
  51. FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/config.h MAX_SIZE_LINE REGEX "^#define \+LANG_SIZE_RESERVED \+")
  52. STRING(REGEX MATCH "0x[0-9]+" MAX_SIZE_HEX "${MAX_SIZE_LINE}")
  53. math(EXPR LANG_MAX_SIZE "${MAX_SIZE_HEX}" OUTPUT_FORMAT DECIMAL)
  54. message("Language maximum size (from config.h): ${LANG_MAX_SIZE} bytes")
  55. set (LANG_BIN_MAX 249856) # Ditto, this in xflash_layout.h but needs invocation of the preprocessor... :-/
  56. get_recommended_gcc_version(RECOMMENDED_TOOLCHAIN_VERSION)
  57. if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL
  58. ${RECOMMENDED_TOOLCHAIN_VERSION}
  59. )
  60. message(WARNING "Recommended AVR toolchain is ${RECOMMENDED_TOOLCHAIN_VERSION}"
  61. ", but you have ${CMAKE_CXX_COMPILER_VERSION}"
  62. )
  63. elseif(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  64. message(
  65. WARNING
  66. "Recommended compiler for host tools and unittests is GCC, you have ${CMAKE_CXX_COMPILER_ID}."
  67. )
  68. endif()
  69. # append custom C/C++ flags
  70. if(CUSTOM_COMPILE_OPTIONS)
  71. string(REPLACE " " ";" CUSTOM_COMPILE_OPTIONS "${CUSTOM_COMPILE_OPTIONS}")
  72. add_compile_options(${CUSTOM_COMPILE_OPTIONS})
  73. endif()
  74. #
  75. # Global Compiler & Linker Configuration
  76. #
  77. # enable warnings
  78. add_compile_options(-Wall -Wextra -Wno-expansion-to-defined -Wsign-compare)
  79. # default standards for all targets
  80. set(CMAKE_C_STANDARD 11)
  81. set(CMAKE_CXX_STANDARD 17)
  82. # support _DEBUG macro (some code uses to recognize debug builds)
  83. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  84. add_compile_definitions(_DEBUG)
  85. endif()
  86. #
  87. # Firmware - get file lists.
  88. #
  89. SET(FW_SOURCES
  90. adc.cpp
  91. backlight.cpp
  92. BlinkM.cpp
  93. bootapp.c
  94. cardreader.cpp
  95. cmdqueue.cpp
  96. Configuration.cpp
  97. ConfigurationStore.cpp
  98. conv2str.cpp
  99. Dcodes.cpp
  100. eeprom.cpp
  101. fancheck.cpp
  102. Filament_sensor.cpp
  103. first_lay_cal.cpp
  104. heatbed_pwm.cpp
  105. la10compat.cpp
  106. language.c
  107. lcd.cpp
  108. Marlin_main.cpp
  109. MarlinSerial.cpp
  110. menu.cpp
  111. mesh_bed_calibration.cpp
  112. mesh_bed_leveling.cpp
  113. messages.cpp
  114. mmu2.cpp
  115. mmu2_crc.cpp
  116. mmu2_error_converter.cpp
  117. mmu2_fsensor.cpp
  118. mmu2_log.cpp
  119. mmu2_power.cpp
  120. mmu2_progress_converter.cpp
  121. mmu2_protocol.cpp
  122. mmu2_protocol_logic.cpp
  123. mmu2_reporting.cpp
  124. mmu2_serial.cpp
  125. motion_control.cpp
  126. optiboot_xflash.cpp
  127. pat9125.cpp
  128. planner.cpp
  129. Prusa_farm.cpp
  130. qr_solve.cpp
  131. rbuf.c
  132. Sd2Card.cpp
  133. SdBaseFile.cpp
  134. SdFatUtil.cpp
  135. SdFile.cpp
  136. SdVolume.cpp
  137. Servo.cpp
  138. sm4.c
  139. sound.cpp
  140. speed_lookuptable.cpp
  141. spi.c
  142. SpoolJoin.cpp
  143. stepper.cpp
  144. swi2c.c
  145. swspi.cpp
  146. Tcodes.cpp
  147. temperature.cpp
  148. timer02.c
  149. Timer.cpp
  150. tmc2130.cpp
  151. tone04.c
  152. twi.cpp
  153. uart2.c
  154. ultralcd.cpp
  155. util.cpp
  156. vector_3.cpp
  157. xflash.c
  158. xflash_dump.cpp
  159. xyzcal.cpp
  160. )
  161. list(TRANSFORM FW_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/)
  162. set(AVR_SOURCES
  163. wiring_digital.c
  164. WInterrupts.c
  165. wiring_pulse.c
  166. hooks.c
  167. wiring.c
  168. wiring_analog.c
  169. wiring_shift.c
  170. CDC.cpp
  171. PluggableUSB.cpp
  172. HardwareSerial.cpp
  173. HardwareSerial0.cpp
  174. HardwareSerial1.cpp
  175. HardwareSerial3.cpp
  176. IPAddress.cpp
  177. HardwareSerial2.cpp
  178. Print.cpp
  179. Stream.cpp
  180. Tone.cpp
  181. USBCore.cpp
  182. WMath.cpp
  183. WString.cpp
  184. abi.cpp
  185. main.cpp
  186. # new.cpp # What happened to this? it was removed in 1.0.5-1 to 1.0.5.2?
  187. )
  188. list(TRANSFORM AVR_SOURCES PREPEND ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/)
  189. #
  190. # Target configuration
  191. #
  192. if(CMAKE_CROSSCOMPILING)
  193. # Reproducible build support
  194. function(set_reproducible_sources source_list prefix)
  195. foreach(file IN LISTS ${source_list})
  196. get_filename_component(base ${file} NAME)
  197. set(target "${prefix}${base}")
  198. set_property(SOURCE ${file} APPEND PROPERTY COMPILE_OPTIONS "-frandom-seed=${target}.o")
  199. endforeach()
  200. endfunction()
  201. function(set_reproducible_target target)
  202. set_target_properties(${target} PROPERTIES STATIC_LIBRARY_OPTIONS "-D")
  203. endfunction()
  204. set_reproducible_sources(AVR_SOURCES "core/")
  205. add_link_options(-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=)
  206. add_link_options(-fdebug-prefix-map=${CMAKE_BINARY_DIR}=)
  207. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "8")
  208. add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=)
  209. endif()
  210. # TODO: get date from the last git commit to set as epoch
  211. set(ENV{SOURCE_DATE_EPOCH} 0)
  212. # default optimization flags
  213. set(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
  214. set(CMAKE_CXX_FLAGS_RELEASE "-Os -g -DNDEBUG")
  215. set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
  216. set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
  217. # mcu and target-related settings
  218. add_compile_options(-mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRUSA_EINSY_RAMBO -DARDUINO_ARCH_AVR)
  219. add_link_options(-mmcu=atmega2560 -Wl,-u,vfprintf -lprintf_flt -lm)
  220. # disable some C++ language features
  221. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>)
  222. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
  223. # disable exceptions
  224. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
  225. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables>)
  226. # split and gc sections
  227. add_compile_options(-ffunction-sections -fdata-sections)
  228. add_link_options(-Wl,--gc-sections)
  229. # LTO (with custom options)
  230. add_compile_options(-flto -fno-fat-lto-objects)
  231. add_link_options(-flto)
  232. # Create this target before we apply the GC options
  233. add_library(avr_core STATIC ${AVR_SOURCES})
  234. set_reproducible_target(avr_core)
  235. target_include_directories(avr_core PRIVATE
  236. ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/
  237. ${PRUSA_BOARDS_DIR}/variants/prusa_einsy_rambo/
  238. )
  239. endif()
  240. # Setup language resources:
  241. # file(GLOB LANG_VARIANTS RELATIVE ${PROJECT_SOURCE_DIR}/lang/po ${PROJECT_SOURCE_DIR}/lang/po/Firmware_??.po)
  242. # string(REPLACE "Firmware_" "" LANG_VARIANTS "${LANG_VARIANTS}")
  243. # string(REPLACE ".po" "" LANG_VARIANTS "${LANG_VARIANTS}")
  244. # list(SORT LANG_VARIANTS)
  245. # message("Languages found: ${LANG_VARIANTS}")
  246. # Meta target to build absolutely everything
  247. add_custom_target(ALL_FIRMWARE)
  248. add_custom_target(ALL_ENGLISH)
  249. add_custom_target(ALL_MULTILANG)
  250. add_dependencies(ALL_FIRMWARE ALL_ENGLISH ALL_MULTILANG)
  251. function(add_base_binary variant_name)
  252. add_executable(${variant_name} ${FW_SOURCES} ${FW_HEADERS} ${VARIANT_CFG_FILE})
  253. target_include_directories(${variant_name} PRIVATE
  254. ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/
  255. ${PRUSA_BOARDS_DIR}/variants/prusa_einsy_rambo/
  256. ${VARIANT_CFG_DIR} # Include the header for this variant.
  257. ${CMAKE_SOURCE_DIR}/Firmware
  258. )
  259. target_link_libraries(${variant_name} avr_core)
  260. # # configure linker script
  261. set(LINKER_SCRIPT ${PRUSA_BOARDS_DIR}/ldscripts/avr6.xn)
  262. target_link_options(${variant_name} PUBLIC -Wl,-T,${LINKER_SCRIPT})
  263. # limit the text section to 248K (256K - 8k reserved for the bootloader)
  264. target_link_options(${variant_name} PUBLIC -Wl,--defsym=__TEXT_REGION_LENGTH__=248K)
  265. # generate firmware.bin file
  266. objcopy(${variant_name} "ihex" ".hex")
  267. # produce ASM listing. Note we also specify the .map as a byproduct so it gets cleaned
  268. # because link_options doesn't have a "generated outputs" feature.
  269. add_custom_command(
  270. TARGET ${variant_name} POST_BUILD COMMAND ${CMAKE_OBJDUMP} -CSd ${variant_name} > ${variant_name}.asm
  271. BYPRODUCTS ${variant_name}.asm ${variant_name}.map
  272. )
  273. # inform about the firmware's size in terminal
  274. add_custom_command(
  275. TARGET ${variant_name} POST_BUILD COMMAND ${CMAKE_SIZE_UTIL} -C --mcu=atmega2560 ${variant_name}
  276. )
  277. report_size(${variant_name})
  278. # generate linker map file
  279. target_link_options(${variant_name} PUBLIC -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${variant_name}.map)
  280. target_compile_definitions(${variant_name} PRIVATE
  281. CMAKE_LANG_CONTROL
  282. )
  283. endfunction()
  284. function(fw_add_variant variant_name)
  285. # Set FW_SOURCES to be reproducible in this variant as it's set in a separate project
  286. set_reproducible_sources(FW_SOURCES "Firmware/")
  287. # Create the Configuration_Prusa.h for this variant so it can be #included.
  288. set(VARIANT_CFG_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
  289. set(VARIANT_CFG_FILE "${VARIANT_CFG_DIR}/Configuration_prusa.h")
  290. add_custom_command(OUTPUT ${VARIANT_CFG_FILE}
  291. COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Firmware/variants/${variant_name}.h ${VARIANT_CFG_FILE}
  292. COMMENT "Generating Configuration_prusa.h for ${variant_name}"
  293. BYPRODUCTS ${VARIANT_CFG_DIR}
  294. )
  295. STRING(REPLACE "1_75mm_" "" variant_name "${variant_name}")
  296. STRING(REPLACE "-E3Dv6full" "" variant_name "${variant_name}")
  297. SET(FW_EN "${variant_name}_EN-only")
  298. SET(FW_MULTI "${variant_name}_Multilang")
  299. add_base_binary(${FW_EN})
  300. # target_compile_options(${variant_name} PRIVATE) # turn this on for lolz -Wdouble-promotion)
  301. target_compile_definitions(${FW_EN} PUBLIC LANG_MODE=0)
  302. add_custom_command(
  303. TARGET ${FW_EN}
  304. POST_BUILD
  305. COMMAND ${CMAKE_OBJCOPY} -O ihex ${CMAKE_CURRENT_BINARY_DIR}/${FW_EN} ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_EN}.hex
  306. BYPRODUCTS ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_EN}.hex
  307. COMMENT "Generating ${variant_name} hex"
  308. )
  309. add_dependencies(ALL_ENGLISH "${FW_EN}")
  310. if (NOT SECONDARY_LANGUAGES)
  311. return() #Done, if no languages there's nothing else to do.
  312. else()
  313. add_base_binary(${FW_MULTI})
  314. target_compile_definitions(${FW_MULTI} PUBLIC LANG_MODE=1)
  315. endif()
  316. #Construct language map
  317. set(LANG_TMP_DIR ${CMAKE_BINARY_DIR}/${variant_name}/lang)
  318. set(LANG_MAP ${LANG_TMP_DIR}/${variant_name}_lang.map)
  319. set(LANG_FWBIN ${CMAKE_CURRENT_BINARY_DIR}/${variant_name}.bin)
  320. set(LANG_FINAL_BIN ${LANG_TMP_DIR}/${variant_name}_lang.bin)
  321. set(LANG_FINAL_HEX ${LANG_TMP_DIR}/${variant_name}_lang.hex)
  322. add_custom_command(OUTPUT ${LANG_FWBIN}
  323. COMMAND "${CMAKE_OBJCOPY}" -I ihex -O binary ${CMAKE_CURRENT_BINARY_DIR}/${variant_name}_Multilang.hex ${LANG_FWBIN}
  324. DEPENDS ${FW_MULTI}
  325. )
  326. add_custom_command(OUTPUT ${LANG_MAP}
  327. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-map.py "${FW_MULTI}" "${LANG_FWBIN}" > "${LANG_MAP}"
  328. DEPENDS ${LANG_FWBIN}
  329. )
  330. set(LANG_BINS "")
  331. foreach (LANG IN LISTS SELECTED_LANGUAGES)
  332. set(LANG_BIN ${LANG_TMP_DIR}/${variant_name}_${LANG}.bin)
  333. set(PO_FILE "${CMAKE_SOURCE_DIR}/lang/po/Firmware_${LANG}.po")
  334. add_custom_command(OUTPUT ${LANG_BIN}
  335. # COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lang/lang-check.py --no-warning --map "${LANG_MAP}" "${PO_FILE}"
  336. # COMMAND ${CMAKE_COMMAND} -E echo "Building lang_${LANG}.bin"
  337. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-build.py ${LANG_MAP} ${PO_FILE} ${LANG_BIN}
  338. # Check bin size:
  339. COMMAND ${CMAKE_COMMAND} -DLANG_MAX_SIZE=${LANG_MAX_SIZE}
  340. -DLANG_FILE=${LANG_BIN}
  341. -P ${PROJECT_CMAKE_DIR}/Check_lang_size.cmake
  342. DEPENDS ${LANG_MAP}
  343. COMMENT "Generating ${variant_name}_${LANG}.bin from .po"
  344. )
  345. LIST(APPEND LANG_BINS ${LANG_BIN})
  346. endforeach()
  347. string(FIND ${variant_name} "MK3" HAS_XFLASH)
  348. if (${HAS_XFLASH} GREATER_EQUAL 0)
  349. add_custom_command( OUTPUT ${LANG_FINAL_BIN}
  350. COMMAND ${CMAKE_COMMAND} -E cat ${LANG_BINS} > ${LANG_FINAL_BIN}
  351. DEPENDS ${LANG_BINS}
  352. COMMENT "Merging language binaries"
  353. )
  354. add_custom_command( OUTPUT ${LANG_FINAL_BIN}
  355. COMMAND ${CMAKE_COMMAND} -DLANG_MAX_SIZE=${LANG_BIN_MAX}
  356. -DLANG_FILE=${LANG_FINAL_BIN}
  357. -P ${PROJECT_CMAKE_DIR}/Check_final_lang_bin_size.cmake
  358. APPEND
  359. )
  360. add_custom_command( OUTPUT ${LANG_FINAL_HEX}
  361. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${LANG_FINAL_BIN} ${LANG_FINAL_HEX}
  362. DEPENDS ${LANG_FINAL_BIN}
  363. COMMENT "Generating Hex for language data"
  364. )
  365. set(LANG_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${variant_name}-Languages.hex)
  366. add_custom_target(${variant_name}-language-hex
  367. COMMAND ${CMAKE_COMMAND} -E copy ${FW_MULTI}.hex ${LANG_HEX}
  368. COMMAND ${CMAKE_COMMAND} -E cat ${LANG_FINAL_HEX} >> ${LANG_HEX}
  369. COMMENT "Generating final ${variant_name}-Languages.hex"
  370. BYPRODUCTS ${LANG_HEX}
  371. DEPENDS ${LANG_FINAL_HEX}
  372. )
  373. add_dependencies(ALL_MULTILANG ${variant_name}-language-hex)
  374. else()
  375. set (ALL_VARIANT_HEXES "")
  376. # Non-xflash, e.g. MK2.5
  377. foreach(LANG IN LISTS SELECTED_LANGUAGES)
  378. SET(LANG_HEX_FN ${variant_name}-en_${LANG})
  379. SET(LANG_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${LANG_HEX_FN}.hex)
  380. SET(LANG_BIN ${LANG_TMP_DIR}/${variant_name}_${LANG}.bin)
  381. SET(LANG_FWBIN_TMP ${LANG_TMP_DIR}/${variant_name}-en_${LANG}.bin)
  382. #Intermediate 2-lang bin
  383. add_custom_command(OUTPUT ${LANG_FWBIN_TMP}
  384. COMMAND ${CMAKE_COMMAND} -E copy ${LANG_FWBIN} ${LANG_FWBIN_TMP}
  385. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-patchsec.py ${FW_MULTI} ${LANG_BIN} ${LANG_FWBIN_TMP}
  386. DEPENDS ${LANG_FWBIN} ${LANG_BIN}
  387. COMMENT "Generating ${variant_name}-en_${LANG}.bin"
  388. )
  389. #Final hex:
  390. add_custom_target(${LANG_HEX_FN}
  391. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${LANG_FWBIN_TMP} ${LANG_HEX}
  392. BYPRODUCTS ${LANG_HEX}
  393. DEPENDS ${LANG_FWBIN_TMP}
  394. COMMENT "Creating ${LANG_HEX_FN}.hex"
  395. )
  396. LIST(APPEND ALL_VARIANT_HEXES ${LANG_HEX_FN})
  397. endforeach()
  398. add_custom_target("${variant_name}-All-Languages"
  399. DEPENDS ${ALL_VARIANT_HEXES}
  400. )
  401. add_dependencies(ALL_MULTILANG "${variant_name}-All-Languages")
  402. endif()
  403. endfunction()
  404. if(CMAKE_CROSSCOMPILING)
  405. # build a list of all supported variants
  406. file(GLOB ALL_VARIANTS RELATIVE ${PROJECT_SOURCE_DIR}/Firmware/variants ${PROJECT_SOURCE_DIR}/Firmware/variants/*.h)
  407. list(TRANSFORM ALL_VARIANTS REPLACE "\.h$" "")
  408. set(FW_VARIANTS ${ALL_VARIANTS} CACHE STRING "Firmware variants to be built")
  409. foreach(THIS_VAR IN LISTS FW_VARIANTS)
  410. if(NOT ${THIS_VAR} IN_LIST ALL_VARIANTS)
  411. message(FATAL_ERROR "Variant ${THIS_VAR} does not exist")
  412. endif()
  413. message("Variant added: ${THIS_VAR}")
  414. string(REPLACE "-E3Dv6full" "" DIR_NAME "${THIS_VAR}")
  415. string(REPLACE "1_75mm_" "" DIR_NAME "${DIR_NAME}")
  416. # Generate a file in a subfolder so that we can organize things a little more neatly in VS code
  417. FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME})
  418. FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME}/CMakeLists.txt "project(${DIR_NAME})\nfw_add_variant(${THIS_VAR})")
  419. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME})
  420. #fw_add_variant(${TRIMMED_NAME})
  421. endforeach(THIS_VAR IN LISTS FW_VARIANTS)
  422. endif()
  423. if(NOT CMAKE_CROSSCOMPILING)
  424. enable_testing()
  425. add_subdirectory(tests)
  426. endif()