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
12if (NOT Pioasm_FOUND)
13    # todo we would like to use pckgconfig to look for it first
14    # see https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
15
16    include(ExternalProject)
17
18    set(PIOASM_SOURCE_DIR ${PICO_SDK_PATH}/tools/pioasm)
19    set(PIOASM_BINARY_DIR ${CMAKE_BINARY_DIR}/pioasm)
20
21    set(PioasmBuild_TARGET PioasmBuild)
22    set(Pioasm_TARGET Pioasm)
23
24    if (NOT TARGET ${PioasmBuild_TARGET})
25        pico_message_debug("PIOASM will need to be built")
26#        message("Adding external project ${PioasmBuild_Target} in ${CMAKE_CURRENT_LIST_DIR}}")
27        ExternalProject_Add(${PioasmBuild_TARGET}
28                PREFIX pioasm
29                SOURCE_DIR ${PIOASM_SOURCE_DIR}
30                BINARY_DIR ${PIOASM_BINARY_DIR}
31                CMAKE_ARGS "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}"
32                CMAKE_CACHE_ARGS "-DPIOASM_EXTRA_SOURCE_FILES:STRING=${PIOASM_EXTRA_SOURCE_FILES}"
33                BUILD_ALWAYS 1 # force dependency checking
34                INSTALL_COMMAND ""
35                )
36    endif()
37
38    if (CMAKE_HOST_WIN32)
39        set(Pioasm_EXECUTABLE ${PIOASM_BINARY_DIR}/pioasm.exe)
40    else()
41        set(Pioasm_EXECUTABLE ${PIOASM_BINARY_DIR}/pioasm)
42    endif()
43    if(NOT TARGET ${Pioasm_TARGET})
44#        message("Adding executable ${Pioasm_Target} in ${CMAKE_CURRENT_LIST_DIR}")
45        add_executable(${Pioasm_TARGET} IMPORTED)
46    endif()
47    set_property(TARGET ${Pioasm_TARGET} PROPERTY IMPORTED_LOCATION
48            ${Pioasm_EXECUTABLE})
49
50#    message("EXE is ${Pioasm_EXECUTABLE}")
51    add_dependencies(${Pioasm_TARGET} ${PioasmBuild_TARGET})
52    set(Pioasm_FOUND 1)
53endif()
54