How to add result of find_library to cmakelist?

389 Views Asked by At

Was reading this:

https://discuss.cocos2d-x.org/t/xcode-12-2-errors-when-ios-simulator-with-cocos2d-x-4-0/52203/22

I don't know much about CMake

find_library(libiconv NAMES libiconv)
find_library(libz NAMES libz)

I believe the above lines will find some missing libraries, but to get things to work, I need to add the result to the library list.

How do I add the result ?

1

There are 1 best solutions below

1
On

find_library populates the variable which you pass as the first argument with the found library path, if any. So you use this variable in target_link_libraries command. It would be something like this:

find_library(ICONV_LIB NAMES libiconv)
target_link_libraries(YourTarget ${ICONV_LIB})

Also you should get familiar with CMake first because you clearly don't know what you are doing. Both zlib & iconv have find modules so what you really want to do is this:

find_package(ZLIB REQUIRED)
find_package(Iconv REQUIRED)
target_link_libraries(YourTarget Iconv::Iconv ZLIB::ZLIB)