-
Notifications
You must be signed in to change notification settings - Fork 8
Fix cmake build: use target_link_libraries instead of LINK_FLAGS #26
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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(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}) |
Outdated
Copilot
AI
Mar 5, 2026
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.
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.
| 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}") |
Outdated
Copilot
AI
Mar 5, 2026
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.
${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.
| 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}) |
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.
Using a raw
-Wl,-rpath,...linker flag is toolchain-specific and bypasses CMake’s dedicated RPATH handling. Prefer settingBUILD_RPATH/INSTALL_RPATH(orCMAKE_INSTALL_RPATH) via target properties for better portability and clearer intent, while still achieving correct runtime search paths.