CMakeLists.txt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. cmake_minimum_required (VERSION 2.6)
  2. project(VSExternalInclude)
  3. if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[01245]")
  4. set(PROJECT_EXT vcxproj)
  5. else()
  6. set(PROJECT_EXT vcproj)
  7. endif()
  8. # make sure directories exists
  9. set(LIB1_BINARY_DIR ${VSExternalInclude_BINARY_DIR}/Lib1)
  10. make_directory("${LIB1_BINARY_DIR}")
  11. set(LIB2_BINARY_DIR ${VSExternalInclude_BINARY_DIR}/Lib2)
  12. make_directory("${LIB2_BINARY_DIR}")
  13. # generate lib1
  14. execute_process(
  15. COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
  16. -A "${CMAKE_GENERATOR_PLATFORM}"
  17. -T "${CMAKE_GENERATOR_TOOLSET}" "${VSExternalInclude_SOURCE_DIR}/Lib1"
  18. WORKING_DIRECTORY ${LIB1_BINARY_DIR}
  19. OUTPUT_VARIABLE OUT
  20. ERROR_VARIABLE OUT
  21. )
  22. message("CMAKE Ran with the following output:\n\"${OUT}\"")
  23. # generate lib2
  24. execute_process(
  25. COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
  26. -A "${CMAKE_GENERATOR_PLATFORM}"
  27. -T "${CMAKE_GENERATOR_TOOLSET}" "${VSExternalInclude_SOURCE_DIR}/Lib2"
  28. WORKING_DIRECTORY ${LIB2_BINARY_DIR}
  29. OUTPUT_VARIABLE OUT
  30. ERROR_VARIABLE OUT
  31. )
  32. message("CMAKE Ran with the following output:\n\"${OUT}\"")
  33. include_external_msproject(lib1 ${VSExternalInclude_BINARY_DIR}/Lib1/LIB1.${PROJECT_EXT})
  34. # lib2 depends on lib1
  35. include_external_msproject(lib2 ${VSExternalInclude_BINARY_DIR}/Lib2/LIB2.${PROJECT_EXT} lib1)
  36. include_directories(${VSExternalInclude_SOURCE_DIR}/Lib2 ${VSExternalInclude_SOURCE_DIR}/Lib1)
  37. set(SOURCES main.cpp)
  38. add_executable(VSExternalInclude ${SOURCES})
  39. # target depends on lib2
  40. add_dependencies(VSExternalInclude lib2)
  41. # VS 10 vcxproj files have depends in them
  42. # Since lib1 and lib2 do not depend on each other
  43. # then the vcxproj files do not depend on each other
  44. # and the sln file can no longer be the only source
  45. # of that depend. So, for VS 10 make the executable
  46. # depend on lib1 and lib2
  47. if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[01245]")
  48. add_dependencies(VSExternalInclude lib1)
  49. endif()
  50. # Interaction testing between the FOLDER target property and
  51. # INCLUDE_EXTERNAL_MSPROJECT targets:
  52. set_target_properties(VSExternalInclude PROPERTIES FOLDER folder1/folder2)
  53. set_target_properties(lib1 PROPERTIES FOLDER folder1/folder2)
  54. set_target_properties(lib2 PROPERTIES FOLDER folder1/folder2)
  55. add_custom_target(EmptyCustomTarget)
  56. set_target_properties(EmptyCustomTarget PROPERTIES FOLDER folder1/folder2)
  57. set_property(GLOBAL PROPERTY USE_FOLDERS ON)