|
| 1 | +cmake_minimum_required(VERSION 3.5) |
| 2 | +# |
| 3 | +# Builds PowerShell.Core.Instrumentation.dll resource-only DLL containing ETW event resources |
| 4 | +# |
| 5 | + |
| 6 | +# The fully qualified path to the event manifest |
| 7 | +SET(EVENTS_MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/PowerShell.Core.Instrumentation.man") |
| 8 | + |
| 9 | +# User mode manifest resource-only dll |
| 10 | +function(add_manifest_binary) |
| 11 | + |
| 12 | + add_definitions(-D_DLL=1) |
| 13 | + add_library(${ARGV}) |
| 14 | + |
| 15 | + # NOTE: EVENTS_MANIFEST must be the fully qualified path to the manifest |
| 16 | + SET(MC_MANIFEST_FULLNAME ${EVENTS_MANIFEST}) |
| 17 | + |
| 18 | + # get the ETW manifest's filename without the directory or extension |
| 19 | + get_filename_component(MC_MANIFEST_BASENAME ${EVENTS_MANIFEST} NAME_WE) |
| 20 | + |
| 21 | + SET(MC_COMMAND "mc.exe") |
| 22 | + SET(GeneratedManifestFiles) |
| 23 | + |
| 24 | + # The target directory for generated managed files |
| 25 | + SET (MC_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}") |
| 26 | + |
| 27 | + # include the generated directory in the include path |
| 28 | + include_directories("${MC_GENERATED_DIR}") |
| 29 | + |
| 30 | + SET (MC_GENERATED_FILES |
| 31 | + ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}.rc |
| 32 | + ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}TEMP.BIN |
| 33 | + ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}_MSG00001.BIN |
| 34 | + ) |
| 35 | + |
| 36 | + SET(MC_COMMAND "mc.exe -h ${MC_GENERATED_DIR} -r ${MC_GENERATED_DIR} ${MC_MANIFEST_FULLNAME}") |
| 37 | + |
| 38 | + add_custom_command( |
| 39 | + COMMENT "Generating native event manifest files for ${EVENTS_MANIFEST}" |
| 40 | + OUTPUT ${MC_GENERATED_FILES} |
| 41 | + DEPENDS ${MC_MANIFEST_FULLNAME} |
| 42 | + COMMAND cmd.exe /c ${MC_COMMAND} |
| 43 | + WORKING_DIRECTORY ${MC_GENERATED_DIR} |
| 44 | + VERBATIM |
| 45 | + ) |
| 46 | + |
| 47 | + list (APPEND GeneratedManifestFiles ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}.rc) |
| 48 | + |
| 49 | + set_source_files_properties(${GeneratedManifestFiles} PROPERTIES GENERATED TRUE) |
| 50 | + add_custom_target(GeneratedManifestFiles DEPENDS ${GeneratedManifestFiles}) |
| 51 | + |
| 52 | + # for a resource only dll, cmake can report an error |
| 53 | + # if there is no linker language set. |
| 54 | + # CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly. |
| 55 | + # Missing variable is: CMAKE_RC_CREATE_SHARED_LIBRARY |
| 56 | + get_property(isSet TARGET ${ARGV0} PROPERTY LINKER_LANGUAGE SET) |
| 57 | + if (NOT ${isSet}) |
| 58 | + set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX") |
| 59 | + endif() |
| 60 | + |
| 61 | + set_target_properties(${ARGV0} PROPERTIES LINK_FLAGS "/NODEFAULTLIB /NOENTRY") |
| 62 | + |
| 63 | + if (BUILD_ONECORE) |
| 64 | + set_target_properties(${ARGV0} PROPERTIES COMPILE_DEFINITIONS "CORECLR") |
| 65 | + endif (BUILD_ONECORE) |
| 66 | + |
| 67 | + # ensure the target is dependent on the generated files. |
| 68 | + add_dependencies(${ARGV0} GeneratedManifestFiles) |
| 69 | + |
| 70 | +endfunction() |
| 71 | + |
| 72 | +file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/version.rc) |
| 73 | + |
| 74 | +add_manifest_binary(PowerShell.Core.Instrumentation SHARED ${SOURCES}) |
| 75 | + |
0 commit comments