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

Commit

Permalink
Check variable return by get_target_property before it's usage (#802)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pramodk authored May 24, 2022
1 parent 0f12b03 commit cb38844
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,23 +473,25 @@ add_subdirectory(coreneuron)

if(CORENRN_ENABLE_GPU)
get_target_property(CORENRN_LINK_LIBRARIES coreneuron INTERFACE_LINK_LIBRARIES)
foreach(LIB ${CORENRN_LINK_LIBRARIES})
get_filename_component(dir_path ${LIB} DIRECTORY)
if(TARGET ${LIB})
# See, for example, caliper where the coreneuron target depends on the caliper target (so we
# get LIB=caliper in this loop), but -l and -L are already added manually here:
# https://github.com/BlueBrain/CoreNeuron/blob/856cea4aa647c8f2b0d5bda6d0fc32144c5942e3/CMakeLists.txt#L411-L412
message(
NOTICE
"Ignoring dependency '${LIB}' of 'coreneuron' and assuming relevant flags have already been added to CORENEURON_LIB_LINK_FLAGS."
)
elseif(NOT dir_path)
# In case LIB is not a target but is just the name of a library, e.g. "dl"
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " -l${LIB}")
else()
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " ${LIB}")
endif()
endforeach()
if(CORENRN_LINK_LIBRARIES)
foreach(LIB ${CORENRN_LINK_LIBRARIES})
get_filename_component(dir_path ${LIB} DIRECTORY)
if(TARGET ${LIB})
# See, for example, caliper where the coreneuron target depends on the caliper target (so we
# get LIB=caliper in this loop), but -l and -L are already added manually here:
# https://github.com/BlueBrain/CoreNeuron/blob/856cea4aa647c8f2b0d5bda6d0fc32144c5942e3/CMakeLists.txt#L411-L412
message(
NOTICE
"Ignoring dependency '${LIB}' of 'coreneuron' and assuming relevant flags have already been added to CORENEURON_LIB_LINK_FLAGS."
)
elseif(NOT dir_path)
# In case LIB is not a target but is just the name of a library, e.g. "dl"
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " -l${LIB}")
else()
set_property(GLOBAL APPEND_STRING PROPERTY CORENEURON_LIB_LINK_FLAGS " ${LIB}")
endif()
endforeach()
endif()
endif()

include(MakefileBuildOptions)
Expand Down

0 comments on commit cb38844

Please sign in to comment.