[CMake] Re: dependency error

Marc Paulescu marc.paulescu at gmail.com
Mon Oct 22 03:13:20 EDT 2007


Hello,
Because I received no reply (maybe because of the attachment) I will
post the CMakeLists contents here :

#======================================================

project(test)

if (WIN32)
    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)

    if (CMAKE_CONFIGURATION_TYPES)
        set(EXECUTABLE_OUTPUT_PATH    ${PROJECT_BINARY_DIR})
        set(LIBRARY_OUTPUT_PATH        ${PROJECT_BINARY_DIR})
    else (CMAKE_CONFIGURATION_TYPES)
        set(EXECUTABLE_OUTPUT_PATH    ${PROJECT_BINARY_DIR}/bin)
        set(LIBRARY_OUTPUT_PATH        ${PROJECT_BINARY_DIR}/bin)
    endif (CMAKE_CONFIGURATION_TYPES)
else (WIN32)
    set(EXECUTABLE_OUTPUT_PATH    ${PROJECT_BINARY_DIR}/bin)
    set(LIBRARY_OUTPUT_PATH        ${PROJECT_BINARY_DIR}/bin)
endif (WIN32)

subdirs(library)

#======================================================

project(library)

set(SOURCES library.c)
source_group("Source Files" FILES ${SOURCES})

set(HEADERS library.h)
source_group("Header Files" FILES ${HEADERS})

add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})

set(DEPS    module1 module2 module3)
target_link_libraries(${PROJECT_NAME} ${DEPS})

subdirs(modules executable)

#======================================================

project(modules)

set(MODULES            module1 module2 module3)

set(module1_DIR        module1)
set(module1_SRCS    ${module1_DIR}/module1.c)
set(module1_HDRS    ${module1_DIR}/module1.h)

set(module2_DIR        module2)
set(module2_SRCS    ${module2_DIR}/module2.c)
set(module2_HDRS    ${module2_DIR}/module2.h)

set(module3_DIR        module3)
set(module3_SRCS    ${module3_DIR}/module3.c)
set(module3_HDRS    ${module3_DIR}/module3.h)

foreach (MODULE ${MODULES})
    file(GLOB SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${${MODULE}_DIR}/*.c)

    if (SRCS)
        source_group(${MODULE} FILES ${${MODULE}_SRCS} ${${MODULE}_HDRS})

        add_library(${MODULE} STATIC ${${MODULE}_SRCS} ${${MODULE}_HDRS})

        set(DEPS library)
        target_link_libraries(${MODULE} ${DEPS})
    else (SRCS)
        set(MODULE_LIB_NAME
${CMAKE_STATIC_LIBRARY_PREFIX}${MODULE}${CMAKE_STATIC_LIBRARY_SUFFIX})

        if (CMAKE_CONFIGURATION_TYPES)
            set(MODULE_LIB_PATH
${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${MODULE_LIB_NAME})
        else (CMAKE_CONFIGURATION_TYPES)
            set(MODULE_LIB_PATH ${LIBRARY_OUTPUT_PATH}/${MODULE_LIB_NAME})
        endif (CMAKE_CONFIGURATION_TYPES)

          add_custom_target(${MODULE} ALL)
        add_custom_command(TARGET ${MODULE}
                           COMMAND ${CMAKE_COMMAND} -E copy
                                "/tmp/${MODULE_LIB_NAME}" ${MODULE_LIB_PATH}
                           COMMENT "Copying library ${MODULE_LIB_PATH}")
    endif (SRCS)

endforeach (MODULE ${MODULES})

#======================================================

project(executable)

set(SOURCES main.c executable.c)
source_group("Source Files" FILES ${SOURCES})

set(HEADERS executable.h)
source_group("Header Files" FILES ${HEADERS})

add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

set(DEPS library)
target_link_libraries(${PROJECT_NAME} ${DEPS})

#======================================================

Thank you.

On 10/12/07, Marc Paulescu <marc.paulescu at gmail.com> wrote:
> Hello,
>
> I have a project with the following dependency :
>
> executable -> static library -> static library module1 , ..., static library module n
>
> The executable depends on the static library. The library depends on the modules
> (which are also static libraries).
>
> An archive with the project is attached.
>
> What I want to do, is :
> When the sources (*.c) of a module are not present the build system should copy an
> already built module (static library) from a "Storage" location and insert it into
> the build process.
>
> If the project is built with all sources then everything is ok.
> When one or more sources from the modules are missing then I receive a
> dependency error (when NMake Makefiles and Unix Makefiles generator are used,
> with Visual Studio generator it works fine) :
>
> make[2]: *** No rule to make target `library/modules/module1', needed by `bin/executable'.  Stop.
>
> Thank you.
>


More information about the CMake mailing list