From cab98936ddeb40e09ed30adca419701e0186ee8a Mon Sep 17 00:00:00 2001 From: crosstyan Date: Thu, 29 Jan 2026 17:54:21 +0800 Subject: [PATCH] Refactor CMake configuration: separate RPT core library into its own CMakeLists.txt and streamline SWIG integration --- CMakeLists.txt | 3 ++- rpt/CMakeLists.txt | 24 ++++++++++++++++++++++++ swig/CMakeLists.txt | 17 ++++------------- 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 rpt/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 541ca72..99bb16e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,5 +12,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -# Add the SWIG subdirectory +# Add subdirectories +add_subdirectory(rpt) add_subdirectory(swig) diff --git a/rpt/CMakeLists.txt b/rpt/CMakeLists.txt new file mode 100644 index 0000000..53820df --- /dev/null +++ b/rpt/CMakeLists.txt @@ -0,0 +1,24 @@ +# RPT Core Library + +set(RPT_SOURCES + camera.cpp + interface.cpp + triangulator.cpp +) + +add_library(rpt_core STATIC ${RPT_SOURCES}) + +target_include_directories(rpt_core PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_options(rpt_core PRIVATE + -fPIC + -march=native + -Wall +) + +# Release mode optimizations +target_compile_options(rpt_core PRIVATE + $<$:-O3;-flto=auto> +) diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index db6eace..4081398 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -7,19 +7,11 @@ find_package(Python3 REQUIRED COMPONENTS Development) # Include SWIG macros include(UseSWIG) -# Compiler flags (matching original Makefile) -set(RPT_COMPILE_FLAGS -fPIC -O3 -march=native -Wall -flto=auto) +# Compiler flags for SWIG wrapper +set(RPT_COMPILE_FLAGS -fPIC -march=native -Wall) -# Create static library from rpt sources -set(RPT_SOURCES - ${CMAKE_SOURCE_DIR}/rpt/camera.cpp - ${CMAKE_SOURCE_DIR}/rpt/interface.cpp - ${CMAKE_SOURCE_DIR}/rpt/triangulator.cpp -) - -add_library(rpt_core STATIC ${RPT_SOURCES}) -target_include_directories(rpt_core PUBLIC ${CMAKE_SOURCE_DIR}/rpt) -target_compile_options(rpt_core PRIVATE ${RPT_COMPILE_FLAGS}) +# Release mode optimizations +list(APPEND RPT_COMPILE_FLAGS $<$:-O3;-flto=auto>) # SWIG interface set_property(SOURCE rpt.i PROPERTY CPLUSPLUS ON) @@ -47,6 +39,5 @@ set_target_properties(rpt PROPERTIES # Ensure SWIG can find headers target_include_directories(rpt PRIVATE - ${CMAKE_SOURCE_DIR}/rpt ${Python3_INCLUDE_DIRS} )