CMakeLists.txt 16 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. FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/config.h MAX_SIZE_LINE REGEX "^#define \+LANG_SIZE_RESERVED \+")
  51. STRING(REGEX MATCH "0x[0-9]+" MAX_SIZE_HEX "${MAX_SIZE_LINE}")
  52. math(EXPR LANG_MAX_SIZE "${MAX_SIZE_HEX}" OUTPUT_FORMAT DECIMAL)
  53. message("Language maximum size (from config.h): ${LANG_MAX_SIZE} bytes")
  54. set (LANG_BIN_MAX 249856) # Ditto, this in xflash_layout.h but needs invocation of the preprocessor... :-/
  55. get_recommended_gcc_version(RECOMMENDED_TOOLCHAIN_VERSION)
  56. if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL
  57. ${RECOMMENDED_TOOLCHAIN_VERSION}
  58. )
  59. message(WARNING "Recommended AVR toolchain is ${RECOMMENDED_TOOLCHAIN_VERSION}"
  60. ", but you have ${CMAKE_CXX_COMPILER_VERSION}"
  61. )
  62. elseif(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  63. message(
  64. WARNING
  65. "Recommended compiler for host tools and unittests is GCC, you have ${CMAKE_CXX_COMPILER_ID}."
  66. )
  67. endif()
  68. # append custom C/C++ flags
  69. if(CUSTOM_COMPILE_OPTIONS)
  70. string(REPLACE " " ";" CUSTOM_COMPILE_OPTIONS "${CUSTOM_COMPILE_OPTIONS}")
  71. add_compile_options(${CUSTOM_COMPILE_OPTIONS})
  72. endif()
  73. #
  74. # Global Compiler & Linker Configuration
  75. #
  76. # include symbols
  77. add_compile_options(-g)
  78. #
  79. # Firmware - get file lists.
  80. #
  81. SET(FW_SOURCES
  82. adc.cpp
  83. backlight.cpp
  84. BlinkM.cpp
  85. bootapp.c
  86. cardreader.cpp
  87. cmdqueue.cpp
  88. Configuration.cpp
  89. ConfigurationStore.cpp
  90. conv2str.cpp
  91. Dcodes.cpp
  92. eeprom.cpp
  93. fancheck.cpp
  94. Filament_sensor.cpp
  95. first_lay_cal.cpp
  96. heatbed_pwm.cpp
  97. la10compat.cpp
  98. language.c
  99. lcd.cpp
  100. Marlin_main.cpp
  101. MarlinSerial.cpp
  102. menu.cpp
  103. mesh_bed_calibration.cpp
  104. mesh_bed_leveling.cpp
  105. messages.cpp
  106. mmu2.cpp
  107. mmu2_crc.cpp
  108. mmu2_error_converter.cpp
  109. mmu2_fsensor.cpp
  110. mmu2_log.cpp
  111. mmu2_power.cpp
  112. mmu2_progress_converter.cpp
  113. mmu2_protocol.cpp
  114. mmu2_protocol_logic.cpp
  115. mmu2_reporting.cpp
  116. mmu2_serial.cpp
  117. motion_control.cpp
  118. optiboot_xflash.cpp
  119. pat9125.cpp
  120. planner.cpp
  121. Prusa_farm.cpp
  122. qr_solve.cpp
  123. rbuf.c
  124. Sd2Card.cpp
  125. SdBaseFile.cpp
  126. SdFatUtil.cpp
  127. SdFile.cpp
  128. SdVolume.cpp
  129. Servo.cpp
  130. sm4.c
  131. sound.cpp
  132. speed_lookuptable.cpp
  133. spi.c
  134. SpoolJoin.cpp
  135. stepper.cpp
  136. swi2c.c
  137. swspi.cpp
  138. Tcodes.cpp
  139. temperature.cpp
  140. timer02.c
  141. Timer.cpp
  142. tmc2130.cpp
  143. tone04.c
  144. twi.cpp
  145. uart2.c
  146. ultralcd.cpp
  147. util.cpp
  148. vector_3.cpp
  149. xflash.c
  150. xflash_dump.cpp
  151. xyzcal.cpp
  152. )
  153. list(TRANSFORM FW_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/)
  154. foreach(_FILE ${FW_SOURCES})
  155. get_filename_component(_BASE ${_FILE} NAME)
  156. set_property(SOURCE ${_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS "-frandom-seed=${_BASE}.o")
  157. endforeach()
  158. set(AVR_SOURCES
  159. wiring_digital.c
  160. WInterrupts.c
  161. wiring_pulse.c
  162. hooks.c
  163. wiring.c
  164. wiring_analog.c
  165. wiring_shift.c
  166. CDC.cpp
  167. PluggableUSB.cpp
  168. HardwareSerial.cpp
  169. HardwareSerial0.cpp
  170. HardwareSerial1.cpp
  171. HardwareSerial3.cpp
  172. IPAddress.cpp
  173. HardwareSerial2.cpp
  174. Print.cpp
  175. Stream.cpp
  176. Tone.cpp
  177. USBCore.cpp
  178. WMath.cpp
  179. WString.cpp
  180. abi.cpp
  181. main.cpp
  182. # new.cpp # What happened to this? it was removed in 1.0.5-1 to 1.0.5.2?
  183. )
  184. list(TRANSFORM AVR_SOURCES PREPEND ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/)
  185. foreach(_FILE ${AVR_SOURCES})
  186. get_filename_component(_BASE ${_FILE} NAME)
  187. set_property(SOURCE ${_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS "-frandom-seed=core/${_BASE}.o")
  188. endforeach()
  189. # optimizations
  190. if(CMAKE_CROSSCOMPILING)
  191. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  192. add_compile_options(-Og)
  193. else()
  194. add_compile_options(-Os)
  195. endif()
  196. # mcu related settings
  197. set(MCU_FLAGS -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_PRUSA_EINSY_RAMBO -DARDUINO_ARCH_AVR)
  198. add_compile_options(${MCU_FLAGS})
  199. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
  200. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>)
  201. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
  202. add_compile_options(-Wall -Wextra -Wno-expansion-to-defined -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects)
  203. # split and gc sections
  204. add_link_options(-Os -g -flto -Wl,--gc-sections -mmcu=atmega2560 -Wl,-u,vfprintf -lprintf_flt -lm )
  205. # Create this target before we apply the GC options
  206. add_library(avr_core STATIC ${AVR_SOURCES})
  207. target_include_directories(avr_core PRIVATE
  208. ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/
  209. ${PRUSA_BOARDS_DIR}/variants/prusa_einsy_rambo/
  210. )
  211. # disable exceptions and related metadata
  212. add_compile_options(-fno-unwind-tables)
  213. add_link_options(-Wl,--defsym,__exidx_start=0,--defsym,__exidx_end=0)
  214. else()
  215. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  216. add_compile_options(-O0)
  217. else()
  218. add_compile_options(-O2)
  219. endif()
  220. endif()
  221. # enable all warnings (well, not all, but some)
  222. add_compile_options(-Wsign-compare)
  223. add_compile_options($<$<COMPILE_LANGUAGE:C>:-std=gnu11>)
  224. # support _DEBUG macro (some code uses to recognize debug builds)
  225. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  226. add_compile_definitions(_DEBUG)
  227. endif()
  228. # Setup language resources:
  229. # file(GLOB LANG_VARIANTS RELATIVE ${PROJECT_SOURCE_DIR}/lang/po ${PROJECT_SOURCE_DIR}/lang/po/Firmware_??.po)
  230. # string(REPLACE "Firmware_" "" LANG_VARIANTS "${LANG_VARIANTS}")
  231. # string(REPLACE ".po" "" LANG_VARIANTS "${LANG_VARIANTS}")
  232. # list(SORT LANG_VARIANTS)
  233. # message("Languages found: ${LANG_VARIANTS}")
  234. # Meta target to build absolutely everything
  235. add_custom_target(ALL_FIRMWARE)
  236. add_custom_target(ALL_ENGLISH)
  237. add_custom_target(ALL_MULTILANG)
  238. add_dependencies(ALL_FIRMWARE ALL_ENGLISH ALL_MULTILANG)
  239. function(add_base_binary variant_name)
  240. add_executable(${variant_name} ${FW_SOURCES} ${FW_HEADERS} ${VARIANT_CFG_FILE})
  241. set_target_properties(${variant_name} PROPERTIES CXX_STANDARD 17)
  242. target_include_directories(${variant_name} PRIVATE
  243. ${PRUSA_BOARDS_DIR}/cores/prusa_einsy_rambo/
  244. ${PRUSA_BOARDS_DIR}/variants/prusa_einsy_rambo/
  245. ${VARIANT_CFG_DIR} # Include the header for this variant.
  246. ${CMAKE_SOURCE_DIR}/Firmware
  247. )
  248. target_link_libraries(${variant_name} avr_core)
  249. # # configure linker script
  250. set(LINKER_SCRIPT ${PRUSA_BOARDS_DIR}/ldscripts/avr6.xn)
  251. target_link_options(${variant_name} PUBLIC -Wl,-T,${LINKER_SCRIPT})
  252. # limit the text section to 248K (256K - 8k reserved for the bootloader)
  253. target_link_options(${variant_name} PUBLIC -Wl,--defsym=__TEXT_REGION_LENGTH__=248K)
  254. # generate firmware.bin file
  255. objcopy(${variant_name} "ihex" ".hex")
  256. # produce ASM listing. Note we also specify the .map as a byproduct so it gets cleaned
  257. # because link_options doesn't have a "generated outputs" feature.
  258. add_custom_command(
  259. TARGET ${variant_name} POST_BUILD COMMAND ${CMAKE_OBJDUMP} -CSd ${variant_name} > ${variant_name}.asm
  260. BYPRODUCTS ${variant_name}.asm ${variant_name}.map
  261. )
  262. # inform about the firmware's size in terminal
  263. add_custom_command(
  264. TARGET ${variant_name} POST_BUILD COMMAND ${CMAKE_SIZE_UTIL} -C --mcu=atmega2560 ${variant_name}
  265. )
  266. report_size(${variant_name})
  267. # generate linker map file
  268. target_link_options(${variant_name} PUBLIC -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${variant_name}.map)
  269. target_compile_definitions(${variant_name} PRIVATE
  270. CMAKE_LANG_CONTROL
  271. )
  272. endfunction()
  273. function(fw_add_variant variant_name)
  274. # Create the Configuration_Prusa.h for this variant so it can be #included.
  275. set(VARIANT_CFG_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
  276. set(VARIANT_CFG_FILE "${VARIANT_CFG_DIR}/Configuration_prusa.h")
  277. add_custom_command(OUTPUT ${VARIANT_CFG_FILE}
  278. COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Firmware/variants/${variant_name}.h ${VARIANT_CFG_FILE}
  279. COMMENT "Generating Configuration_prusa.h for ${variant_name}"
  280. BYPRODUCTS ${VARIANT_CFG_DIR}
  281. )
  282. STRING(REPLACE "1_75mm_" "" variant_name "${variant_name}")
  283. STRING(REPLACE "-E3Dv6full" "" variant_name "${variant_name}")
  284. SET(FW_EN "${variant_name}_EN-only")
  285. SET(FW_MULTI "${variant_name}_Multilang")
  286. add_base_binary(${FW_EN})
  287. # target_compile_options(${variant_name} PRIVATE) # turn this on for lolz -Wdouble-promotion)
  288. target_compile_definitions(${FW_EN} PUBLIC LANG_MODE=0)
  289. add_custom_command(
  290. TARGET ${FW_EN}
  291. POST_BUILD
  292. COMMAND ${CMAKE_OBJCOPY} -O ihex ${CMAKE_CURRENT_BINARY_DIR}/${FW_EN} ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_EN}.hex
  293. BYPRODUCTS ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${FW_EN}.hex
  294. COMMENT "Generating ${variant_name} hex"
  295. )
  296. add_dependencies(ALL_ENGLISH "${FW_EN}")
  297. if (NOT SECONDARY_LANGUAGES)
  298. return() #Done, if no languages there's nothing else to do.
  299. else()
  300. add_base_binary(${FW_MULTI})
  301. target_compile_definitions(${FW_MULTI} PUBLIC LANG_MODE=1)
  302. endif()
  303. #Construct language map
  304. set(LANG_TMP_DIR ${CMAKE_BINARY_DIR}/${variant_name}/lang)
  305. set(LANG_MAP ${LANG_TMP_DIR}/${variant_name}_lang.map)
  306. set(LANG_FWBIN ${CMAKE_CURRENT_BINARY_DIR}/${variant_name}.bin)
  307. set(LANG_FINAL_BIN ${LANG_TMP_DIR}/${variant_name}_lang.bin)
  308. set(LANG_FINAL_HEX ${LANG_TMP_DIR}/${variant_name}_lang.hex)
  309. add_custom_command(OUTPUT ${LANG_FWBIN}
  310. COMMAND "${CMAKE_OBJCOPY}" -I ihex -O binary ${CMAKE_CURRENT_BINARY_DIR}/${variant_name}_Multilang.hex ${LANG_FWBIN}
  311. DEPENDS ${FW_MULTI}
  312. )
  313. add_custom_command(OUTPUT ${LANG_MAP}
  314. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-map.py "${FW_MULTI}" "${LANG_FWBIN}" > "${LANG_MAP}"
  315. DEPENDS ${LANG_FWBIN}
  316. )
  317. set(LANG_BINS "")
  318. foreach (LANG IN LISTS SELECTED_LANGUAGES)
  319. set(LANG_BIN ${LANG_TMP_DIR}/${variant_name}_${LANG}.bin)
  320. set(PO_FILE "${CMAKE_SOURCE_DIR}/lang/po/Firmware_${LANG}.po")
  321. add_custom_command(OUTPUT ${LANG_BIN}
  322. # COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lang/lang-check.py --no-warning --map "${LANG_MAP}" "${PO_FILE}"
  323. # COMMAND ${CMAKE_COMMAND} -E echo "Building lang_${LANG}.bin"
  324. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-build.py ${LANG_MAP} ${PO_FILE} ${LANG_BIN}
  325. # Check bin size:
  326. COMMAND ${CMAKE_COMMAND} -DLANG_MAX_SIZE=${LANG_MAX_SIZE}
  327. -DLANG_FILE=${LANG_BIN}
  328. -P ${PROJECT_CMAKE_DIR}/Check_lang_size.cmake
  329. DEPENDS ${LANG_MAP}
  330. COMMENT "Generating ${variant_name}_${LANG}.bin from .po"
  331. )
  332. LIST(APPEND LANG_BINS ${LANG_BIN})
  333. endforeach()
  334. string(FIND ${variant_name} "MK3" HAS_XFLASH)
  335. if (${HAS_XFLASH} GREATER_EQUAL 0)
  336. add_custom_command( OUTPUT ${LANG_FINAL_BIN}
  337. COMMAND ${CMAKE_COMMAND} -E cat ${LANG_BINS} > ${LANG_FINAL_BIN}
  338. DEPENDS ${LANG_BINS}
  339. COMMENT "Merging language binaries"
  340. )
  341. add_custom_command( OUTPUT ${LANG_FINAL_BIN}
  342. COMMAND ${CMAKE_COMMAND} -DLANG_MAX_SIZE=${LANG_BIN_MAX}
  343. -DLANG_FILE=${LANG_FINAL_BIN}
  344. -P ${PROJECT_CMAKE_DIR}/Check_final_lang_bin_size.cmake
  345. APPEND
  346. )
  347. add_custom_command( OUTPUT ${LANG_FINAL_HEX}
  348. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${LANG_FINAL_BIN} ${LANG_FINAL_HEX}
  349. DEPENDS ${LANG_FINAL_BIN}
  350. COMMENT "Generating Hex for language data"
  351. )
  352. set(LANG_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${variant_name}-Languages.hex)
  353. add_custom_target(${variant_name}-language-hex
  354. COMMAND ${CMAKE_COMMAND} -E copy ${FW_MULTI}.hex ${LANG_HEX}
  355. COMMAND ${CMAKE_COMMAND} -E cat ${LANG_FINAL_HEX} >> ${LANG_HEX}
  356. COMMENT "Generating final ${variant_name}-Languages.hex"
  357. BYPRODUCTS ${LANG_HEX}
  358. DEPENDS ${LANG_FINAL_HEX}
  359. )
  360. add_dependencies(ALL_MULTILANG ${variant_name}-language-hex)
  361. else()
  362. set (ALL_VARIANT_HEXES "")
  363. # Non-xflash, e.g. MK2.5
  364. foreach(LANG IN LISTS SELECTED_LANGUAGES)
  365. SET(LANG_HEX_FN ${variant_name}-en_${LANG})
  366. SET(LANG_HEX ${CMAKE_BINARY_DIR}/${FN_PREFIX}-${LANG_HEX_FN}.hex)
  367. SET(LANG_BIN ${LANG_TMP_DIR}/${variant_name}_${LANG}.bin)
  368. SET(LANG_FWBIN_TMP ${LANG_TMP_DIR}/${variant_name}-en_${LANG}.bin)
  369. #Intermediate 2-lang bin
  370. add_custom_command(OUTPUT ${LANG_FWBIN_TMP}
  371. COMMAND ${CMAKE_COMMAND} -E copy ${LANG_FWBIN} ${LANG_FWBIN_TMP}
  372. COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-patchsec.py ${FW_MULTI} ${LANG_BIN} ${LANG_FWBIN_TMP}
  373. DEPENDS ${LANG_FWBIN} ${LANG_BIN}
  374. COMMENT "Generating ${variant_name}-en_${LANG}.bin"
  375. )
  376. #Final hex:
  377. add_custom_target(${LANG_HEX_FN}
  378. COMMAND ${CMAKE_OBJCOPY} -I binary -O ihex ${LANG_FWBIN_TMP} ${LANG_HEX}
  379. BYPRODUCTS ${LANG_HEX}
  380. DEPENDS ${LANG_FWBIN_TMP}
  381. COMMENT "Creating ${LANG_HEX_FN}.hex"
  382. )
  383. LIST(APPEND ALL_VARIANT_HEXES ${LANG_HEX_FN})
  384. endforeach()
  385. add_custom_target("${variant_name}-All-Languages"
  386. DEPENDS ${ALL_VARIANT_HEXES}
  387. )
  388. add_dependencies(ALL_MULTILANG "${variant_name}-All-Languages")
  389. endif()
  390. endfunction()
  391. if(CMAKE_CROSSCOMPILING)
  392. file(GLOB FW_VARIANTS RELATIVE ${PROJECT_SOURCE_DIR}/Firmware/variants ${PROJECT_SOURCE_DIR}/Firmware/variants/*.h)
  393. foreach(THIS_VAR IN LISTS FW_VARIANTS)
  394. string(REPLACE ".h" "" TRIMMED_NAME "${THIS_VAR}")
  395. message("Variant added: ${TRIMMED_NAME}")
  396. string(REPLACE "-E3Dv6full" "" DIR_NAME "${TRIMMED_NAME}")
  397. string(REPLACE "1_75mm_" "" DIR_NAME "${DIR_NAME}")
  398. # Generate a file in a subfolder so that we can organize things a little more neatly in VS code
  399. FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME})
  400. FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME}/CMakeLists.txt "project(${DIR_NAME})\nfw_add_variant(${TRIMMED_NAME})")
  401. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/build_gen/${DIR_NAME})
  402. #fw_add_variant(${TRIMMED_NAME})
  403. endforeach(THIS_VAR IN LISTS FW_VARIANTS)
  404. endif()
  405. if(NOT CMAKE_CROSSCOMPILING)
  406. # do not build the firmware by default (tests are the focus if not crosscompiling)
  407. project(cmake_test)
  408. # Prepare "Catch" library for other executables
  409. set(CATCH_INCLUDE_DIR Catch2)
  410. add_library(Catch INTERFACE)
  411. target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
  412. # Make test executable
  413. set(TEST_SOURCES
  414. Tests/tests.cpp
  415. Tests/Example_test.cpp
  416. Tests/Timer_test.cpp
  417. Tests/AutoDeplete_test.cpp
  418. Tests/PrusaStatistics_test.cpp
  419. Firmware/Timer.cpp
  420. Firmware/AutoDeplete.cpp
  421. )
  422. add_executable(tests ${TEST_SOURCES})
  423. target_include_directories(tests PRIVATE Tests)
  424. target_link_libraries(tests Catch)
  425. endif()