<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>opticode.ch blog &#187; Uncategorized</title>
	<atom:link href="http://opticode.ch/blog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://opticode.ch/blog</link>
	<description>the fine Art of coding - Julien Pilet</description>
	<lastBuildDate>Mon, 02 Dec 2024 07:54:32 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Transitive link dependencies with cmake</title>
		<link>http://opticode.ch/blog/transitive-link-dependencies-with-cmake/</link>
		<comments>http://opticode.ch/blog/transitive-link-dependencies-with-cmake/#comments</comments>
		<pubDate>Thu, 03 Jul 2014 13:02:05 +0000</pubDate>
		<dc:creator><![CDATA[Julien Pilet]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://opticode.ch/blog/?p=27</guid>
		<description><![CDATA[CMake has a great feature: transitive link dependencies. Let&#8217;s imagine an executable A that depends on library B which itself depends on library C. CMake is smart enough to link A with B and C, even if the dependency list of A only includes B. Knowing this, I organize my sources in a particular way. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>CMake has a great feature: transitive link dependencies. Let&#8217;s imagine an executable A that depends on library B which itself depends on library C. CMake is smart enough to link A with B and C, even if the dependency list of A only includes B.</p>
<p>Knowing this, I organize my sources in a particular way. A class is usually declared in a .h file and implemented in a cpp file. Well, for almost each .h/.cpp pair I define a library and list in the CMakeLists.txt the dependencies directly used by the cpp file.</p>
<p>Such an approach as huge advantages. First, the code base can scale easily, with many utility classes and executables that link only what is required. For example, each h/cpp file pair should ideally have a unit test. This test probably needs to be linked with only a small fraction of the code base. Relying an CMake transitive dependencies is a great way of selecting only what is required and all that is required.</p>
<p>There is another advantage. Imagine a library L that depends on boost. Of course, all users of L must link boost. Later in the life of the project, L is refactored to rely on c++11 features and it does not need boost anymore. Well, simply changing the dependency list of L will remove boost from everything that does not need it anymore. How convenient!</p>
<p>Of course, this scheme blows up the number of libraries, but this is not a problem. Even visual studio can manage workspaces with hundreds of projects quite well.</p>
<p>CMakeLists.txt example:</p>
<pre><code>cmake_minimum_required(VERSION 2.8)
add_library(logging logging.h logging.cpp)
cxx_test(loggingTest loggingTest.cpp logging gtest_main)
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://opticode.ch/blog/transitive-link-dependencies-with-cmake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.120 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2025-07-06 21:09:06 -->
