CMakeLists.txt 16 KB

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