运行CMake命令,Ctrl-Shft-P -> CMake: Delete Cache and Reconfigure,就可从VS Code的OUTPUT窗口(在下方)的CMake Configure信息:
[main] Configuring project: test_isa
[driver] Removing /home/x10/esm7000/app/test_isa/build/CMakeCache.txt
[driver] Removing /home/x10/esm7000/app/test_isa/build/CMakeFiles
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=/home/x10/esm7000/app/test_isa/esm7000_toolchain.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/home/x10/esm7000/toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER:FILEPATH=/home/x10/esm7000/toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -S/home/x10/esm7000/rootfs/usr/app/test_isa -B/home/x10/esm7000/rootfs/usr/app/test_isa/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 6.2.0
[cmake] -- The CXX compiler identification is GNU 6.2.0
[cmake] -- Check for working C compiler: /home/x10/esm7000/toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
[cmake] -- Check for working C compiler: /home/x10/esm7000/toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -- works
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Check for working CXX compiler: /home/x10/esm7000/toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++
[cmake] -- Check for working CXX compiler: /home/x10/esm7000/toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -- works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/x10/esm7000/app/test_isa/build
[cmakefileapi-driver] This version of CMake does not support the "toolchains" object kind. Compiler paths will be determined by reading CMakeCache.txt.
CMake配置成功后,点击VS Code下方状态栏上的Build键,即可对应用进行交叉编译:
[main] Building folder: test_isa
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/x10/esm7000/app/test_isa/build --config Debug --target all -j 10 --
[build] Scanning dependencies of target test_isa
[build] [ 50%] Building CXX object CMakeFiles/test_isa.dir/main.cpp.o
[build] [100%] Linking CXX executable test_isa
[build] [100%] Built target test_isa
[build] Build finished with exit code 0
cmake_minimum_required(VERSION 3.1.0)
set(PRJNAME test_isa)
project(${PRJNAME} VERSION 0.2.0)
# Set the variable CMAKE_CXX_STANDARD to 11
# and the variable CMAKE_CXX_STANDARD_REQUIRED to True
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Use configure_file to configure and copy UserConfig.h.in to UserConfig.h
configure_file(UserConfig.h.in UserConfig.h)
include(CTest)
enable_testing()
set(SOURCEFILES test_isa.cpp isa_api_v3.cpp isa_dma_ext.cpp isa_dma_mmap.cpp)
add_executable(${PRJNAME} ${SOURCEFILES})
# Use target_include_directories to include ${PROJECT_BINARY_DIR}
target_include_directories(${PRJNAME} PRIVATE ${PROJECT_BINARY_DIR})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
点击Build进行编译,可看到多个cpp文件均被正常编译:
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/x10/esm7000/app/test_isa/build --config Release --target all -j 10 --
[build] Scanning dependencies of target test_isa
[build] [ 20%] Building CXX object CMakeFiles/test_isa.dir/isa_dma_ext.cpp.o
[build] [ 40%] Building CXX object CMakeFiles/test_isa.dir/isa_api_v3.cpp.o
[build] [ 60%] Building CXX object CMakeFiles/test_isa.dir/test_isa.cpp.o
[build] [ 80%] Building CXX object CMakeFiles/test_isa.dir/isa_dma_mmap.cpp.o
[build] [100%] Linking CXX executable test_isa
[build] [100%] Built target test_isa
[build] Build finished with exit code 0
让C/C++ IntelliSense正确感知
VS Code的C/C++插件可使编辑器正常感知包含在交叉编译工具里面的目标运行环境。具体做法是通过C/C++命令来进行必要的设置:Ctrl-Shft-P -> C/C++: Edit Configure (UI)。设置完成后,VS Code会自动在.vscode路径在生成c_cpp_properties.json如下: