Skip to content

Commit

Permalink
lestarch: fpp tools installation checks version
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Nov 4, 2021
1 parent 40b7c6a commit 2e16638
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 42 deletions.
4 changes: 2 additions & 2 deletions cmake/fpp-download/CMakeLists.fpp.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ project(fpp-download NONE)
include(ExternalProject)
ExternalProject_Add(fpp-tools
GIT_REPOSITORY https://github.com/fprime-community/fpp
GIT_TAG 6b1b39634c40f76641287c5c2221b937bc97e058
GIT_TAG ${FPP_VERSION}
SOURCE_DIR "${CMAKE_BINARY_DIR}/fpp-tools/src"
BINARY_DIR "${CMAKE_BINARY_DIR}/fpp-tools/bin"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "${CMAKE_BINARY_DIR}/fpp-tools/src/compiler/install"
INSTALL_COMMAND "${CMAKE_BINARY_DIR}/fpp-tools/src/compiler/install" "${FPP_TOOLS_PATH}"
TEST_COMMAND ""
)
2 changes: 1 addition & 1 deletion cmake/fpp-download/CMakeLists.sbt.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(ExternalProject)
ExternalProject_Add(sbt
URL https://github.com/sbt/sbt/releases/download/v1.5.5/sbt-1.5.5.zip
DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/sbt-download"
SOURCE_DIR "${CMAKE_BINARY_DIR}/sbt"
SOURCE_DIR "${FPP_TOOLS_PATH}/sbt"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
Expand Down
99 changes: 74 additions & 25 deletions cmake/fpp-download/fpp.cmake
Original file line number Diff line number Diff line change
@@ -1,37 +1,86 @@
message(STATUS "Searching/installing for fpp-tools")
find_program(FPP_DEPEND fpp-depend)
find_program(FPP_TO_XML fpp-to-xml)
find_program(FPP_TO_CPP fpp-to-cpp)
find_program(FPP_LOCATE_DEFS fpp-locate-defs)
####
# fpp.cmake:
#
# A setup to install fpp tool suite automatically as part of the CMake run. If the user wants to avoid this, the user
# should install FPP on the system path and that will be used.
####
set(FPP_VERSION 0d7c587898ddb7a672775dbd2efe55d4e42051da)
set(FPP_TOOLS_PATH "${CMAKE_BINARY_DIR}/fpp-tools-install" CACHE PATH "Installation path for fpp tools")

####
# locate_fpp_tools:
#
# Locates the fpp tool suite and sets FPP_FOUND if the right version of the tools is found. It will look first to the
# above install location and then to the system path as a fallback.
####
function(locate_fpp_tools NO_DEFAULTS)
set(FPP_RE_MATCH "(v[0-9].[0-9].[0-9]) commit ([a-f0-9]+)")
# Loop through each tool, looking if it was found and check the version
foreach(TOOL FPP_DEPEND FPP_TO_XML FPP_TO_CPP FPP_LOCATE_DEFS)
string(TOLOWER ${TOOL} PROGRAM)
string(REPLACE "_" "-" PROGRAM "${PROGRAM}")

# Clear any previous version of this find and search in this order: install dir, system path
unset(${TOOL} CACHE)
find_program(${TOOL} ${PROGRAM} PATHS ${FPP_TOOLS_PATH} NO_DEFAULT_PATH)
find_program(${TOOL} ${PROGRAM} PATHS ${FPP_TOOLS_PATH})

# If the tool exists, check the version
if (${TOOL})
execute_process(COMMAND ${${TOOL}} --help OUTPUT_VARIABLE OUTPUT_TEXT)
if (OUTPUT_TEXT MATCHES "${FPP_RE_MATCH}")
if ("${CMAKE_MATCH_1}" STREQUAL "${FPP_VERSION}" OR "${CMAKE_MATCH_2}" STREQUAL "${FPP_VERSION}")
continue()
endif()
message(STATUS "[fpp-tools] ${${TOOL}} version ${CMAKE_MATCH_0} not expected version ${FPP_VERSION}")
endif()
endif()
set(FPP_FOUND False PARENT_SCOPE)
return()
endforeach()
set(FPP_FOUND True PARENT_SCOPE)
message(STATUS "[fpp-tools] fpp-depend found at: ${FPP_DEPEND}")
message(STATUS "[fpp-tools] fpp-to-xml found at: ${FPP_TO_XML}")
message(STATUS "[fpp-tools] fpp-to-cpp found at: ${FPP_TO_CPP}")
message(STATUS "[fpp-tools] fpp-locate-defs found at: ${FPP_LOCATE_DEFS}")
endfunction(locate_fpp_tools)


message(STATUS "[fpp-tools] Searching for fpp-tools")
locate_fpp_tools(False)
# Download and unpack googletest at configure time if it doesn't exit already
if (NOT FPP_DEPEND OR NOT FPP_TO_XML OR NOT FPP_TO_CPP OR NOT FPP_LOCATE_DEFS)
if (NOT FPP_FOUND)
make_directory(${FPP_TOOLS_PATH})
include("${CMAKE_CURRENT_LIST_DIR}/sbt.cmake")
message(STATUS "[fpp-tools] Installing new tools to ${FPP_TOOLS_PATH}, this will take a few minutes")
configure_file("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.fpp.txt.in" fpp-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fpp-download )
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fpp-download
OUTPUT_QUIET
ERROR_VARIABLE ERROR_OUT
)
if(result)
message(FATAL_ERROR "CMake step for fpp failed: ${result}")
message(FATAL_ERROR "Download step for fpp failed: ${result}\n${ERROR_OUT}")
endif()
# Cached JAVA and sbt items
find_program(JAVA java)
find_program(SBT sbt)
get_filename_component(JAVA_PATH "${JAVA}" DIRECTORY)
get_filename_component(SBT_PATH "${SBT}" DIRECTORY)

