I have a multi-target CMake file where all the targets are building fine on OS X, but when I build the target on Ubuntu Linux, it does not link the system libraries added in target_include_directories.
Here's an example of a target (each target is similar).
set(SOURCE_FILES_TARGET)
set(RELEASE_LIBS iconv m xml2 z icucore resolv curl )
add_executable(TARGET_NAME ${SOURCE_FILES_TARGET)
target_include_directories(TARGET_NAME PRIVATE external_lib1/headers external_lib2/headers )
target_link_libraries(TARGET_NAME ${RELEASE_LIBS})
target_link_libraries(TARGET_NAME ${CMAKE_SOURCE_DIR}/lib1.a)
target_link_libraries(TARGET_NAME ${CMAKE_SOURCE_DIR}/lib2.a)
The libraries are a little different for linux (comparing the .la files), but even one which is the same (xml2) results in undefined reference errors. Also, on OS X the "target_link_libraries" command works as listed above, and with -lxml2 format.
I tried to add the "pthreads" library on linux (as it asked for this, but not on OS X), and the only way I was able to add it was
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
however, this is a global setting for all targets. Basically, if I put pthread into target_link_libraries it is ignored, just like the rest of them.
How should I best add these libraries to the targets? Maybe I'm missing something on the OS X side and it just happens to work?