2012-09-25 05:30:42 +04:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2016-02-21 03:17:29 +03:00
|
|
|
cmake_policy(SET CMP0054 NEW)
|
2012-09-25 05:30:42 +04:00
|
|
|
project(PDBDirectoryAndName C)
|
|
|
|
|
2012-09-29 14:36:46 +04:00
|
|
|
# Make sure the proper compiler is in use.
|
2014-10-14 18:25:32 +04:00
|
|
|
if(NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
|
2012-09-29 14:36:46 +04:00
|
|
|
message(FATAL_ERROR "The PDBDirectoryAndName test works only with MSVC or Intel")
|
2012-09-25 05:30:42 +04:00
|
|
|
endif()
|
|
|
|
|
2014-02-24 23:15:21 +04:00
|
|
|
# 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()
|
|
|
|
|
2012-09-25 22:29:41 +04:00
|
|
|
set(my_targets "")
|
|
|
|
|
2012-09-25 05:30:42 +04:00
|
|
|
add_library(mylibA SHARED mylibA.c)
|
|
|
|
set_target_properties(mylibA PROPERTIES
|
|
|
|
PDB_NAME "mylibA_Special"
|
|
|
|
PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB"
|
|
|
|
)
|
2012-09-25 22:29:41 +04:00
|
|
|
list(APPEND my_targets mylibA)
|
2012-09-25 05:30:42 +04:00
|
|
|
|
|
|
|
add_library(mylibB STATIC mylibB.c)
|
|
|
|
set_target_properties(mylibB PROPERTIES
|
2014-02-24 23:15:21 +04:00
|
|
|
COMPILE_PDB_NAME "mylibB_Special"
|
|
|
|
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibB_PDB"
|
2012-09-25 05:30:42 +04:00
|
|
|
)
|
2014-02-24 23:15:21 +04:00
|
|
|
if(NOT NO_COMPILE_PDB)
|
|
|
|
list(APPEND my_targets mylibB)
|
|
|
|
endif()
|
2012-09-25 05:30:42 +04:00
|
|
|
|
|
|
|
add_library(mylibC SHARED mylibC.c)
|
|
|
|
set_target_properties(mylibC PROPERTIES
|
|
|
|
PDB_NAME "mylibC_Special"
|
|
|
|
)
|
2012-09-25 22:29:41 +04:00
|
|
|
list(APPEND my_targets mylibC)
|
2012-09-25 05:30:42 +04:00
|
|
|
|
|
|
|
add_library(mylibD STATIC mylibD.c)
|
|
|
|
set_target_properties(mylibD PROPERTIES
|
2014-02-24 23:15:21 +04:00
|
|
|
COMPILE_PDB_NAME "mylibD_Special"
|
2012-09-25 05:30:42 +04:00
|
|
|
)
|
2014-02-24 23:15:21 +04:00
|
|
|
if(NOT NO_COMPILE_PDB)
|
|
|
|
list(APPEND my_targets mylibD)
|
|
|
|
endif()
|
2012-09-25 05:30:42 +04:00
|
|
|
|
|
|
|
add_executable(myexe myexe.c)
|
|
|
|
set_target_properties(myexe PROPERTIES
|
|
|
|
PDB_NAME "myexe_Special"
|
|
|
|
PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/myexe_PDB"
|
|
|
|
)
|
2012-09-25 22:29:41 +04:00
|
|
|
list(APPEND my_targets myexe)
|
2012-09-25 05:30:42 +04:00
|
|
|
|
|
|
|
target_link_libraries(myexe mylibA mylibB mylibC mylibD)
|
|
|
|
|
|
|
|
add_executable(myexe2 myexe2.c)
|
|
|
|
set_target_properties(myexe2 PROPERTIES
|
|
|
|
PDB_NAME "myexe2_Special"
|
|
|
|
)
|
2012-09-25 22:29:41 +04:00
|
|
|
list(APPEND my_targets myexe2)
|
2012-09-25 05:30:42 +04:00
|
|
|
|
|
|
|
target_link_libraries(myexe2 mylibA mylibD)
|
2012-09-25 22:29:41 +04:00
|
|
|
|
2016-02-21 03:17:29 +03:00
|
|
|
|
|
|
|
# Clang/C2 does not produce pdb files for static libraries
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
|
|
|
|
CMAKE_C_SIMULATE_ID STREQUAL "MSVC")
|
|
|
|
list(REMOVE_ITEM my_targets mylibB mylibD)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2012-09-25 22:29:41 +04:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Check that PDB files actually appear where expected.
|
|
|
|
|
|
|
|
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)
|
2014-02-24 23:15:21 +04:00
|
|
|
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()
|
2012-09-25 22:29:41 +04:00
|
|
|
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})
|