execute_process(COMMAND ${CMAKE_COMMAND} -E env PATH="${JAVA_PATH}:${SBT_PATH}:$ENV{PATH}"
${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fpp-download )
execute_process(
COMMAND ${CMAKE_COMMAND} -E env PATH="${JAVA_PATH}:${SBT_PATH}:$ENV{PATH}" ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fpp-download
OUTPUT_QUIET
ERROR_VARIABLE ERROR_OUT
)
if(result)
message(FATAL_ERROR "Build step for fpp failed: ${result}")
message(FATAL_ERROR "Build step for fpp failed: ${result}\n${ERROR_OUT}")
endif()
locate_fpp_tools(True)
if (NOT FPP_FOUND)
message(FATAL_ERROR "[fpp-tools] Failed to install fpp-tools version ${FPP_VERSION}")
endif()
find_program(FPP_DEPEND fpp-depend PATH ${CMAKE_BINARY_DIR}/fpp-tools/src/compiler/bin/)
find_program(FPP_TO_XML fpp-to-xml PATH ${CMAKE_BINARY_DIR}/fpp-tools/src/compiler/bin/)
find_program(FPP_TO_CPP fpp-to-cpp PATH ${CMAKE_BINARY_DIR}/fpp-tools/src/compiler/bin/)
find_program(FPP_LOCATE_DEFS fpp-locate-defs PATH ${CMAKE_BINARY_DIR}/fpp-tools/src/compiler/bin/)
endif()
message(STATUS "fpp-depend found at: ${FPP_DEPEND}")
message(STATUS "fpp-to-xml found at: ${FPP_TO_XML}")
message(STATUS "fpp-to-cpp found at: ${FPP_TO_CPP}")
message(STATUS "fpp-locate-defs found at: ${FPP_LOCATE_DEFS}")
endif()
35 changes: 21 additions & 14 deletions cmake/fpp-download/sbt.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
message(STATUS "Searching/installing for sbt")
message(STATUS "[fpp-tools] Searching for sbt")
find_program(SBT sbt)
# Download and unpack googletest at configure time if it doesn't exit already
if (SBT STREQUAL "SBT-NOTFOUND" )
if (NOT SBT)
message(STATUS "[fpp-tools] Installing sbt, this will take a few minutes")
configure_file("${CMAKE_CURRENT_LIST_DIR}/CMakeLists.sbt.txt.in" sbt-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sbt-download )
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sbt-download
OUTPUT_QUIET
ERROR_VARIABLE ERROR_OUT
)
if(result)
message(FATAL_ERROR "CMake step for sbt failed: ${result}")
message(FATAL_ERROR "CMake step for sbt failed: ${result}\n${ERROR_OUT}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sbt-download )
execute_process(
COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sbt-download
OUTPUT_QUIET
ERROR_VARIABLE ERROR_OUT
)
if(result)
message(FATAL_ERROR "Build step for sbt failed: ${result}")
message(FATAL_ERROR "Build step for sbt failed: ${result}\n${ERROR_OUT}")
endif()
find_program(SBT sbt PATH ${CMAKE_BINARY_DIR}/sbt/bin)

find_program(SBT sbt PATH ${FPP_TOOLS_PATH}/sbt/bin)
endif()
message(STATUS "sbt found at: ${SBT}")

message(STATUS "[fpp-tools] sbt found at: ${SBT}")
1 change: 1 addition & 0 deletions cmake/target/fpp-locs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(NEEDED_PROPERTIES
CMAKE_DEBUG_OUTPUT
FPRIME_USE_STUBBED_DRIVERS
FPRIME_USE_BAREMETAL_SCHEDULER
FPP_TOOLS_PATH
)
set(FPP_CONFIGS
"${FPRIME_CONFIG_DIR}/AcConstants.fpp"
Expand Down

0 comments on commit 2e16638

Please sign in to comment.