From 79c82236557462fdae4761db8bf072d601e267b2 Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 11 Jan 2024 14:23:40 +0100 Subject: [PATCH 1/2] Only build samples if project is top level --- CMakeLists.txt | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d627a0..f31e6b2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,17 @@ cmake_minimum_required(VERSION 3.0) project(livox_sdk) -set(CMAKE_CXX_STANDARD 11) - message(STATUS "main project dir: " ${PROJECT_SOURCE_DIR}) +# This variable is set by project() in CMake 3.21+ +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}" PROJECT_IS_TOP_LEVEL) + +if(PROJECT_IS_TOP_LEVEL) + option(shared_DEVELOPER_MODE "Enable developer mode" OFF) +endif() + +set(CMAKE_CXX_STANDARD 11) + if (CMAKE_CROSSCOMPILING) set(THREADS_PTHREAD_ARG "PLEASE_FILL_OUT-FAILED_TO_RUN" @@ -16,12 +23,16 @@ if (UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") endif(UNIX) +# Always build the core SDK library add_subdirectory(sdk_core sdk_core) -add_subdirectory(sample/hub) -add_subdirectory(sample/lidar) -add_subdirectory(sample/hub_lvx_file) -add_subdirectory(sample/lidar_lvx_file) -add_subdirectory(sample_cc/hub) -add_subdirectory(sample_cc/lidar) -add_subdirectory(sample_cc/trouble_shooting) -add_subdirectory(sample_cc/lidar_utc_sync) +# Only build the samples if this is the top-level project +if(PROJECT_IS_TOP_LEVEL) + add_subdirectory(sample/hub) + add_subdirectory(sample/lidar) + add_subdirectory(sample/hub_lvx_file) + add_subdirectory(sample/lidar_lvx_file) + add_subdirectory(sample_cc/hub) + add_subdirectory(sample_cc/lidar) + add_subdirectory(sample_cc/trouble_shooting) + add_subdirectory(sample_cc/lidar_utc_sync) +endif() \ No newline at end of file From 2d782aee6c137344e86f4685749171a0a0bc98df Mon Sep 17 00:00:00 2001 From: Patrick Kappl Date: Thu, 11 Jan 2024 14:23:50 +0100 Subject: [PATCH 2/2] Make unnecessarily hard-coded flags optional --- sdk_core/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk_core/CMakeLists.txt b/sdk_core/CMakeLists.txt index 54b0cc0..9964be3 100644 --- a/sdk_core/CMakeLists.txt +++ b/sdk_core/CMakeLists.txt @@ -30,10 +30,13 @@ else(WIN32) set(PLATFORM unix) endif (WIN32) -target_compile_options(${SDK_LIBRARY} +# Warnings are only for developers +if(shared_DEVELOPER_MODE) + target_compile_options(${SDK_LIBRARY} PRIVATE $<$:-Wall -Werror -Wno-c++11-long-long> PRIVATE $<$:-Wno-unknown-pragmas -Wall -Werror -Wno-c++11-long-long> PRIVATE $<$:-Wno-unknown-pragmas -Wall -Werror -Wno-c++11-long-long>) +endif() target_sources(${SDK_LIBRARY} PRIVATE