[CMake] generating code from compiled program

James Bigler bigler at cs.utah.edu
Wed Sep 26 14:21:49 EDT 2007


Bill Hoffman wrote:
> Andreas Pakulat wrote:
>>
>>>    
>>>> On 26.09.07 10:03:08, James Bigler wrote:
>>>>      
>>>>> Has anyone any examples of building a compiler (of sorts) and using 
>>>>> that
>>>>> compiler to generate code then integrated into another CMake target
> Does this help:
> 
> http://www.cmake.org/Wiki/CMake_FAQ
> See :How can I generate a source file during the build?

I just realized that my problem might be related to a circular dependency I 
hadn't noticed before.  It was reported by make as "compiler depends on 
compiler" which didn't make sense to me.

ADD_LIBRARY(lib_a ${source_files})
ADD_TARGET_LIBRARY(lib_a lib_helper)

ADD_EXECUTABLE(compiler compiler.cc)
ADD_TARGET_LIBRARY(compiler lib_a)

GET_TARGET_PROPERTY(compiler_location compiler ${CMAKE_BUILD_TYPE}_LOCATION)
ADD_CUSTOM_COMMAND(
   OUTPUT source.cc
   COMMAND ${compiler_location} -o source.cc
   DEPENDS compiler
   )

ADD_LIBRARY(lib_helper source.cc)

=====================================
Here's the dependency chain:

lib_helper <- source.cc
source.cc  <- compiler
compiler   <- lib_a
lib_a      <- lib_helper  !!!! Circular dependency :(

I'll need to refactor some code before I can address this again.  I'm hoping 
that once I do this, all will become well in the world.  If I still have 
problems, once I remove the circular dependency, I'll come asking again.

Thanks for everyone's suggestions and help!  This is why I like the CMake 
mailing list so much.

James


More information about the CMake mailing list