In a single CMakeLists.txt
there is a shared library target SL
and an executable X
target linking to SL
. Although each target builds correctly in isolation, when both occupy the same CMakeLists.txt
, I get this error:
Expected output file at path/to/libSL.so for target SL but there was none
In simplified form, CMakeLists.txt
looks like:
add_library(SL SHARED ${SL_sources})
add_executable(X ${X_sources})
target_link_libraries(X SL)
Explicitly adding the dependency does not help:
add_dependencies(X SL)
Why does cmake refuse to builld SL
before attempting the link to X
? Is there a problem with putting these two targets in the same file? Is it a bug in cmake?