CMakeLists.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. Tcodes.cpp
  164. temperature.cpp
  165. timer02.c
  166. Timer.cpp
  167. tmc2130.cpp
  168. tone04.c
  169. twi.cpp
  170. uart2.c
  171. ultralcd.cpp
  172. util.cpp
  173. vector_3.cpp
  174. xflash.c
  175. xflash_dump.cpp
  176. xyzcal.cpp
  177. )
  178. list(TRANSFORM FW_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/)
  179. set(AVR_SOURCES
  180. wiring_digital.c
  181. WInterrupts.c
  182. wiring_pulse.c
  183. hooks.c
  184. wiring.c
  185. wiring_analog.c
  186. wiring_shift.c
  187. CDC.cpp
  188. PluggableUSB.cpp
  189. HardwareSerial.cpp
  190. HardwareSerial0.cpp
  191. HardwareSerial1.cpp
  192. HardwareSerial3.cpp
  193. IPAddress.cpp
  194. HardwareSerial2.cpp
  195. Print.cpp
  196. Stream.cpp
  197. Tone.cpp
  198. USBCore.cpp
  199. WMath.cpp
  200. WString.cpp
  201. abi.cpp
  202. main.cpp
  203. )
  204. list(TRANSFORM AVR_SOURCES PREPEND ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/)
  205. #
  206. # Target configuration
  207. #
  208. if(CMAKE_CROSSCOMPILING)
  209. # TODO: get date from the last git commit to set as epoch
  210. set_source_epoch(0)
  211. # default optimization flags
  212. set(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
  213. set(CMAKE_CXX_FLAGS_RELEASE "-Os -g -DNDEBUG")
  214. set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
  215. set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
  216. # mcu and target-related settings
  217. add_compile_options(
  218. -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRUSA_EINSY_RAMBO
  219. -DARDUINO_ARCH_AVR
  220. )
  221. add_link_options(-mmcu=atmega2560 -Wl,-u,vfprintf -lprintf_flt -lm)
  222. # disable some C++ language features
  223. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>)
  224. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
  225. # disable exceptions
  226. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
  227. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables>)
  228. # split and gc sections
  229. add_compile_options(-ffunction-sections -fdata-sections)
  230. add_link_options(-ffunction-sections -fdata-sections -Wl,--gc-sections)
  231. # LTO (with custom options)
  232. add_compile_options(-flto -fno-fat-lto-objects)
  233. add_link_options(-flto)
  234. # Create this target before we apply the GC options
  235. add_library(avr_core STATIC ${AVR_SOURCES})
  236. set_reproducible_target(avr_core)
  237. target_include_directories(
  238. avr_core PRIVATE ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/
  239. ${PRUSA_BOARDS_DIR}/variants/prusa_einsy_rambo/
  240. )
  241. endif()
  242. # Meta targets to build absolutely everything
  243. add_custom_target(ALL_FIRMWARE)
  244. add_custom_target(ALL_ENGLISH)
  245. add_custom_target(ALL_MULTILANG)
  246. add_dependencies(ALL_FIRMWARE ALL_ENGLISH ALL_MULTILANG)
  247. set_target_properties(ALL_MULTILANG PROPERTIES EXCLUDE_FROM_ALL FALSE)
  248. function(add_base_binary variant_name)
  249. add_executable(${variant_name} ${FW_SOURCES} ${FW_HEADERS} ${VARIANT_CFG_DST})
  250. set_target_properties(${variant_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
  251. set_reproducible_target(${variant_name})
  252. target_include_directories(
  253. ${variant_name}
  254. PRIVATE ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/
  255. ${PRUSA_BOARDS_DIR}/variants/prusa_einsy_rambo/ ${CMAKE_SOURCE_DIR}/Firmware
  256. )
  257. target_link_libraries(${variant_name} avr_core)
  258. # configure linker script
  259. set(LINKER_SCRIPT ${PRUSA_BOARDS_DIR}/ldscripts/avr6.xn)
  260. target_link_options(${variant_name} PUBLIC -Wl,-T,${LINKER_SCRIPT})
  261. # limit the text section to 248K (256K - 8k reserved for the bootloader)
  262. target_link_options(${variant_name} PUBLIC -Wl,--defsym=__TEXT_REGION_LENGTH__=248K)
  263. # produce ASM listing. Note we also specify the .map as a byproduct so it gets cleaned because
  264. # link_options doesn't have a "generated outputs" feature.
  265. add_custom_command(
  266. TARGET ${variant_name}
  267. POST_BUILD
  268. COMMAND ${CMAKE_OBJDUMP} --prefix ${CMAKE_SOURCE_DIR} -CSd ${variant_name} > ${variant_name}.asm
  269. BYPRODUCTS ${variant_name}.asm ${variant_name}.map
  270. )
  271. # inform about the firmware's size in terminal
  272. add_custom_command(
  273. TARGET ${variant_name}
  274. POST_BUILD
  275. COMMAND ${CMAKE_SIZE_UTIL} -C --mcu=atmega2560 ${variant_name}
  276. )
  277. report_size(${variant_name})
  278. # generate linker map file
  279. target_link_options(
  280. ${variant_name} PUBLIC -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${variant_name}.map
  281. )
  282. target_compile_definitions(${variant_name} PRIVATE CMAKE_CONTROL)
  283. endfunction()
  284. function(fw_add_variant variant_name)
  285. set(variant_header "variants/${variant_name}.h")
  286. string(REPLACE "1_75mm_" "" variant_name "${variant_name}")
  287. string(REPLACE "-E3Dv6full" "" variant_name "${variant_name}")
  288. # Single-language build
  289. set(FW_EN "${variant_name}_EN-only")
  290. set(FW_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_EN}.hex)
  291. add_base_binary(${FW_EN})
  292. target_compile_definitions(${FW_EN} PUBLIC LANG_MODE=0 FW_VARIANT="${variant_header}")
  293. add_custom_command(
  294. TARGET ${FW_EN}
  295. POST_BUILD
  296. COMMAND ${CMAKE_OBJCOPY} -O ihex ${FW_EN} ${FW_EN}.hex
  297. COMMAND ${CMAKE_COMMAND} -E create_hardlink ${FW_EN}.hex ${FW_HEX}
  298. BYPRODUCTS ${FW_EN}.hex ${FW_HEX}
  299. COMMENT "Generating ${FW_EN}.hex"
  300. )
  301. add_dependencies(ALL_ENGLISH ${FW_EN})
  302. # Multi-language build/s
  303. set(FW_LANG_BASE "${variant_name}_Multilang_base")
  304. set(FW_LANG_PATCH "${variant_name}_Multilang_patch")
  305. add_base_binary(${FW_LANG_BASE})
  306. target_compile_definitions(${FW_LANG_BASE} PUBLIC LANG_MODE=1 FW_VARIANT="${variant_header}")
  307. # Construct language map
  308. set(LANG_TMP_DIR lang)
  309. set(LANG_MAP ${LANG_TMP_DIR}/${variant_name}_lang.map)
  310. add_custom_command(
  311. OUTPUT ${LANG_MAP}
  312. COMMAND ${CMAKE_OBJCOPY} -O binary ${FW_LANG_BASE} ${FW_LANG_PATCH}.bin
  313. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-map.py ${FW_LANG_BASE} ${FW_LANG_PATCH}.bin > ${LANG_MAP}
  314. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${FW_LANG_PATCH}.bin ${FW_LANG_PATCH}.hex
  315. DEPENDS ${FW_LANG_BASE}
  316. BYPRODUCTS ${FW_LANG_PATCH}.bin ${FW_LANG_PATCH}.hex
  317. COMMENT "Generating ${variant_name} language map"
  318. )
  319. # Base targets for language checks
  320. add_custom_target(check_lang_${variant_name})
  321. add_dependencies(check_lang check_lang_${variant_name})
  322. # Build language catalogs
  323. set(LANG_BINS "")
  324. foreach(LANG IN LISTS SELECTED_LANGUAGES)
  325. set(LANG_BIN ${LANG_TMP_DIR}/${variant_name}_${LANG}.bin)
  326. set(PO_FILE "${CMAKE_SOURCE_DIR}/lang/po/Firmware_${LANG}.po")
  327. # Full language checks
  328. add_custom_target(
  329. check_lang_${variant_name}_${LANG}
  330. COMMENT "Checking ${variant_name} language ${LANG}"
  331. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-check.py --map ${LANG_MAP} ${PO_FILE}
  332. DEPENDS ${LANG_MAP} ${PO_FILE}
  333. USES_TERMINAL
  334. )
  335. add_dependencies(check_lang_${variant_name} check_lang_${variant_name}_${LANG})
  336. add_dependencies(check_lang_${LANG} check_lang_${variant_name}_${LANG})
  337. add_custom_command(
  338. OUTPUT ${LANG_BIN}
  339. # Check po file for errors _only_
  340. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-check.py --errors-only --map ${LANG_MAP} ${PO_FILE}
  341. # Build the catalog
  342. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-build.py ${LANG_MAP} ${PO_FILE} ${LANG_BIN}
  343. # Check bin size
  344. COMMAND ${CMAKE_COMMAND} -DLANG_MAX_SIZE=${LANG_MAX_SIZE} -DLANG_FILE=${LANG_BIN} -P
  345. ${PROJECT_CMAKE_DIR}/Check_lang_size.cmake
  346. DEPENDS ${LANG_MAP} ${PO_FILE}
  347. COMMENT "Generating ${variant_name}_${LANG}.bin"
  348. )
  349. list(APPEND LANG_BINS ${LANG_BIN})
  350. endforeach()
  351. string(FIND ${variant_name} "MK3" HAS_XFLASH)
  352. if(${HAS_XFLASH} GREATER_EQUAL 0)
  353. # X-Flash based build (catalogs appended to patched binary)
  354. set(FW_LANG_FINAL "${variant_name}_Multilang")
  355. set(LANG_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_LANG_FINAL}.hex)
  356. set(LANG_CATBIN ${LANG_TMP_DIR}/${variant_name}_cat.bin)
  357. set(LANG_CATHEX ${LANG_TMP_DIR}/${variant_name}_cat.hex)
  358. add_custom_command(
  359. OUTPUT ${LANG_CATBIN}
  360. COMMAND ${CMAKE_COMMAND} -E cat ${LANG_BINS} > ${LANG_CATBIN}
  361. DEPENDS ${LANG_BINS}
  362. COMMENT "Merging language catalogs"
  363. )
  364. #[[
  365. #add_custom_command(OUTPUT ${LANG_FINAL_BIN}
  366. # COMMAND ${CMAKE_COMMAND} -DLANG_MAX_SIZE=${LANG_BIN_MAX} -DLANG_FILE=${LANG_FINAL_BIN}
  367. # -P ${PROJECT_CMAKE_DIR}/Check_final_lang_bin_size.cmake
  368. # APPEND)
  369. #]]
  370. add_custom_command(
  371. OUTPUT ${LANG_CATHEX}
  372. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${LANG_CATBIN} ${LANG_CATHEX}
  373. DEPENDS ${LANG_CATBIN}
  374. COMMENT "Generating Hex for language data"
  375. )
  376. add_custom_command(
  377. OUTPUT ${FW_LANG_FINAL}.hex
  378. COMMAND ${CMAKE_COMMAND} -E cat ${FW_LANG_PATCH}.hex ${LANG_CATHEX} > ${FW_LANG_FINAL}.hex
  379. COMMAND ${CMAKE_COMMAND} -E create_hardlink ${FW_LANG_FINAL}.hex ${LANG_HEX}
  380. BYPRODUCTS ${LANG_HEX}
  381. DEPENDS ${FW_LANG_PATCH}.hex ${LANG_CATHEX}
  382. COMMENT "Generating final ${FW_LANG_FINAL}.hex"
  383. )
  384. add_custom_target(${FW_LANG_FINAL} DEPENDS ${FW_LANG_FINAL}.hex)
  385. add_dependencies(ALL_MULTILANG ${FW_LANG_FINAL})
  386. else()
  387. set(ALL_VARIANT_HEXES "")
  388. # Non-xflash, e.g. MK2.5
  389. foreach(LANG IN LISTS SELECTED_LANGUAGES)
  390. set(FW_LANG_FINAL ${variant_name}-en_${LANG})
  391. set(LANG_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_LANG_FINAL}.hex)
  392. set(LANG_BIN ${LANG_TMP_DIR}/${variant_name}_${LANG}.bin)
  393. # Patched binary with pre-baked secondary language
  394. add_custom_command(
  395. OUTPUT ${FW_LANG_FINAL}.bin
  396. COMMAND ${CMAKE_OBJCOPY} -O binary ${FW_LANG_BASE} ${FW_LANG_FINAL}.bin
  397. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-patchsec.py ${FW_LANG_BASE} ${LANG_BIN}
  398. ${FW_LANG_FINAL}.bin
  399. DEPENDS ${FW_LANG_BASE} ${LANG_BIN}
  400. COMMENT "Generating ${FW_LANG_FINAL}.bin"
  401. )
  402. # Final hex files
  403. add_custom_command(
  404. OUTPUT ${FW_LANG_FINAL}.hex
  405. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${FW_LANG_FINAL}.bin ${FW_LANG_FINAL}.hex
  406. COMMAND ${CMAKE_COMMAND} -E create_hardlink ${FW_LANG_FINAL}.hex ${LANG_HEX}
  407. BYPRODUCTS ${LANG_HEX}
  408. DEPENDS ${FW_LANG_FINAL}.bin
  409. COMMENT "Creating ${FW_LANG_FINAL}.hex"
  410. )
  411. add_custom_target(${FW_LANG_FINAL} DEPENDS ${FW_LANG_FINAL}.hex)
  412. list(APPEND ALL_VARIANT_HEXES ${FW_LANG_FINAL})
  413. endforeach()
  414. add_custom_target("${variant_name}-All-Languages" DEPENDS ${ALL_VARIANT_HEXES})
  415. add_dependencies(ALL_MULTILANG "${variant_name}-All-Languages")
  416. endif()
  417. endfunction()
  418. if(CMAKE_CROSSCOMPILING)
  419. # Main target for language checks
  420. add_custom_target(check_lang)
  421. foreach(LANG IN LISTS SELECTED_LANGUAGES)
  422. add_custom_target(check_lang_${LANG})
  423. add_dependencies(check_lang check_lang_${LANG})
  424. endforeach()
  425. # build a list of all supported variants
  426. file(
  427. GLOB ALL_VARIANTS
  428. RELATIVE ${PROJECT_SOURCE_DIR}/Firmware/variants
  429. ${PROJECT_SOURCE_DIR}/Firmware/variants/*.h
  430. )
  431. list(TRANSFORM ALL_VARIANTS REPLACE "\.h$" "")
  432. set(FW_VARIANTS
  433. ${ALL_VARIANTS}
  434. CACHE STRING "Firmware variants to be built"
  435. )
  436. foreach(THIS_VAR IN LISTS FW_VARIANTS)
  437. if(NOT ${THIS_VAR} IN_LIST ALL_VARIANTS)
  438. message(FATAL_ERROR "Variant ${THIS_VAR} does not exist")
  439. endif()
  440. message("Variant added: ${THIS_VAR}")
  441. string(REPLACE "-E3Dv6full" "" DIR_NAME "${THIS_VAR}")
  442. string(REPLACE "1_75mm_" "" DIR_NAME "${DIR_NAME}")
  443. # Generate a file in a subfolder so that we can organize things a little more neatly in VS code
  444. file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME})
  445. file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME}/CMakeLists.txt
  446. "project(${DIR_NAME})\nfw_add_variant(${THIS_VAR})"
  447. )
  448. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME})
  449. endforeach(THIS_VAR IN LISTS FW_VARIANTS)
  450. endif()
  451. #
  452. # Tests
  453. #
  454. if(NOT CMAKE_CROSSCOMPILING)
  455. enable_testing()
  456. add_subdirectory(tests)
  457. endif()