Skip to content

Commit

Permalink
Create Raspbian cross-compiler (#3)
Browse files Browse the repository at this point in the history
* Create Raspbian cross-compiler

* Update CMakeLists.txt

* Update main.yml
  • Loading branch information
mcm001 authored Apr 21, 2022
1 parent e542dcf commit d8cff0d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 10 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ jobs:
- run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
if: matrix.artifact-name != 'Raspbian'
- run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../CMake/arm-pi-gnueabihf.toolchain.cmake
cmake --build build
if: matrix.artifact-name == 'Raspbian'
# Upload client artifact.
- uses: actions/upload-artifact@master
Expand All @@ -86,13 +91,11 @@ jobs:
steps:
- uses: actions/download-artifact@v2

- uses: pyTooling/Actions/releaser@r0
- name: Release
uses: softprops/action-gh-release@v1
if: github.event_name == 'push'
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: 'Dev'
rm: true
files: |
**/*.dll
**/*.so
**/*.dylib
if: github.event_name == 'push'
**/*.dylib
80 changes: 80 additions & 0 deletions CMake/arm-pi-gnueabihf.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# if(COMMAND toolchain_save_config)
# return() # prevent recursive call
# endif()

set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
set(GNU_MACHINE "arm-raspbian10-linux-gnueabi" CACHE STRING "GNU compiler triple")
set(SOFTFP no)
set(FLOAT_ABI_SUFFIX "hf")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSROOT "$ENV{ROOTFS_DIR}")

# include("$ENV{ROOTFS_DIR}/usr/src/opencv-4.5.2/platforms/linux/gnu.toolchain.cmake")

if(NOT DEFINED CMAKE_C_COMPILER)
find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
else()
#message(WARNING "CMAKE_C_COMPILER=${CMAKE_C_COMPILER} is defined")
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
else()
#message(WARNING "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is defined")
endif()
if(NOT DEFINED CMAKE_LINKER)
find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
else()
#message(WARNING "CMAKE_LINKER=${CMAKE_LINKER} is defined")
endif()
if(NOT DEFINED CMAKE_AR)
find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
else()
#message(WARNING "CMAKE_AR=${CMAKE_AR} is defined")
endif()

if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
endif()

set(ARM_LINKER_FLAGS "-Wl,-rpath -Wl,$ENV{ROOTFS_DIR}/opt/vc/lib")

if(NOT DEFINED CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "" CACHE INTERNAL "")
set(CMAKE_C_FLAGS "" CACHE INTERNAL "")
set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "")

set(CMAKE_CXX_FLAGS "-isystem $ENV{ROOTFS_DIR}/usr/include/arm-linux-gnueabihf ${CMAKE_CXX_FLAGS} -Wno-psabi")
set(CMAKE_C_FLAGS "-isystem $ENV{ROOTFS_DIR}/usr/include/arm-linux-gnueabihf ${CMAKE_C_FLAGS} -Wno-psabi")
set(CMAKE_SHARED_LINKER_FLAGS "${ARM_LINKER_FLAGS} -rdynamic ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${ARM_LINKER_FLAGS} -rdynamic ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${ARM_LINKER_FLAGS} -rdynamic ${CMAKE_EXE_LINKER_FLAGS}")
else()
#message(WARNING "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' is defined")
endif()

if(USE_NEON)
message(WARNING "You use obsolete variable USE_NEON to enable NEON instruction set. Use -DENABLE_NEON=ON instead." )
set(ENABLE_NEON TRUE)
elseif(USE_VFPV3)
message(WARNING "You use obsolete variable USE_VFPV3 to enable VFPV3 instruction set. Use -DENABLE_VFPV3=ON instead." )
set(ENABLE_VFPV3 TRUE)
endif()

set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${ARM_LINUX_SYSROOT})

if(EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CUDA_TOOLKIT_ROOT_DIR})
endif()

set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
ARM_LINUX_SYSROOT
ENABLE_NEON
ENABLE_VFPV3
CUDA_TOOLKIT_ROOT_DIR
)

# toolchain_save_config()
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if(POLICY CMP0077)
endif()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF)
option(BUILD_OPENCV_DEMO "Build OpenCV Demo" OFF)

if (ASAN)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} \
Expand Down Expand Up @@ -186,14 +187,12 @@ target_link_libraries(apriltag_demo apriltag)

# opencv_demo
find_package(OpenCV COMPONENTS core imgproc videoio highgui QUIET)
if(OpenCV_FOUND)
if(BUILD_OPENCV_DEMO)
add_executable(opencv_demo example/opencv_demo.cc)
target_link_libraries(opencv_demo apriltag ${OpenCV_LIBRARIES})
set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11)
install(TARGETS opencv_demo RUNTIME DESTINATION bin)
else()
message(WARNING "OpenCV not found: Not building demo")
endif(OpenCV_FOUND)
endif(BUILD_OPENCV_DEMO)

# install example programs
install(TARGETS apriltag_demo RUNTIME DESTINATION bin)

0 comments on commit d8cff0d

Please sign in to comment.