如何使用忍者在cmake中复制命令行参数? [英] How can I replicate a command line arguments in cmake with ninja?

查看:58
本文介绍了如何使用忍者在cmake中复制命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个android(基于clang)编译器,我想使用该编译器使用CMake编译android项目.与命令行参数能够编译项目,我想用忍者在CMake中复制相同的参数. 有效的命令行代码如下:

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)

此工具链的输出如下:

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

这里存在--sysroot(在底部),而在命令行中我期望根本不添加-isysroot和idirafter参数.我尝试了很多可能性,但没有任何效果.我无法弄清楚哪里做错了.任何帮助将不胜感激.

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.

推荐答案

发布的命令行输出是用于构建单个源文件main.cpp:

The command line output posted is one for building a single source file, main.cpp:

-o CMakeFiles\androidcmakeexample.dir\src\main.cpp.obj

也许您缺少适当的CMAKE_CXX_FLAGS,它是CMake设置,用于指定如何编译C ++源文件.

Perhaps you are missing a proper CMAKE_CXX_FLAGS, which is the CMake setting that specifies how C++ source files are compiled.

尝试将以下内容添加到您的CMakeLists.txt:

Try adding the following to your CMakeLists.txt:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ANDROID_LIBRARY}")

这篇关于如何使用忍者在cmake中复制命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