I'm having a android (clang based) compiler that i want to use to compile android projects using CMake. with command line arguments am able to compile the project and i want to replicate the same arguments in CMake with Ninja. Command Line Code that is working is as follows :
c:\myproj\backup\bin\myandroidcompiler.exe
-isysroot C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\platforms\android-14\arch-arm
-idirafter =\usr\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++\4.8\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++\4.8\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++\4.8\libs\armeabi-v7a\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\android\native_app_glue
-I c:\myproj\backup\dev\tp\include\android\fmx
-isystem c:\myproj\backup\dev\tp\include
-isystem c:\myproj\backup\dev\tp\include\android\crtl
-isystem c:\myproj\backup\dev\tp\include\android\rtl
-isystem c:\myproj\backup\dev\tp\include\android\fmx
-isystem c:\myproj\backup\dev\tp\include\android\rtl
-g -fno-limit-debug-info -fborland-extensions -fborland-auto-refcount -nobuiltininc -nostdsysteminc -triple thumbv7-none-linux-androideabi -emit-obj -mconstructor-aliases -mrelocation-model pic -pic-level 2 -masm-verbose -target-abi aapcs-linux -target-cpu cortex-a8 -nostdinc++ -fdeprecated-macro -fexceptions -fcxx-exceptions -munwind-tables -mstackrealign -fno-spell-checking -main-file-name hello.cpp -x c++ -std=c++11 -O0 -fmath-errno -tU -o hello.o -dependency-file hello.d -MT hello.o hello.cpp
I am using the following toolchain file :
# compiler
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME ANDROID64)
set(ANDROID_ABI armabi-v7a)
#set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
set(CMAKE_ANDROID_NDK "C:/Users/Public/Documents/Android/AndroidNDK-9c_x86")
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
#initializaing variables
set(SYSROOT_PATH "C:/Users/Public/Documents/Android/AndroidNDK-9c_x86/platforms/android-14/arch-arm")
set(LIBSTDCPP_PATH "C:/Users/Public/Documents/Android/AndroidNDK-9c_x86/sources/cxx-stl/gnu-libstdc++/4.8/include")
set(ARMEABI_V7A_PATH "C:/Users/Public/Documents/Android/AndroidNDK-9c_x86/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include ")
set(NATIVE_APP_GLUE_PATH "C:/Users/Public/Documents/Android/AndroidNDK-9c_x86/sources/android/native_app_glue")
set(LIBRARY_INCLUDE_PATH "=\\usr\\include")
set(ANDROID_FMX_PATH "c:/myproj/backup/dev/tp/include/android/fmx ")
set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -isysroot ${SYSROOT_PATH}")
# Adding the Library Paths
set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -idirafter ${LIBRARY_INCLUDE_PATH}")
set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -idirafter ${LIBSTDCPP_PATH}")
set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -idirafter ${ARMEABI_V7A_PATH}")
set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -idirafter ${NATIVE_APP_GLUE_PATH}")
set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -I ${ANDROID_FMX_PATH}")
#set(ANDROID_LIBRARY "${ANDROID_LIBRARY} -g -fno-limit-debug-info -fborland-extensions -fborland-auto-refcount -nobuiltininc -nostdsysteminc -triple thumbv7-none-linux-androideabi -emit-obj -mconstructor-aliases -mrelocation-model pic -pic-level 2 -masm-verbose -target-abi aapcs-linux -target-cpu cortex-a8 -nostdinc++ -fdeprecated-macro -fexceptions -fcxx-exceptions -munwind-tables -mstackrealign -fno-spell-checking")
add_definitions("--sysroot=${SYSROOT_PATH}")
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
include_directories(SYSTEM "c:/myproj/backup/dev/tp/include")
include_directories(SYSTEM "c:/myproj/backup/dev/tp/include/android/crtl")
include_directories(SYSTEM "c:/myproj/backup/dev/tp/include/android/rtl")
include_directories(SYSTEM "c:/myproj/backup/dev/tp/include/android/fmx")
# setting the link library flag
#set(link_flags ${ANDROID_LIBRARY})
# Setting the Link Library Path in flag
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ${ANDROID_LIBRARY})
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${ANDROID_LIBRARY})
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ANDROID_LIBRARY}" CACHE INTERNAL "" FORCE)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ANDROID_LIBRARY}" CACHE INTERNAL "" FORCE)
# sysroot location
#set(MYSYSROOT /path/to/sysroots/cortexa7-vfp-neon-telechips-linux-gnueabi)
# compiler/linker flags
#add_definitions("--sysroot=${SYSROOT_PATH}")
#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${SYSROOT_PATH}" CACHE INTERNAL "" FORCE)
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${SYSROOT_PATH}" CACHE INTERNAL "" FORCE)
# cmake built-in settings to use find_xxx() functions
#set(CMAKE_FIND_ROOT_PATH ${SYSROOT_PATH})
# specify the cross compiler
SET(CMAKE_C_COMPILER "C:/myproj/Backup/dev/tp/bin/myandroidcompiler.exe")
#SET(CMAKE_C_COMPILER "clang")
#SET(CMAKE_C_FLAGS "-v")
#SET(CMAKE_CXX_FLAGS "-v")
SET(CMAKE_CXX_COMPILER "C:/myproj/Backup/dev/tp/bin/myandroidcompiler.exe")
#SET(CMAKE_CXX_COMPILER "clang++")
# Setting the sysroot path for linux system
#set(CMAKE_SYSROOT "${SYSROOT_PATH}")
# adding the -systems variable path
#set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags")
#set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags")
#set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared lnk flags")
link_directories("${LIBRARY_INCLUDE_PATH}")
link_directories("${LIBSTDCPP_PATH}")
link_directories("${ARMEABI_V7A_PATH}")
link_directories("${NATIVE_APP_GLUE_PATH}")
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)
output am getting from this toolchain is as follows :
C:\myproj\Backup\dev\tp\bin\myandroidcompiler.exe -DANDROID -Dandroidcmakeexample_EXPORTS
-isystem c:\myproj\backup\dev\tp\include
-isystem c:\myproj\backup\dev\tp\include\android\crtl
-isystem c:\myproj\backup\dev\tp\include\android\rtl
-isystem c:\myproj\backup\dev\tp\include\android\fmx
-IC:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\android\native_app_glue
-std=c++11 -ffor-scope -fno-exceptions -pipe -ffunction-sections -fdata-sections -ffast-math -pedantic -Werror -Wnon-virtual-dtor -Wsign-promo -fvisibility=hidden -fvisibility-inlines-hidden -Wstrict-null-sentinel -Os -ftree-vectorize -g -fno-limit-debug-info -fborland-extensions -fborland-auto-refcount -nobuiltininc -nostdsysteminc -triple thumbv7-none-linux-androideabi -emit-obj -mconstructor-aliases -mrelocation-model pic -pic-level 2 -masm-verbose
-target-abi aapcs-linux -target-cpu cortex-a8 -nostdinc++ -fdeprecated-macro
-fexceptions -fcxx-exceptions -munwind-tables -mstackrealign -fno-spell-checking -x c++ -std=c++11 -O0 -fmath-errno
--sysroot=C:/Users/Public/Documents/Android/AndroidNDK-9c_x86/platforms/android-14/arch-arm
--sysroot=C:/Users/Public/Documents/Android/AndroidNDK-9c_x86/platforms/android-14/arch-arm
-o CMakeFiles\androidcmakeexample.dir\src\main.cpp.obj -c ..\src\main.cpp
Here --sysroot (present at bottom) is present, while in command line i expected -isysroot and idirafter arguments are not added at all. I have tried many possibilities but nothing worked. I am unable to figure out what am doing wrong. any help would be very much appreciated.
The command line output posted is one for building a single source file,
main.cpp
:-o CMakeFiles\androidcmakeexample.dir\src\main.cpp.obj
Perhaps you are missing a proper
CMAKE_CXX_FLAGS
, which is the CMake setting that specifies how C++ source files are compiled.Try adding the following to your
CMakeLists.txt
:set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ANDROID_LIBRARY}")