[CMake] One library with multiple sub-directories

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Nov 3 11:50:38 EST 2004


After hacking at this for a bit I found why my source files were not 
being built in their respective sub directories. I have added the 
important detail to the structure here:

directory structure:
	/-
	-/foo
		default.cpp
		generated.h	#new, this file is actually generated by a script 
triggered by cmake
	-/bar
		default.cpp

top level cmake:
	SUBDIRS( foo)
	SUBDIRS(bar)
	SET(GENERATED_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/foo/generated.h) #new
	SET (MY_LIB_SRC ${FOO_SRC} ${BAR_SRC})

	STRING(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" 
RELATIVE_MY_LIB_SRC "${MY_LIB_SRC}" )  #new

	SET_SOURCE_FILE_PROPERTIES(${RELATIVE_MY_LIB_SRC} PROPERTIES 
OBJECT_DEPENDS "${GENERATED_HEADERS}") #new

	ADD_LIBRARY(my ${RELATIVIE_MY_LIB_SRC}

foo (simular for bar) directory cmake:
	SET(LOCAL_FOO_SRC default.cpp )

	SET(FOO_SRC "" CACHE INTERNAL "source files for foo")
	FOREACH(file ${LOCAL_FOO_SRC})
     		SET(FOO_SRC "${FOO_SRC};${CMAKE_CURRENT_SOURCE_DIR}/${file}" 
CACHE INTERNAL "source files for foo")
	ENDFOREACH(file)

So is it because I don't have all the object depends files as relative 
paths that  causes cmake to still build in the top level cmake dir? It 
seems like cmake may be not so smart when it comes to trying to build 
in subdirs? Are there any suggestions on how to make it do that here?

Thanks,
Brad


On Nov 2, 2004, at 3:55 PM, Bradley Lowekamp wrote:

> I have a good bit of stuff, going on in the sub directories. If I just 
> pass relative paths to the ADD_LIBRARY command then it should still 
> work even with SUBDIRS? Well I am in the mists of looking up some 
> string editing to try that out now, lets hope this works.
>
> Thanks,
> Brad
>
> On Nov 2, 2004, at 3:28 PM, Brad King wrote:
>
>> Bradley Lowekamp wrote:
>>> Hello,
>>>     I am trying to generate a single library from multiple source 
>>> sub-directories where in the subdirectories files may have the same 
>>> name. Currently I have been making sure that each file had different 
>>> names, but I can't be doing this any more. The way I have it 
>>> currently set up is basically as follows:Just leave out the SUBDIRS 
>>> and build it all from the top:
>>
>> ADD_LIBRARIES(my foo/default.cpp bar/default.cpp)
>>
>> The object files will be built with the proper relative paths.
>>
>> -Brad
>>
>>
> ========================================================
> Bradley Lowekamp
> Management Systems Designers Contractor for
> Office of High Performance Computing and Communications
> National Library of Medicine
> 'blowekamp at mail.nih.gov
>
> _______________________________________________
> CMake mailing list
> CMake at www.cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>



More information about the CMake mailing list