title: Adding a shared library and executable, compiling source files twice
body: <pre><code>gcc (GCC) 4.7.2
  cmake version 2.8.11  
  </code></pre>
  
  <p>Hello,</p>
  
  <p>I wondering if there is a way around the following issue. I have highlighted below:</p>
  
  <pre><code>SET(GW_SOURCE_FILES 
    module.c 
    module_imp.c 
    module_message.c
    module_config.c
    module_queue.c)
  
  # Compiles the source files to create the shared library called dlg_gw.so
  ADD_LIBRARY(dlg_gw SHARED ${GW_SOURCE_FILES}) 
  
  # Link additional libraries to this
  TARGET_LINK_LIBRARIES(dlg_gw gc srl ${APRUTIL})
  
  # ISSUE: Now I want to create my executable using the same source files. module.c is where my 'void main(void)' is. 
  # However, I have some functions in there which will also be part of the library.
  # However, this will recompile the same source files all over again. I don't really like that behaviour.
  ADD_EXECUTABLE(sun_gw ${GW_SOURCE_FILES})
  
  # After the executable is created, link the libraries with it.
  TARGET_LINK_LIBRARIES(sun_gw ${APR} driver dlg_gw dlg_sip dlg_ss7 dlg_isdn)
  </code></pre>
  
  <p>I hope you can see the issue above, as I am compiling the same source files twice. Once to create the <code>dlg_gw</code> library. Then again to create the executable <code>sun_gw</code>.</p>
  
  <p>I was thinking of taking out the 'void main(void)' and putting it in a new file called runtime.c and then doing the following:</p>
  
  <pre><code>ADD_EXECUTABLE(sun_gw runtime.c)
  </code></pre>
  
  <p>But the above require me to change some of the source code.</p>
  
  <p>Many thanks for any other suggestions,</p>