如何使用忍者在 cmake 中复制命令行参数?
How can I replicate a command line arguments in cmake with ninja?
我有一个 android(基于 clang 的)编译器,我想用它来编译 android 使用 CMake 的项目。使用命令行参数可以编译项目,我想在 CMake 中使用 Ninja 复制相同的参数。
正在运行的命令行代码如下:
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++.8\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++.8\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++.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 参数根本没有添加。我尝试了很多可能性,但没有任何效果。我无法弄清楚做错了什么。非常感谢任何帮助。
发布的命令行输出用于构建单个源文件,main.cpp
:
-o CMakeFiles\androidcmakeexample.dir\src\main.cpp.obj
也许您缺少一个正确的 CMAKE_CXX_FLAGS
,它是指定如何编译 C++ 源文件的 CMake 设置。
尝试将以下内容添加到您的 CMakeLists.txt
:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ANDROID_LIBRARY}")
我有一个 android(基于 clang 的)编译器,我想用它来编译 android 使用 CMake 的项目。使用命令行参数可以编译项目,我想在 CMake 中使用 Ninja 复制相同的参数。 正在运行的命令行代码如下:
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++.8\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++.8\include
-idirafter C:\Users\Public\Documents\Android\AndroidNDK-9c_x86\sources\cxx-stl\gnu-libstdc++.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 参数根本没有添加。我尝试了很多可能性,但没有任何效果。我无法弄清楚做错了什么。非常感谢任何帮助。
发布的命令行输出用于构建单个源文件,main.cpp
:
-o CMakeFiles\androidcmakeexample.dir\src\main.cpp.obj
也许您缺少一个正确的 CMAKE_CXX_FLAGS
,它是指定如何编译 C++ 源文件的 CMake 设置。
尝试将以下内容添加到您的 CMakeLists.txt
:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ANDROID_LIBRARY}")