CMakeLists.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_minimum_required(VERSION 2.8)
  2. project(PDBDirectoryAndName C)
  3. # Make sure the proper compiler is in use.
  4. if(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")
  5. message(FATAL_ERROR "The PDBDirectoryAndName test works only with MSVC or Intel")
  6. endif()
  7. set(my_targets "")
  8. add_library(mylibA SHARED mylibA.c)
  9. set_target_properties(mylibA PROPERTIES
  10. PDB_NAME "mylibA_Special"
  11. PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB"
  12. )
  13. list(APPEND my_targets mylibA)
  14. add_library(mylibB STATIC mylibB.c)
  15. set_target_properties(mylibB PROPERTIES
  16. PDB_NAME "mylibB_Special"
  17. PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibB_PDB"
  18. )
  19. # TODO: The only .pdb available for a static library is that generated
  20. # by the compiler /Fd option which is not the same as the linker /pdb.
  21. # list(APPEND my_targets mylibB)
  22. add_library(mylibC SHARED mylibC.c)
  23. set_target_properties(mylibC PROPERTIES
  24. PDB_NAME "mylibC_Special"
  25. )
  26. list(APPEND my_targets mylibC)
  27. add_library(mylibD STATIC mylibD.c)
  28. set_target_properties(mylibD PROPERTIES
  29. PDB_NAME "mylibD_Special"
  30. )
  31. # TODO: See comment for mylibB.
  32. # list(APPEND my_targets mylibD)
  33. add_executable(myexe myexe.c)
  34. set_target_properties(myexe PROPERTIES
  35. PDB_NAME "myexe_Special"
  36. PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/myexe_PDB"
  37. )
  38. list(APPEND my_targets myexe)
  39. target_link_libraries(myexe mylibA mylibB mylibC mylibD)
  40. add_executable(myexe2 myexe2.c)
  41. set_target_properties(myexe2 PROPERTIES
  42. PDB_NAME "myexe2_Special"
  43. )
  44. list(APPEND my_targets myexe2)
  45. target_link_libraries(myexe2 mylibA mylibD)
  46. #-----------------------------------------------------------------------------
  47. # Check that PDB files actually appear where expected.
  48. # The PDB_NAME and PDB_OUTPUT_DIRECTORY options do not work in VS 6.
  49. if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  50. return()
  51. endif()
  52. set(pdbs "")
  53. foreach(t ${my_targets})
  54. get_property(pdb_name TARGET ${t} PROPERTY PDB_NAME)
  55. get_property(pdb_dir TARGET ${t} PROPERTY PDB_OUTPUT_DIRECTORY)
  56. if(NOT pdb_dir)
  57. set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
  58. endif()
  59. list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
  60. endforeach()
  61. add_custom_target(check_pdbs ALL VERBATIM
  62. COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"
  63. -P ${CMAKE_CURRENT_SOURCE_DIR}/check_pdbs.cmake
  64. )
  65. add_dependencies(check_pdbs ${my_targets})