CMakeLists.txt 18 KB

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