Fix possible linker errors by using CMake find_library macro
authorPetr Štetiar <ynezz@true.cz>
Tue, 5 Jun 2018 07:41:25 +0000 (09:41 +0200)
committerPetr Štetiar <ynezz@true.cz>
Wed, 5 Jun 2019 11:10:50 +0000 (13:10 +0200)
Fixes following errors while compiling natively on x86:

 cc -fPIC -shared  -o rpcsys.so sys.c.o -lubox -lubus
 ld: cannot find -lubox
 ld: cannot find -lubus

Signed-off-by: Petr Štetiar <ynezz@true.cz>
CMakeLists.txt

index ceb472e941620558fac586eb032a6930e7f61034..3bfc286baffc0ba838e83f64c423e1b0c6b744cb 100644 (file)
@@ -22,6 +22,10 @@ IF(HAVE_SHADOW)
   ADD_DEFINITIONS(-DHAVE_SHADOW)
 ENDIF()
 
+FIND_LIBRARY(uci NAMES uci)
+FIND_LIBRARY(ubus NAMES ubus)
+FIND_LIBRARY(ubox NAMES ubox)
+FIND_LIBRARY(blobmsg_json NAMES blobmsg_json)
 FIND_LIBRARY(json NAMES json-c json)
 FIND_LIBRARY(crypt NAMES crypt)
 IF(crypt STREQUAL "crypt-NOTFOUND")
@@ -35,28 +39,29 @@ FIND_PATH(ubox_include_dir libubox/blobmsg_json.h)
 INCLUDE_DIRECTORIES(${ubox_include_dir})
 
 ADD_EXECUTABLE(rpcd main.c exec.c session.c uci.c plugin.c)
-TARGET_LINK_LIBRARIES(rpcd ubox ubus uci dl blobmsg_json ${json} ${crypt})
+TARGET_LINK_LIBRARIES(rpcd ${ubox} ${ubus} ${uci} ${blobmsg_json} ${json} ${crypt} dl)
 
 SET(PLUGINS "")
 
 IF(FILE_SUPPORT)
   SET(PLUGINS ${PLUGINS} file_plugin)
   ADD_LIBRARY(file_plugin MODULE file.c)
-  TARGET_LINK_LIBRARIES(file_plugin ubox ubus)
+  TARGET_LINK_LIBRARIES(file_plugin ${ubox} ${ubus})
   SET_TARGET_PROPERTIES(file_plugin PROPERTIES OUTPUT_NAME file PREFIX "")
 ENDIF()
 
 IF(RPCSYS_SUPPORT)
   SET(PLUGINS ${PLUGINS} rpcsys_plugin)
   ADD_LIBRARY(rpcsys_plugin MODULE sys.c)
-  TARGET_LINK_LIBRARIES(rpcsys_plugin ubox ubus)
+  TARGET_LINK_LIBRARIES(rpcsys_plugin ${ubox} ${ubus})
   SET_TARGET_PROPERTIES(rpcsys_plugin PROPERTIES OUTPUT_NAME rpcsys PREFIX "")
 ENDIF()
 
 IF (IWINFO_SUPPORT)
+  FIND_LIBRARY(iwinfo NAMES iwinfo)
   SET(PLUGINS ${PLUGINS} iwinfo_plugin)
   ADD_LIBRARY(iwinfo_plugin MODULE iwinfo.c)
-  TARGET_LINK_LIBRARIES(iwinfo_plugin ubox ubus iwinfo)
+  TARGET_LINK_LIBRARIES(iwinfo_plugin ${ubox} ${ubus} ${iwinfo})
   SET_TARGET_PROPERTIES(iwinfo_plugin PROPERTIES OUTPUT_NAME iwinfo PREFIX "")
 ENDIF()