CMakeLists.txt 2.3 KB

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