Hi everyone, I have been using cmake for quite a while now. I am using 2.4.6 on NetBSD. Among other things I do a dependency build automatically, based on a well-known directory tree.
For example lets say you have : CMakeLists.txt Source1.c depends/subprojA/ depends/subprojA/CMakeLists.txt - defining a new project that can be used separately. depends/subprojA/SourceSubprojA.c This works well. My problem arise when I want to have two or more main targets ( lets say you add Source2.c to the previous example ) to get two executables using the same library for example. The depends target gets cmake'd twice by the following code as expected ( simplified a lot because I do that in more complex generic cmake scripts ): [...snip...] MACRO (Build) FOREACH ( looparg ${ARGN} ) GET_FILENAME_COMPONENT(exename ${looparg} NAME_WE ) ADD_EXECUTABLE(${exename} ${looparg}) ADD_SUBDIRECTORY(depends/subprojA depends/subprojA_build EXCLUDE_FROM_ALL) TARGET_LINK_LIBRARIES(${exename} subprojA) ADD_DEPENDENCIES(${exename} subprojA) ENDFOREACH ( looparg ) ENDMACRO (BuildDepends) [...snip...] FILE ( GLOB sourcelist ${CMAKE_SOURCE_DIR} *.c) Build( ${sourcelist} ) [...snip...] And cmake gives me lots of warnings : make: "CMakeFiles/CMakeFiles/Makefile2" line 402: warning: duplicate script for target "depends/subprojA_build/CMakeFiles/subprojA.dir/all" ignored make: "CMakeFiles/CMakeFiles/Makefile2" line 250: warning: using previous script for "depends/subprojA_build/CMakeFiles/subprojA.dir/all" defined here Although it works ;) What I need to do is : Not to do the ADD_SUBDIRECTORY if this subdirectory has just been cmaked, *_without_* taking the ADD_SUBDIRECTORY out of the loop or out of the macro of course ;) My actual macro is more complex and provide a way to build and link custom dependencies only if needed. But I dont know how to check this dependency has been already made in this cmake call. I just want to avoid the cmaking of it if possible, to avoid the warnings... The build will still run fine. So I wonder if there is a way to check if a target has already been added ? how can I get the list of target ? Can do a check on the subdirectory to make sure I just entered it for the first time in this " $ cmake sourcedir " call ? Maybe another way to check something that will be enough so that I am assured that depends/subprojectA will be built once and once only if needed ? I know I could build it manually, but I still want depends/subprojectA to build automatically with only one "cmake . && make" call I can provide you with my cmake scripts, but I think it will be more of a trouble than a help to solve this little problem, probably coming of my lack of knowledge. They are available here anyway if you want them : https://asmodehn.fr/trac/Workshop/browser/trunk/CMake although probably not the last version I am talking about here. I hope I have been clear enough on my problem ;) Dont hesitate to ask me more questions if you want more informations. Thank you very much for your help :) -- Asmodehn _______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake