title: CMake: satisfying dependencies when building shared object file (.so) from object file (.o)
body: <p>I am able to do this without CMake using a handwritten Makefile, like so:</p>
  
  <pre><code>g++  $(CXSCINC) -c -fPIC cellComplex_extern.cpp -o cellComplex_extern.o  
  g++  $(CXSCINC) -shared -Wl -o cellComplex_lib.so cellComplex_extern.o $(CXSCLIB) -lcxsc
  </code></pre>
  
  <p>This gets me shared library <code>cellComplex_lib.so</code>, which then gets picked up by <code>ctypes</code> as a dynamically linked library (<code>lib = ctypes.cdll.LoadLibrary('./cellComplex_lib.so'</code>) for later use.  </p>
  
  <p>My project has moved to CMake as a build system and I am looking to emulate the functionality of my Makefile above.  </p>
  
  <p>So far I have discovered the <code>add_library()</code> command for CMakeLists.txt, but the link to the CXSC library is never made (as evidenced by horrible complaining when I run <code>make</code> after <code>cmake</code>.  </p>
  
  <p><strong>How can I tell CMake to build <code>cellComplex_lib</code> with the third-party library CXSC?</strong></p>
  
  <p>-- non-working <code>CMakeLists.txt</code> --</p>
  
  <pre><code>add_library(include/python/cellComplex_extern OBJECT
              include/python/cellComplex_extern.cpp ${all_headers})
  
  add_library(include/python/cellComplex_lib SHARED
              include/python/cellComplex_extern)
  target_link_libraries(include/python/cellComplex_lib ${CXSC_LIB_DIR}/libcxsc.a)
  </code></pre>
  
  <p>Result of running cmake followed by make:</p>
  
  <pre><code>.
  .
  .
  [ 75%] Built target include/python/cellComplex_extern
  Linking CXX shared library libinclude/python/cellComplex_lib.dylib
  ld: can't open output file for writing: libinclude/python/cellComplex_lib.dylib, errno=2 for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make[2]: *** [libinclude/python/cellComplex_lib.dylib] Error 1
  make[1]: *** [CMakeFiles/include/python/cellComplex_lib.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>