[CMake] Merging a project from autoconf and GNUMakefiles
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Tue Nov 16 12:52:39 EST 2010
On 2010-11-16 09:35-0500 Torri, Stephen CIV NSWCDD, W15 wrote:
> I am trying to merge a project that was using autoconf and GNUMakefiles. When you use automake you can build static libraries in sub directories and then link them together into one shared library in the end that was install. This is not possible with Visual Studio. In GNU Make for the project I can see that there are GNMakefiles in the subdirectories that build the object files where they are linked together in the top level GNUMakefile.
>
> In projects I have done where I have had source files in subdirectories I could include all of them in a variable in the single CMakeLists.txt file in the top directory. This project has 1079 C++ and C files in a variety of subdirectories. The only way I can see to make a single shared library with CMake is to include all the source files into a single variable in the single CMakeLists.txt file like I do in my own projects. So to do this same technique with this project seems unreasonable to ask these developers to adopt.
>
> So I am wondering if I can set a single variable used across a variety of CMakeLists.txt files? So that way in subdirectoryA I can add files to a variable called SOURCES that I append files in from subdirectoryB. Therefore in the top level CMakeLists.txt file I can declare:
>
> add_library ( target ${SOURCES} )
> target_link_libraries ( target ${DEPENDENCY_LIBRARIES} )
>
> In a similar way I can include those headers I want to install in all the subdirectories.
CMake deliberately reduces scope to help reduce side effects. But
there are ways to beat that for needs like yours.
You should look at the documentation of PARENT_SCOPE in the set
command. It might be suitable for your needs, but a drawback is you
must have (I assume) an unbroken recursive chain of such set commands
to communicate data from some deep subdirectory to your top-level
directory, and I would think that is a pretty fragile structure
subject to hard-to-find bugs if some subdirectories are moved around
in the future. For my own similar needs, I far prefer setting a GLOBAL
property (see documentation of set_property(GLOBAL...[APPEND]...)).
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
More information about the CMake
mailing list