summaryrefslogtreecommitdiffstats
path: root/Tests/PDBDirectoryAndName/CMakeLists.txt
blob: 180f9fea2134b2676a0e80fdb651b01a5d6c6995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
cmake_minimum_required(VERSION 2.8)
project(PDBDirectoryAndName C)

# Make sure the proper compiler is in use.
if(NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
  message(FATAL_ERROR "The PDBDirectoryAndName test works only with MSVC or Intel")
endif()

# Intel 11.1 does not support /Fd but Intel 14.0 does.
# TODO: Did a version in between these add it?
if(CMAKE_C_COMPILER_ID STREQUAL Intel AND
   CMAKE_C_COMPILER_VERSION VERSION_LESS 14.0)
  set(NO_COMPILE_PDB 1)
endif()

set(my_targets "")

add_library(mylibA SHARED mylibA.c)
set_target_properties(mylibA PROPERTIES
    PDB_NAME "mylibA_Special"
    PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB"
)
list(APPEND my_targets mylibA)

add_library(mylibB STATIC mylibB.c)
set_target_properties(mylibB PROPERTIES
    COMPILE_PDB_NAME "mylibB_Special"
    COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibB_PDB"
)
if(NOT NO_COMPILE_PDB)
  list(APPEND my_targets mylibB)
endif()

add_library(mylibC SHARED mylibC.c)
set_target_properties(mylibC PROPERTIES
    PDB_NAME "mylibC_Special"
)
list(APPEND my_targets mylibC)

add_library(mylibD STATIC mylibD.c)
set_target_properties(mylibD PROPERTIES
    COMPILE_PDB_NAME "mylibD_Special"
)
if(NOT NO_COMPILE_PDB)
  list(APPEND my_targets mylibD)
endif()

add_executable(myexe myexe.c)
set_target_properties(myexe PROPERTIES
    PDB_NAME "myexe_Special"
    PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/myexe_PDB"
)
list(APPEND my_targets myexe)

target_link_libraries(myexe mylibA mylibB mylibC mylibD)

add_executable(myexe2 myexe2.c)
set_target_properties(myexe2 PROPERTIES
    PDB_NAME "myexe2_Special"
)
list(APPEND my_targets myexe2)

target_link_libraries(myexe2 mylibA mylibD)

#-----------------------------------------------------------------------------
# Check that PDB files actually appear where expected.

# The PDB_NAME and PDB_OUTPUT_DIRECTORY options do not work in VS 6.
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
  return()
endif()

set(pdbs "")
foreach(t ${my_targets})
  get_property(pdb_name TARGET ${t} PROPERTY PDB_NAME)
  get_property(pdb_dir TARGET ${t} PROPERTY PDB_OUTPUT_DIRECTORY)
  if(NOT pdb_name)
    get_property(pdb_name TARGET ${t} PROPERTY COMPILE_PDB_NAME)
  endif()
  if(NOT pdb_dir)
    get_property(pdb_dir TARGET ${t} PROPERTY COMPILE_PDB_OUTPUT_DIRECTORY)
  endif()
  if(NOT pdb_dir)
    set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
  endif()
  list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
endforeach()
add_custom_target(check_pdbs ALL VERBATIM
  COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"
                           -P ${CMAKE_CURRENT_SOURCE_DIR}/check_pdbs.cmake
  )
add_dependencies(check_pdbs ${my_targets})