FindPioasm.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Finds (or builds) the Pioasm executable
  2. #
  3. # This will define the following variables
  4. #
  5. # Pioasm_FOUND
  6. #
  7. # and the following imported targets
  8. #
  9. # Pioasm
  10. #
  11. if (NOT Pioasm_FOUND)
  12. # todo we would like to use pckgconfig to look for it first
  13. # see https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
  14. include(ExternalProject)
  15. set(PIOASM_SOURCE_DIR ${PICO_SDK_PATH}/tools/pioasm)
  16. set(PIOASM_BINARY_DIR ${CMAKE_BINARY_DIR}/pioasm)
  17. set(PioasmBuild_TARGET PioasmBuild)
  18. set(Pioasm_TARGET Pioasm)
  19. if (NOT TARGET ${PioasmBuild_TARGET})
  20. pico_message_debug("PIOASM will need to be built")
  21. # message("Adding external project ${PioasmBuild_Target} in ${CMAKE_CURRENT_LIST_DIR}}")
  22. ExternalProject_Add(${PioasmBuild_TARGET}
  23. PREFIX pioasm
  24. SOURCE_DIR ${PIOASM_SOURCE_DIR}
  25. BINARY_DIR ${PIOASM_BINARY_DIR}
  26. CMAKE_ARGS "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}"
  27. CMAKE_CACHE_ARGS "-DPIOASM_EXTRA_SOURCE_FILES:STRING=${PIOASM_EXTRA_SOURCE_FILES}"
  28. BUILD_ALWAYS 1 # force dependency checking
  29. INSTALL_COMMAND ""
  30. )
  31. endif()
  32. if (CMAKE_HOST_WIN32)
  33. set(Pioasm_EXECUTABLE ${PIOASM_BINARY_DIR}/pioasm.exe)
  34. else()
  35. set(Pioasm_EXECUTABLE ${PIOASM_BINARY_DIR}/pioasm)
  36. endif()
  37. if(NOT TARGET ${Pioasm_TARGET})
  38. # message("Adding executable ${Pioasm_Target} in ${CMAKE_CURRENT_LIST_DIR}")
  39. add_executable(${Pioasm_TARGET} IMPORTED)
  40. endif()
  41. set_property(TARGET ${Pioasm_TARGET} PROPERTY IMPORTED_LOCATION
  42. ${Pioasm_EXECUTABLE})
  43. # message("EXE is ${Pioasm_EXECUTABLE}")
  44. add_dependencies(${Pioasm_TARGET} ${PioasmBuild_TARGET})
  45. set(Pioasm_FOUND 1)
  46. endif()