[CMake] cross-compiling for arm
Rolf Eike Beer
eike at sf-mail.de
Fri Sep 16 17:42:41 EDT 2016
Gunter, Walter E wrote:
> I setup the Main CMakeLists.txt to cross_compile using an arm toolchain:
>
> cmake_minimum_required(VERSION 3.2)
>
> project(enterprise CXX)
>
> set(CMAKE_SYSTEM_NAME Linux)
> set(CMAKE_CXX_COMPILER
> /opt/toolchains/arm-2008q3/bin/arm-none-linux-gnueabi-g++)
> set(CMAKE_SYSTEM_PROCESSOR arm)
>
> set(CMAKE_AR /opt/toolchains/arm-2008q3/bin/arm-none-linux-gnueabi-ar)
> set(CMAKE_FIND_ROOT_PATH /mnt/root)
>
> 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)
>
> set(COMPILE_FLAGS "-lrt -Wall -lpthread")
>
> find_package(Threads)
>
> add_subdirectory(src)
>
> if(CMAKE_CROSSCOMPILING)
> message("I should be cross compiling: ")
> endif()
>
> #find_package(GTest REQUIRED)
>
> --------------------------------------------------------
>
> I made some changes to my cmakelists.txt in my src file :
>
> set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}
> *list of files*.cpp
> Mainfile.cpp
> Mycan.cpp #this one references the linux/can.h
> )
>
> include_directories("../includes")
> set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX)
This is not needed, CMake will automatically detect this.
> add_executable(enterprise ${SOURCES})
> target_link_libraries(enterprise ${CMAKE_THREAD_LIBS_INIT} pthread)
pthread is not needed here. If CMAKE_THREAD_LIBS_INIT is empty you probably
have a problem already. Also you should do
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
before find_package(Threads), and ideally
target_link_libraries(enterprise Threads::Threads)
afterwards, as this will also add the -pthread flag to compilation.
I still doubt that you properly use a toolchain file (i.e. "cmake -D
CMAKE_TOOLCHAIN_FILE=my_arm_stuff.cmake …" in a clean build dir).
Eike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160916/19d529fe/attachment.sig>
More information about the CMake
mailing list