0%

CMake设置编译选项

CMake中设置编译选项

1
2
3
4
5
6
7
8
9
10
11
option(BUILD_VISUALIZATIONS "Build visualization, default OFF" OFF)
message("BUILD_VISUALIZATIONS is ${BUILD_VISUALIZATIONS}")


# 可以跟build type关联
# if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)

if(BUILD_VISUALIZATIONS)
add_definitions(-DBUILD_VISUALIZATIONS)
# target_compile_definitions(${project_name} PRIVATE BUILD_VISUALIZATIONS)
endif()

代码中作为宏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifdef BUILD_VISUALIZATIONS

void visualize_cloud(const cloud_ptr_t& cloud_ptr)
{
std::cout << "visualizations on" << std::endl;
// visualize cloud
}

#else

template <typename... Args>
void visualize_cloud(Args...) {
std::cout << "pass visualizations" << std::endl;
}

#endif

编译时传入参数

1
--cmake-args -DBUILD_VISUALIZATIONS=ON