I try to correctly manage the dependence of the goal on an external library, and for some reason I fail. I read a lot of tutorials, posts, and examples, but since I'm new to CMake, I think I'm missing the obvious thing.
The setting is as follows. An external library built in another (unsupported CMake language) language creates libadatest.a. For this, I used ExternalProject_Add. Then there is another regular C target that uses this lib library. Everything works fine, but if I change the original lib, even if I recompile it, the target C will not be recompiled. Here is a complete sample. I am using CMake 2.8.12:
cmake_minimum_required(VERSION 2.8) include(ExternalProject) ExternalProject_Add( AdaTestExternal # Not important SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} BUILD_COMMAND gprbuild -P${CMAKE_CURRENT_SOURCE_DIR}/adalibtest -XOBJ_DIR=${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} -XLIB_DIR=${CMAKE_CURRENT_BINARY_DIR} ALWAYS 1 # Force build, gprbuild will take care of dependencies # BUILD_ALWAYS 1 # For 3.0 higher versions? INSTALL_COMMAND "" ) add_custom_target(AdaTest DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libadatest.a) link_directories(${CMAKE_CURRENT_BINARY_DIR}) # Needed or won't find it add_executable(main_ada main.c) add_dependencies(main_ada AdaTest) # We must depend on the final output lib target_link_libraries(main_ada adatest)
I tried to create an intermediate user target, which depends on the actual library and, in turn, makes the main goal of C depend on this target.
When I delete the external library (libadatest.a), which is correctly recompiled from the outside, but the main executable is not re-linked. It is easiest to see that the timestamp of the library is more recent than the executable file that uses it.
Edit: I also tried this instead of a custom target with the same negative result:
add_library(AdaTest UNKNOWN IMPORTED IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/libadatest.a)
source share