Skip to content

Commit

Permalink
Added cmake toolchain arm support. (#350)
Browse files Browse the repository at this point in the history
This PR only adds cmake toolchain files for ARM. NAME/COMMAND stuff is so CMAKE_CROSSCOMPILING_EMULATOR is used. The message() is to prevent a warning about unused variable when specifying CMAKE_TOOLCHAIN_FILE.
  • Loading branch information
nmoinvaz authored and Dead2 committed Jun 4, 2019
1 parent 3e6ea19 commit ef3edcb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ else()
endif()
message(STATUS "Architecture: ${ARCH}")

if(CMAKE_TOOLCHAIN_FILE)
message(STATUS "Using cmake toolchain: ${CMAKE_TOOLCHAIN_FILE}")
endif()

option (WITH_GZFILEOP "Compile with support for gzFile related functions" OFF)
option (ZLIB_COMPAT "Compile with zlib compatible API" OFF)
if (ZLIB_COMPAT)
Expand Down Expand Up @@ -807,7 +811,7 @@ if (ZLIB_ENABLE_TESTS)
enable_testing()
add_executable(example test/example.c)
target_link_libraries(example zlib)
add_test(example example${CMAKE_EXECUTABLE_SUFFIX})
add_test(NAME example COMMAND example${CMAKE_EXECUTABLE_SUFFIX})

add_executable(minigzip test/minigzip.c)
target_link_libraries(minigzip zlib)
Expand All @@ -816,7 +820,7 @@ if (ZLIB_ENABLE_TESTS)
add_executable(example64 test/example.c)
target_link_libraries(example64 zlib)
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
add_test(example64 example64${CMAKE_EXECUTABLE_SUFFIX})
add_test(NAME example64 COMMAND example64${CMAKE_EXECUTABLE_SUFFIX})

add_executable(minigzip64 test/minigzip.c)
target_link_libraries(minigzip64 zlib)
Expand Down
26 changes: 26 additions & 0 deletions cmake/toolchain-aarch64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_SYSTEM_VERSION 1)

message(STATUS "Using cross-compile toolchain: ${CROSS_COMPILE_TOOLCHAIN}")

set(CMAKE_C_COMPILER_TARGET "aarch64-linux-gnu")
set(CMAKE_CXX_COMPILER_TARGET "aarch64-linux-gnu")

set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64 -L /usr/${CMAKE_C_COMPILER_TARGET}/)

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

find_program(C_COMPILER_FULL_PATH ${CMAKE_C_COMPILER_TARGET}-gcc)
if(NOT C_COMPILER_FULL_PATH)
message(FATAL_ERROR "Cross-compiler ${CMAKE_C_COMPILER_TARGET}-gcc not found")
endif()
set(CMAKE_C_COMPILER ${C_COMPILER_FULL_PATH})

find_program(CXX_COMPILER_FULL_PATH ${CMAKE_C_COMPILER_TARGET}-g++)
if(CXX_COMPILER_FULL_PATH)
set(CMAKE_CXX_COMPILER ${CXX_COMPILER_FULL_PATH})
endif()
24 changes: 24 additions & 0 deletions cmake/toolchain-arm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_VERSION 1)

message(STATUS "Using cross-compile toolchain: ${CMAKE_C_COMPILER_TARGET}")

set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CROSSCOMPILING_EMULATOR qemu-arm -L /usr/${CMAKE_C_COMPILER_TARGET}/)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

find_program(C_COMPILER_FULL_PATH ${CMAKE_C_COMPILER_TARGET}-gcc)
if(NOT C_COMPILER_FULL_PATH)
message(FATAL_ERROR "Cross-compiler ${CMAKE_C_COMPILER_TARGET}-gcc not found")
endif()
set(CMAKE_C_COMPILER ${C_COMPILER_FULL_PATH})

find_program(CXX_COMPILER_FULL_PATH ${CMAKE_C_COMPILER_TARGET}-g++)
if(CXX_COMPILER_FULL_PATH)
set(CMAKE_CXX_COMPILER ${CXX_COMPILER_FULL_PATH})
endif()

0 comments on commit ef3edcb

Please sign in to comment.