CMakeLists.txt 16 KB

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