Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ set_target_properties(ncvis
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
LINK_FLAGS "${NCVIS_LINKER_FLAGS}"
)

# Link libraries after object files (required for GNU ld)
target_link_options(ncvis PRIVATE -Wl,-rpath,${WXCONFIG_RPATH}/lib)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a raw -Wl,-rpath,... linker flag is toolchain-specific and bypasses CMake’s dedicated RPATH handling. Prefer setting BUILD_RPATH / INSTALL_RPATH (or CMAKE_INSTALL_RPATH) via target properties for better portability and clearer intent, while still achieving correct runtime search paths.

Suggested change
)
# Link libraries after object files (required for GNU ld)
target_link_options(ncvis PRIVATE -Wl,-rpath,${WXCONFIG_RPATH}/lib)
BUILD_RPATH "${WXCONFIG_RPATH}/lib"
INSTALL_RPATH "${WXCONFIG_RPATH}/lib"
)
# Link libraries after object files (required for GNU ld)

Copilot uses AI. Check for mistakes.
separate_arguments(WX_LINK_LIBS UNIX_COMMAND "${WX_LINK_FLAGS}")
separate_arguments(NC_LINK_LIBS UNIX_COMMAND "-L${NC_LIB_DIR} -lnetcdf ${NC_LINK_FLAGS}")
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing -L… search-path flags via target_link_libraries works but is not idiomatic CMake and can be harder to reason about across generators. Prefer expressing the library directory via target_link_directories(ncvis PRIVATE ${NC_LIB_DIR}) (or linking to an imported target like NetCDF::NetCDF if available) and keep target_link_libraries focused on actual libraries (e.g., netcdf).

Suggested change
separate_arguments(NC_LINK_LIBS UNIX_COMMAND "-L${NC_LIB_DIR} -lnetcdf ${NC_LINK_FLAGS}")
separate_arguments(NC_LINK_LIBS UNIX_COMMAND "-lnetcdf ${NC_LINK_FLAGS}")
target_link_directories(ncvis PRIVATE ${NC_LIB_DIR})

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate_arguments(... UNIX_COMMAND ...) hard-codes UNIX-style parsing. If this project is ever generated on non-UNIX platforms, this can mis-parse arguments. Using NATIVE_COMMAND (or guarding with if(UNIX) and providing an alternative) makes the behavior more robust.

Suggested change
separate_arguments(WX_LINK_LIBS UNIX_COMMAND "${WX_LINK_FLAGS}")
separate_arguments(NC_LINK_LIBS UNIX_COMMAND "-L${NC_LIB_DIR} -lnetcdf ${NC_LINK_FLAGS}")
separate_arguments(WX_LINK_LIBS NATIVE_COMMAND "${WX_LINK_FLAGS}")
separate_arguments(NC_LINK_LIBS NATIVE_COMMAND "-L${NC_LIB_DIR} -lnetcdf ${NC_LINK_FLAGS}")

Copilot uses AI. Check for mistakes.
target_link_libraries(ncvis PRIVATE ${WX_LINK_LIBS} ${NC_LINK_LIBS})

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${WX_LINK_FLAGS} / ${NC_LINK_FLAGS} typically contain a mix of true libraries (-l...) and non-library linker options (e.g., -pthread, -Wl,...). Feeding the whole parsed list into target_link_libraries makes the intent unclear and can complicate future changes. Consider splitting the parsed values into (1) libraries for target_link_libraries and (2) flags for target_link_options, so each API is used for its intended purpose.

Suggested change
separate_arguments(WX_LINK_LIBS UNIX_COMMAND "${WX_LINK_FLAGS}")
separate_arguments(NC_LINK_LIBS UNIX_COMMAND "-L${NC_LIB_DIR} -lnetcdf ${NC_LINK_FLAGS}")
target_link_libraries(ncvis PRIVATE ${WX_LINK_LIBS} ${NC_LINK_LIBS})
separate_arguments(WX_LINK_ITEMS UNIX_COMMAND "${WX_LINK_FLAGS}")
separate_arguments(NC_LINK_ITEMS UNIX_COMMAND "-L${NC_LIB_DIR} -lnetcdf ${NC_LINK_FLAGS}")
# Split wxWidgets link items into libraries (-l...) and other linker options
set(WX_LIBRARIES "")
set(WX_OPTIONS "")
foreach(item IN LISTS WX_LINK_ITEMS)
if(item MATCHES "^-l.+")
list(APPEND WX_LIBRARIES "${item}")
else()
list(APPEND WX_OPTIONS "${item}")
endif()
endforeach()
# Split NetCDF link items into libraries (-l...) and other linker options
set(NC_LIBRARIES "")
set(NC_OPTIONS "")
foreach(item IN LISTS NC_LINK_ITEMS)
if(item MATCHES "^-l.+")
list(APPEND NC_LIBRARIES "${item}")
else()
list(APPEND NC_OPTIONS "${item}")
endif()
endforeach()
# Link true libraries
target_link_libraries(ncvis PRIVATE ${WX_LIBRARIES} ${NC_LIBRARIES})
# Apply non-library linker options
target_link_options(ncvis PRIVATE ${WX_OPTIONS} ${NC_OPTIONS})

Copilot uses AI. Check for mistakes.
# Install target
INSTALL(TARGETS ncvis
RUNTIME DESTINATION bin
Expand Down
Loading