mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-10-08 00:00:23 -04:00
2.8 KiB
2.8 KiB
Plan: Modernize CMake
See also: RECOMMENDATIONS.md | PLAN.md
Current State
cmake_minimum_required(VERSION 2.8.12)— from 2013- Uses
-std=c++0x(draft C++11) instead of proper standard setting - Global
include_directories(),ADD_DEFINITIONS(),link_libraries()instead of target-specific - Deprecated
CMAKE_CREATE_WIN32_EXE,LINK_FLAGS,SOURCE_GROUP REGULAR_EXPRESSION - Stray comma in
CMAKE_OSX_DEPLOYMENT_TARGETassignment
Implementation Plan
Phase 1: Minimum viable modernization
- Bump
cmake_minimum_required(VERSION 3.14...3.28)— enables modern policies while allowing newer CMake. - Replace
ADD_DEFINITIONS( -std=c++0x -pthread )with:target_compile_features(CubicSDR PRIVATE cxx_std_14) find_package(Threads REQUIRED) target_link_libraries(CubicSDR PRIVATE Threads::Threads) - Fix the stray comma on the
CMAKE_OSX_DEPLOYMENT_TARGETline:SET(CMAKE_OSX_DEPLOYMENT_TARGET, "10.9")→set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9"). - Replace
set(CMAKE_CREATE_WIN32_EXE ...)with:set_target_properties(CubicSDR PROPERTIES WIN32_EXECUTABLE TRUE) target_link_options(CubicSDR PRIVATE /SUBSYSTEM:WINDOWS /ENTRY:"mainCRTStartup")
Phase 2: Target-specific commands
- Replace all
include_directories(...)withtarget_include_directories(CubicSDR PRIVATE ...). - Replace all
ADD_DEFINITIONS(...)withtarget_compile_definitions(CubicSDR PRIVATE ...). - Replace
link_libraries(${HAMLIB_LIBRARY})withtarget_link_libraries(CubicSDR PRIVATE ${HAMLIB_LIBRARY}). - Replace
set_target_properties(... LINK_FLAGS ...)withtarget_link_options().
Phase 3: Advanced modernization (optional, future)
- Replace
include(${wxWidgets_USE_FILE})with imported targets (requires wxWidgets 3.2+). - Replace
SOURCE_GROUP(... REGULAR_EXPRESSION ...)withsource_group(TREE ...). - Consider bumping minimum to CMake 3.16+ for broader modern feature access.
Verification Criteria
cmake_minimum_requiredversion is 3.14 or higher.cmake -B buildconfigures without errors on MSVC, GCC, and Clang.- Build produces a working executable with no regressions.
- No global
include_directories(),ADD_DEFINITIONS(), orlink_libraries()remain (all are target-specific). - The stray comma on the
CMAKE_OSX_DEPLOYMENT_TARGETline is fixed.
Rollback Strategy
This is a high-touch change to a single file. If the build breaks:
git revertthe commit to restore the originalCMakeLists.txt.- The original CMake 2.8 patterns are functional on all platforms — the revert is safe.
- If only Phase 2 causes issues (e.g., a missed
include_directories), consider doing Phase 1 alone first and verifying before proceeding.
Files to Modify
| File | Action |
|---|---|
CMakeLists.txt |
All phases |