CMake添加-D_DEBUG宏

Linux下Debug版不会自动添加 _DEBUG宏,只有NDEBUG宏可用。


cmake ../src _DCMAKE_BUILD_TYPE=Debug -D_DEBUG

会报错: -D_DEBUG should be: VAR:type=value

需要-D_DEBUG=1.


改为在CMakeLists.txt中添加:

if (CMAKE_BUILD_TYPE STREQUAL Debug)

    add_definitions(

        -D_DEBUG

    )

endif ()


cmake_minimum_required(VERSION 2.8.3) project(fast_livo) set(CMAKE_BUILD_TYPE "Release") message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Set common compile options set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fexceptions") # Specific settings for Debug build set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") # Detect CPU architecture message(STATUS "Current CPU architecture: ${CMAKE_SYSTEM_PROCESSOR}") # Specific settings for Release build if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64|ARM|AARCH64)") if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") # 64-bit ARM optimizations (e.g., RK3588 and Jetson Orin NX) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -mcpu=native -mtune=native -ffast-math") message(STATUS "Using 64-bit ARM optimizations: -O3 -mcpu=native -mtune=native -ffast-math") else() # 32-bit ARM optimizations with NEON support set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -mcpu=native -mtune=native -mfpu=neon -ffast-math") message(STATUS "Using 32-bit ARM optimizations: -O3 -mcpu=native -mtune=native -mfpu=neon -ffast-math") endif() add_definitions(-DARM_ARCH) else() # x86-64 (Intel/AMD) optimizations set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -mtune=native -funroll-loops") #-flto message(STATUS "Using general x86 optimizations: -O3 -march=native -mtune=native -funroll-loops") add_definitions(-DX86_ARCH) endif() # Define project root directory add_definitions(-DROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\") # Detect CPU core count for potential multithreading optimization include(ProcessorCount) ProcessorCount(N) message(STATUS "Processor count: ${N}") # Set the number of cores for multithreading if(N GREATER 4) math(EXPR PROC_NUM "4") add_definitions(-DMP_EN -DMP_PROC_NUM=${PROC_NUM}) message(STATUS "Multithreading enabled. Cores: ${PROC_N
最新发布
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值