[CMake] acyclic subdirectory builds

Egon Kocjan egon at krul.ath.cx
Thu Apr 3 17:49:24 EDT 2008


Hello again,

I am slowly porting a complicated project to cmake. I have an acyclic 
graph of dependencies and "shared" build directories and I have trouble 
generating VS slns. A simple example (the real build is way more 
complicated):

liba/include.cmake:
get_filename_component(liba_dir ${CMAKE_CURRENT_LIST_FILE} PATH)
add_subdirectory(${liba_dir} ${liba_dir})
include_directories(${liba_dir})
link_libraries(liba)

liba/CMakeLists.txt:
add_library(liba a.cpp)

exea/CMakeLists.txt:
include(../liba/include.cmake)
add_executable(exea x.cpp)

exeb/CMakeLists.txt:
include(../liba/include.cmake)
add_executable(exeb y.cpp)

proj/CMakeLists.txt:
add_subdirectory(../exea ../exea)
add_subdirectory(../exeb ../exeb)

The idea here is that libraries use 100% modular include files. When I 
run cmake I get this in .sln:

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", 
".\ZERO_CHECK.vcproj", "{CDAEE59D-0373-4F41-9CF9-8DFA13581522}"
	ProjectSection(ProjectDependencies) = postProject
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exea", 
"C:\temp\exea\exea.vcproj", "{83ED0A1A-2D2D-489B-8C48-0D8F77FD3E5B}"
	ProjectSection(ProjectDependencies) = postProject
		{CCEE2530-3384-49B2-B5FB-6C588DF69FF7} = 
{CCEE2530-3384-49B2-B5FB-6C588DF69FF7}
		{CDAEE59D-0373-4F41-9CF9-8DFA13581522} = 
{CDAEE59D-0373-4F41-9CF9-8DFA13581522}
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liba", 
"C:\temp\liba\liba.vcproj", "{CCEE2530-3384-49B2-B5FB-6C588DF69FF7}"
	ProjectSection(ProjectDependencies) = postProject
		{CDAEE59D-0373-4F41-9CF9-8DFA13581522} = 
{CDAEE59D-0373-4F41-9CF9-8DFA13581522}
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exeb", 
"C:\temp\exeb\exeb.vcproj", "{01DD3A6A-19F5-4958-92C8-9AE7F300FF50}"
	ProjectSection(ProjectDependencies) = postProject
		{CCEE2530-3384-49B2-B5FB-6C588DF69FF7} = 
{CCEE2530-3384-49B2-B5FB-6C588DF69FF7}
		{CDAEE59D-0373-4F41-9CF9-8DFA13581522} = 
{CDAEE59D-0373-4F41-9CF9-8DFA13581522}
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liba", 
"C:\temp\liba\liba.vcproj", "{CCEE2530-3384-49B2-B5FB-6C588DF69FF7}"
	ProjectSection(ProjectDependencies) = postProject
		{CDAEE59D-0373-4F41-9CF9-8DFA13581522} = 
{CDAEE59D-0373-4F41-9CF9-8DFA13581522}
	EndProjectSection
EndProject

As you can see, the dependencies are correct, but liba is generated 
twice. Visual studio complains about duplicates, but it seems to work ok 
regardless. Is this a bug? Am I breaking some unwritten rules here? What 
about other generators, like xcode, ...

thanks
Egon Kocjan


More information about the CMake mailing list