I'm trying to link to a library from another library using CMake and Xcode.
This is an issue for any library, but to make things easier to convey, let's use zlib
as an example.
This seems to work for executables as follows:
LINK_DIRECTORIES(${LIB_DIR}/zlib/build/)
ADD_EXECUTABLE(MY_EXECUTABLE ...
And it generates an Xcode project with the setting shown below:
As you can see, the $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
bit gets added correctly, to the zlib
library path.
But if I try to do this:
LINK_DIRECTORIES(${LIB_DIR}/zlib/build/)
ADD_LIBRARY(MY_LIBRARY ...
zlib
never gets linked to MY_EXECUTABLE
when I link it to MY_LIBRARY
And TARGET_LINK_LIBRARIES
after ADD_LIBRARY
allows me to link to zlib
from MY_LIBRARY
but I have to specify the full path, which won't work as the configuration (Debug, Release, etc) as well as the effective platform (iphoneos, iphonesimulator, etc) are factors.
What I want to do is to have zlib
added to the Xcode Library Search Paths, with the $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
bit, as shown above.
Turning my comment into an answer
CMake does support adding the appropriate configuration to paths in multi-configuration environments with generator expressions (see e.g. CMake - Accessing configuration parameters of multiple-configuration generators)
And arguments to target_link_libraries() support the use of generator expressions. So in your case you can make use of the
$<CONFIG>
generator expression which would look something like this:Be aware - if you may have changed some policies - of one note from the
target_link_libraries()
documentation about policies CMP0003 - Libraries linked via full path no longer produce linker search paths and CMP0004 - Libraries linked may not have leading or trailing whitespace: