Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit cb38844

Browse files
authored
Check variable return by get_target_property before it's usage (#802)
* CMake's get_target_property might return `<VAR>-NOTFOUND` and hence it should be checked before it's usage * As mentioned in neuronsimulator/nrn/issues/1788, it can result into an error like: => LINKING executable ./special LDFLAGS are: -lreadline -lncurses /users/bp000174/nrn-install/share/nrn/nrnmain.cpp: /usr/bin/ld: cannot find -lCORENRN_LINK_LIBRARIES-NOTFOUND
1 parent 0f12b03 commit cb38844

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

CMakeLists.txt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -473,23 +473,25 @@ add_subdirectory(coreneuron)
473473

474474
if(CORENRN_ENABLE_GPU)
475475
get_target_property(CORENRN_LINK_LIBRARIES coreneuron INTERFACE_LINK_LIBRARIES)
476-
foreach(LIB ${CORENRN_LINK_LIBRARIES})
477-
get_filename_component(dir_path ${LIB} DIRECTORY)
478-
if(TARGET ${LIB})
479-
# See, for example, caliper where the coreneuron target depends on the caliper target (so we
480-
# get LIB=caliper in this loop), but -l and -L are already added manually here:
481-
# https://github.com/BlueBrain/CoreNeuron/blob/856cea4aa647c8f2b0d5bda6d0fc32144c5942e3/CMakeLists.txt#L411-L412
482-
message(
483-
NOTICE
484-
"Ignoring dependency '${LIB}' of 'coreneuron' and assuming relevant flags have already been added to CORENEURON_LIB_LINK_FLAGS."
485-
)
486-
elseif(NOT dir_path)
487-
# In case LIB is not a target but is just the name of a library, e.g. "dl"
488-
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " -l${LIB}")
489-
else()
490-
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " ${LIB}")
491-
endif()
492-
endforeach()
476+
if(CORENRN_LINK_LIBRARIES)
477+
foreach(LIB ${CORENRN_LINK_LIBRARIES})
478+
get_filename_component(dir_path ${LIB} DIRECTORY)
479+
if(TARGET ${LIB})
480+
# See, for example, caliper where the coreneuron target depends on the caliper target (so we
481+
# get LIB=caliper in this loop), but -l and -L are already added manually here:
482+
# https://github.com/BlueBrain/CoreNeuron/blob/856cea4aa647c8f2b0d5bda6d0fc32144c5942e3/CMakeLists.txt#L411-L412
483+
message(
484+
NOTICE
485+
"Ignoring dependency '${LIB}' of 'coreneuron' and assuming relevant flags have already been added to CORENEURON_LIB_LINK_FLAGS."
486+
)
487+
elseif(NOT dir_path)
488+
# In case LIB is not a target but is just the name of a library, e.g. "dl"
489+
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " -l${LIB}")
490+
else()
491+
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " ${LIB}")
492+
endif()
493+
endforeach()
494+
endif()
493495
endif()
494496

495497
include(MakefileBuildOptions)

0 commit comments

Comments
 (0)