我怎样才能复制的命令行参数的cmake与忍者?(How can I replicate a comm

2019-09-28 13:45发布

我有一个机器人(基于铛)编译器,我想用它来编译使用CMake的机器人项目。 用命令行参数是能够编译项目,我希望复制C进行相同的参数与忍者。 正在工作的命令行代码如下:

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

我使用以下工具链文件:

# 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参数根本不被加入。 我已经尝试了许多可能性,但没有奏效。 我无法弄清楚什么做错了。 任何帮助将是非常赞赏。

Answer 1:

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

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

也许你缺少一个适当的CMAKE_CXX_FLAGS ,这是CMake的设置,指定C ++源文件编译方式。

尝试添加以下到您CMakeLists.txt

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



文章来源: How can I replicate a command line arguments in cmake with ninja?