-
-
Notifications
You must be signed in to change notification settings - Fork 47
fix: replace C++20 designated initializers with C++17 compatible assignments #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,10 +2,19 @@ | |||||||||||||||
| # Img2Num Top-Level (Manages all libs and apps) | ||||||||||||||||
| # ================================================================= | ||||||||||||||||
| cmake_minimum_required(VERSION 3.16) | ||||||||||||||||
| project(Img2Num LANGUAGES CXX) | ||||||||||||||||
| project(Img2NumRootManager LANGUAGES CXX) | ||||||||||||||||
|
|
||||||||||||||||
| set(CMAKE_CXX_STANDARD 17) | ||||||||||||||||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||||||||||||||||
| # Ensure we strictly conform to the C++17 standard | ||||||||||||||||
| # This is important for inter-OS reproducibility | ||||||||||||||||
| set(CMAKE_CXX_EXTENSIONS OFF) | ||||||||||||||||
|
|
||||||||||||||||
| # Reusable flags to ensure good quality code | ||||||||||||||||
| set(IMG2NUM_STRICT_CXX_FLAGS | ||||||||||||||||
| $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>>:-Wpedantic -Werror=pedantic -Werror=c++20-extensions> | ||||||||||||||||
| $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/permissive-> | ||||||||||||||||
|
Comment on lines
+14
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation, line length, and generator expression syntax for strict compiler flags. Line 15 exceeds the 120-character maximum (174 chars) and both lines 15–16 use 4-space indentation instead of the required 2-space. The space-separated compiler flags in the GNU/Clang generator expression must be quoted with the Suggested fix set(IMG2NUM_STRICT_CXX_FLAGS
- $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>>:-Wpedantic -Werror=pedantic -Werror=c++20-extensions>
- $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/permissive->
+ "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>>:SHELL:-Wpedantic -Werror=pedantic -Werror=c++20-extensions>"
+ "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/permissive->"
)Additionally, line 7 sets 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| option(BUILD_PYTHON "Build Python bindings" OFF) | ||||||||||||||||
| option(IMG2NUM_BUILD_EXAMPLES "Build example applications" ON) | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,6 @@ | ||||||||||||||
| # ================================================================= | ||||||||||||||
| # Img2Num Python Bindings | ||||||||||||||
| # ================================================================= | ||||||||||||||
| set(CMAKE_CXX_STANDARD 17) | ||||||||||||||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||||||||||||||
|
|
||||||||||||||
| project(PyImg2Num | ||||||||||||||
| LANGUAGES CXX | ||||||||||||||
| VERSION 0.0.0 | ||||||||||||||
|
|
@@ -12,18 +9,18 @@ project(PyImg2Num | |||||||||||||
| include(CMakePackageConfigHelpers) | ||||||||||||||
| include(GNUInstallDirs) | ||||||||||||||
|
|
||||||||||||||
| set(CMAKE_CXX_STANDARD 17) | ||||||||||||||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||||||||||||||
|
|
||||||||||||||
| set(PYBIND11_FINDPYTHON ON) | ||||||||||||||
| find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy) | ||||||||||||||
| find_package(pybind11 REQUIRED) | ||||||||||||||
|
|
||||||||||||||
| file(GLOB BINDING_SRC | ||||||||||||||
| "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" | ||||||||||||||
| ) | ||||||||||||||
|
Comment on lines
16
to
18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Make source glob reconfiguration-safe. Line 16 uses Suggested fix-file(GLOB BINDING_SRC
- "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
-)
+file(GLOB BINDING_SRC CONFIGURE_DEPENDS
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
+)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| pybind11_add_module(_img2num MODULE ${BINDING_SRC}) | ||||||||||||||
|
|
||||||||||||||
| target_compile_options(_img2num PRIVATE ${IMG2NUM_STRICT_CXX_FLAGS}) | ||||||||||||||
|
|
||||||||||||||
| target_link_libraries(_img2num PRIVATE Img2Num) | ||||||||||||||
|
|
||||||||||||||
| target_include_directories(_img2num PRIVATE | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,7 @@ | ||||||||||||
| # ================================================================= | ||||||||||||
| # Example Console App (C) | ||||||||||||
| # ================================================================= | ||||||||||||
| cmake_minimum_required(VERSION 3.16) | ||||||||||||
| project(Img2NumExample LANGUAGES C) | ||||||||||||
| project(CImg2NumExample_console_c LANGUAGES C) | ||||||||||||
|
|
||||||||||||
| set(CMAKE_C_STANDARD 11) | ||||||||||||
| set(CMAKE_C_STANDARD_REQUIRED ON) | ||||||||||||
|
|
@@ -11,17 +10,19 @@ set(CMAKE_C_STANDARD_REQUIRED ON) | |||||||||||
| set(EXAMPLE_SRC main.c) | ||||||||||||
|
|
||||||||||||
| # Build executable | ||||||||||||
| add_executable(console_c_app ${EXAMPLE_SRC}) | ||||||||||||
| add_executable(CImg2NumExample_console_c ${EXAMPLE_SRC}) | ||||||||||||
|
|
||||||||||||
| target_compile_options(CImg2NumExample_console_c PRIVATE ${IMG2NUM_STRICT_CXX_FLAGS}) | ||||||||||||
|
|
||||||||||||
| # Include the downloaded headers directly | ||||||||||||
| target_include_directories(console_c_app PRIVATE | ||||||||||||
| target_include_directories(CImg2NumExample_console_c PRIVATE | ||||||||||||
| ${CMAKE_SOURCE_DIR}/third_party | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| # Location to store the output images | ||||||||||||
| target_compile_definitions(console_c_app PRIVATE | ||||||||||||
| target_compile_definitions(CImg2NumExample_console_c PRIVATE | ||||||||||||
| OUTPUT_DIR="${CMAKE_BINARY_DIR}/outputs/console-c" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| # Link against the C bindings | ||||||||||||
| target_link_libraries(console_c_app PRIVATE CImg2Num m) | ||||||||||||
| target_link_libraries(CImg2NumExample_console_c PRIVATE CImg2Num m) | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cd example-apps/console-c && cat -n CMakeLists.txtRepository: Ryan-Millard/Img2Num Length of output: 1126 🏁 Script executed: # Check other example apps for patterns of conditional linking
find example-apps -name "CMakeLists.txt" -type f | head -10 | xargs cat -nRepository: Ryan-Millard/Img2Num Length of output: 2173 🏁 Script executed: # Search for existing conditional linking patterns in the main CMakeLists files
rg "if.*MSVC" --type cmakeRepository: Ryan-Millard/Img2Num Length of output: 46 🏁 Script executed: # Search for target_link_libraries with math library
rg "target_link_libraries.*\bm\b" --type cmake -A 2 -B 2Repository: Ryan-Millard/Img2Num Length of output: 277 🌐 Web query:
💡 Result: When developing with the MSVC compiler on Windows, you should not explicitly link a separate math library (often referred to as 'libm' or 'm') [1][2]. The math functions required by the ISO C standard (such as sin, cos, sqrt, etc.) are provided directly by the Universal C Runtime (UCRT) library [3]. This runtime is automatically linked by MSVC by default [4][2]. Attempting to explicitly link a library named 'm' or 'm.lib' on Windows will typically result in a linker error (e.g., LNK1104: cannot open file 'm.lib'), as no such standalone library exists in the MSVC toolchain [1][5][6]. In CMake projects, you should ensure that 'm' is not added to your link dependencies when targeting MSVC [1][7]. A common, portable approach is to use a conditional check in your CMakeLists.txt to avoid linking 'm' on Windows [1][7][8]: # Example of portable math library linking in CMake if (NOT WIN32) target_link_libraries(your_target PUBLIC m) endif Alternatively, you can use the check_library_exists module to determine if a separate math library is required for your current compiler and platform, which correctly identifies that it is unnecessary on MSVC [8]. If you are working with cross-platform projects or third-party libraries (e.g., via pkg-config), you may occasionally encounter build scripts that incorrectly include '-lm' unconditionally; these should be patched to omit the dependency when the compiler is MSVC [9][6][10]. Citations:
Guard Line 28 links Suggested fix# Link against the C bindings
-target_link_libraries(CImg2NumExample_console_c PRIVATE CImg2Num m)
+target_link_libraries(CImg2NumExample_console_c PRIVATE CImg2Num)
+if(NOT MSVC)
+ target_link_libraries(CImg2NumExample_console_c PRIVATE m)
+endif()📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,25 @@ | ||
| # ================================================================= | ||
| # Example Console App (C++) | ||
| # ================================================================= | ||
| cmake_minimum_required(VERSION 3.16) | ||
| project(Img2NumExample LANGUAGES CXX) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| project(Img2NumExample_console_cpp LANGUAGES CXX) | ||
|
|
||
| # Collect source files | ||
| file(GLOB_RECURSE EXAMPLE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") | ||
|
|
||
| # Build executable | ||
| add_executable(console_cpp_app ${EXAMPLE_SRC}) | ||
| add_executable(Img2NumExample_console_cpp ${EXAMPLE_SRC}) | ||
|
|
||
| target_compile_options(Img2NumExample_console_cpp PRIVATE ${IMG2NUM_STRICT_CXX_FLAGS}) | ||
|
|
||
| # Include the downloaded STB headers | ||
| target_include_directories(console_cpp_app PRIVATE | ||
| target_include_directories(Img2NumExample_console_cpp PRIVATE | ||
| ${CMAKE_SOURCE_DIR}/third_party | ||
| ) | ||
|
|
||
| # Location to store the output images | ||
| target_compile_definitions(console_cpp_app PRIVATE | ||
| target_compile_definitions(Img2NumExample_console_cpp PRIVATE | ||
| OUTPUT_DIR="${CMAKE_BINARY_DIR}/outputs/console-cpp" | ||
| ) | ||
|
|
||
| # Link against the core Img2Num library | ||
| target_link_libraries(console_cpp_app PRIVATE Img2Num) | ||
| target_link_libraries(Img2NumExample_console_cpp PRIVATE Img2Num) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Ryan-Millard/Img2Num
Length of output: 1101
🏁 Script executed:
Repository: Ryan-Millard/Img2Num
Length of output: 93
🏁 Script executed:
Repository: Ryan-Millard/Img2Num
Length of output: 174
Resolve the C++17 vs C++20 standard mismatch.
CMakeLists.txt line 7 enforces C++17 (
set(CMAKE_CXX_STANDARD 17)), but the repository coding guidelines (.clang-format) require C++20 (Standard: c++20). This creates a configuration conflict that must be resolved—either update CMakeLists.txt to enforce C++20, or explicitly update the project standards documentation and all configuration files to C++17.Note: Line 9 contains a comment explicitly stating C++17 intent, and line 15 includes
-Werror=c++20-extensions, suggesting this may be a deliberate choice. However, it contradicts the stated coding standards and requires alignment.🤖 Prompt for AI Agents
Source: Coding guidelines