CMakeLists.txt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. cmake_minimum_required(VERSION 2.8)
  2. project(LinkDirectory C)
  3. # Put the subproject source tree in our build tree so it can refer to
  4. # link directories relative to its source.
  5. if(NOT "${LinkDirectory_SOURCE_DIR}" STREQUAL "${LinkDirectory_BINARY_DIR}")
  6. file(COPY External/ DESTINATION External PATTERN CVS EXCLUDE)
  7. endif()
  8. # Build a library into the subproject source tree.
  9. add_library(mylibA STATIC mylibA.c)
  10. set_property(TARGET mylibA PROPERTY
  11. ARCHIVE_OUTPUT_DIRECTORY "${LinkDirectory_BINARY_DIR}/External/lib")
  12. # Build a library into our build tree relative to the subproject build tree.
  13. add_library(mylibB STATIC mylibB.c)
  14. set_property(TARGET mylibB PROPERTY
  15. ARCHIVE_OUTPUT_DIRECTORY "${LinkDirectory_BINARY_DIR}/lib")
  16. # Create a custom target to drive the subproject build.
  17. include(ExternalProject)
  18. ExternalProject_Add(ExternalTarget
  19. SOURCE_DIR "${LinkDirectory_BINARY_DIR}/External"
  20. BINARY_DIR "${LinkDirectory_BINARY_DIR}/External-build"
  21. CMAKE_ARGS "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${LinkDirectory_BINARY_DIR}/bin"
  22. PREFIX "${LinkDirectory_BINARY_DIR}/External-build/root"
  23. DOWNLOAD_COMMAND ""
  24. INSTALL_COMMAND ""
  25. )
  26. # Add a step to wipe out the subproject executable after our libraries
  27. # change. This is needed because the subproject cannot depend on them
  28. # directly because it does not know the full paths to the libraries.
  29. # (The purpose of this test is to check that link_directories works.)
  30. ExternalProject_Add_Step(ExternalTarget cleanup
  31. COMMAND ${CMAKE_COMMAND} -E remove_directory ${LinkDirectory_BINARY_DIR}/bin
  32. DEPENDEES download
  33. DEPENDERS configure
  34. DEPENDS mylibA mylibB
  35. "${LinkDirectory_BINARY_DIR}/External/CMakeLists.txt"
  36. "${LinkDirectory_BINARY_DIR}/External/myexe.c"
  37. )
  38. # Make the subproject build after our targets.
  39. add_dependencies(ExternalTarget mylibA mylibB)