[问题解决]:CMakeLists.txt 修改默认编译器导致死循环的问题解决
问题描述:
和 add_subdirectory 一起使用时候造成的死循环。
解决方法是,在 project 之前 设置编译器
# HOME CMAKE cmake_minimum_required(VERSION 3.19) set(TOOLCHAIN_DIR /shared/RV1126_1109_20210712/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-g++) set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-gcc) project(testV4l) set(CMAKE_CXX_STANDARD 11) set(LOCAL_DIST /home/shared/Downloads/tk_ipc_deploy_0517/deps/armv7l) set(THIRD_PART_ROOT /home/shared/Downloads/tk_ipc_deploy_0517/tk_ipc_pj/3rd/) # include packaged macro cmake file include(macro.cmake) find_lib("FFMPEG" ${LOCAL_DIST}/ffmpeg-4.3.3 false) find_lib("X264" ${LOCAL_DIST}/x264 true) include_directories( ${FFMPEG_INCLUDE} ${THIRD_PART_ROOT}/concurrentqueue/ ) link_directories( ${FFMPEG_LIB_PATH} ${X264_LIB_PATH} ) msg("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") msg("CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") msg("ffmpeg lib: ${FFMPEG_LIB_PATH}") add_subdirectory(v4l2cam output.v4l2cam) add_executable(testV4l main.cpp)
# 子CMAKE cmake_minimum_required (VERSION 3.10) project (rv1126_v4l2Cam) option(BUILD_FOR_RV1126 "build for platform[rv1126]" OFF) option(BUILD_FOR_RK3399PRO "build for platform[rk3399pro]" OFF) option(BUILD_FOR_X64 "build for platform[x64]" ON) if(BUILD_FOR_RK3399PRO) include("/root/shared/tools/x64/cross/cmakes/rk3399pro_base.cmake") add_definitions(-DV4LCAMERA_PLATFORM_TYPE=1) endif() if(BUILD_FOR_RV1126) # include("/root/shared/tools/x64/cross/cmakes/rv1126_base.cmake") set(TOOLCHAIN_DIR /shared/RV1126_1109_20210712/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-g++) set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-gcc) add_definitions(-DV4LCAMERA_PLATFORM_TYPE=2) endif() if(BUILD_FOR_X64) add_definitions(-DV4LCAMERA_PLATFORM_TYPE=0) endif() option(OPT_LIBYUV_ENABLE "enable libyuv function" OFF) option(OPT_FFMPEG_ENABLE "enable ffmpeg function" ON) option(OPT_LOG_ENABLE "enable log function" OFF) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_BUILD_TYPE Debug) set(3RD_CONCURRENTQUEUE_INC_DIR "/root/shared/local_install/common/headonly/concurrentqueue") set(3RD_INIPARSER_INC_DIR "/root/shared/local_install/common/headonly/ini_parser") set(3RD_SPDLOG_INC_DIR "/root/shared/local_install/common/headonly/spdlog-v1.8.5") if(BUILD_FOR_X64) set(LIBYUV_INSTALL_PREFIX "/root/shared/local_install/x64/ubuntu20.04/libyuv-0.0.1788") set(OPENCV_INSTALL_PREFIX "/root/shared/local_install/x64/ubuntu20.04/opencv-3.4.1_baseworld") set(FFMPEG_INSTALL_PREFIX "/root/shared/local_install/x64/ubuntu20.04/ffmpeg-4.3.1_x264_x265_rtmp") set(3RD_X264_LIB_DIR "/root/shared/local_install/x64/ubuntu20.04/x264-snapshot-20180212-2245-stable/lib") set(3RD_X265_LIB_DIR "/root/shared/local_install/x64/ubuntu20.04/x265_3.2/lib") set(3RD_RTMP_LIB_DIR "/root/shared/local_install/x64/ubuntu20.04/librtmp-2.3/lib") set(LIBYUV_LIB_LINK_LIBS "yuv" "jpeg" ) set(LIBFFMEPG_LIB_LINK_LIBS "avutil" "swresample" "avformat" "avcodec" ) endif() if(BUILD_FOR_RK3399PRO) include("/root/shared/tools/x64/cross/cmakes/rk3399pro_base.cmake") set(LIBYUV_INSTALL_PREFIX "/root/shared/local_install/aarch64/libyuv_no_neon-0.0.1788") set(OPENCV_INSTALL_PREFIX "/root/shared/local_install/aarch64/opencv-3.4.1_baseworld") set(FFMPEG_INSTALL_PREFIX "/root/shared/local_install/aarch64/ffmpeg-4.3.1_x264") set(3RD_X264_LIB_DIR "/root/shared/local_install/aarch64/x264_prebuild/lib") set(3RD_X265_LIB_DIR "") set(3RD_RTMP_LIB_DIR "") set(LIBYUV_LIB_LINK_LIBS "yuv" ) set(LIBFFMEPG_LIB_LINK_LIBS "avutil" "swresample" "avformat" "avcodec" "x264" ) endif() if(BUILD_FOR_RV1126) # include("/root/shared/tools/x64/cross/cmakes/rv1126_base.cmake") set(TOOLCHAIN_DIR /shared/RV1126_1109_20210712/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-g++) set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-gcc) set(LIBYUV_INSTALL_PREFIX "/root/shared/local_install/rv1126/libyuv_no_neon-0.0.1788") set(OPENCV_INSTALL_PREFIX "/root/shared/local_install/rv1126/opencv-3.4.1_baseworld") set(FFMPEG_INSTALL_PREFIX "/root/shared/local_install/rv1126/ffmpeg-4.3.1_x264") set(3RD_X264_LIB_DIR "/root/shared/local_install/rv1126/x264-snapshot-20180212-2245-stable/lib") set(3RD_X265_LIB_DIR "") set(3RD_RTMP_LIB_DIR "") set(LIBYUV_LIB_LINK_LIBS "yuv" ) set(LIBFFMEPG_LIB_LINK_LIBS "avutil" "swresample" "avformat" "avcodec" "x264" ) endif() add_compile_options(-std=c++11) aux_source_directory(./gitSrc/lib/src LIB_SRC) set(LIB_SRC_DIR "${LIB_SRC}" ) set(LIB_INC_DIR "./gitSrc/lib/inc" "${3RD_CONCURRENTQUEUE_INC_DIR}" ) set(LIB_LINK_DIRS ) set(LIB_LINK_LIBS "pthread" ) if(OPT_LOG_ENABLE) add_definitions(-DOPT_LOG_EN=1) set(LIB_INC_DIR "${LIB_INC_DIR}" "${3RD_INIPARSER_INC_DIR}" "${3RD_SPDLOG_INC_DIR}" ) else() add_definitions(-DOPT_LOG_EN=0) endif() if(OPT_LIBYUV_ENABLE) add_definitions(-DOPT_LIBYUV_EN=1) set(LIB_INC_DIR "${LIB_INC_DIR}" "${LIBYUV_INSTALL_PREFIX}/include" ) set(LIB_LINK_DIRS "${LIB_LINK_DIRS}" "${LIBYUV_INSTALL_PREFIX}/lib" ) set(LIB_LINK_LIBS "${LIB_LINK_LIBS}" "${LIBYUV_LIB_LINK_LIBS}" ) else() add_definitions(-DOPT_LIBYUV_EN=0) endif() if(OPT_FFMPEG_ENABLE) add_definitions(-DOPT_FFMPEG_EN=1) set(LIB_INC_DIR "${LIB_INC_DIR}" "${FFMPEG_INSTALL_PREFIX}/include" ) set(LIB_LINK_DIRS "${LIB_LINK_DIRS}" "${FFMPEG_INSTALL_PREFIX}/lib" "${3RD_X264_LIB_DIR}" "${3RD_X265_LIB_DIR}" "${3RD_RTMP_LIB_DIR}" ) set(LIB_LINK_LIBS "${LIB_LINK_LIBS}" "${LIBFFMEPG_LIB_LINK_LIBS}" ) else() add_definitions(-DOPT_FFMPEG_EN=0) endif() include_directories(${LIB_INC_DIR}) link_directories(${LIB_LINK_DIRS}) add_library(${PROJECT_NAME} SHARED ${LIB_SRC_DIR}) target_link_libraries( ${PROJECT_NAME} ${LIB_LINK_LIBS} ) #### demo set(DEMO_SRC_DIR "./gitSrc/demo/src") set(DEMO_SRCS "${DEMO_SRC_DIR}/demo.cpp" ) set(DEMO_INC_DIR "./gitSrc/demo/inc") set(DEMO_LINK_DIRS "${LIB_LINK_DIRS}" ) set(DEMO_LINK_LIBS "${PROJECT_NAME}" ) include_directories(${DEMO_INC_DIR}) link_directories(${DEMO_LINK_DIRS}) add_executable(${PROJECT_NAME}_demo ${DEMO_SRCS}) target_link_libraries( ${PROJECT_NAME}_demo ${DEMO_LINK_LIBS} ) message("v4l2cam")