Skip to content

Commit

Permalink
profiling: update DatadogConfig cmake to be used for windows builds (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
taegyunkim authored Feb 5, 2025
1 parent e57ee81 commit f2fb806
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions cmake/DatadogConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,37 @@ endif()

find_path(Datadog_INCLUDE_DIR datadog/profiling.h HINTS ${Datadog_ROOT}/include)

find_library(
Datadog_LIBRARY
NAMES datadog_profiling
HINTS ${Datadog_ROOT}/lib)
set(DD_LIB_NAME "datadog_profiling")

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Prefer static linking over dynamic unless specified
set(LINK_TYPE "static")
if (DEFINED VCRUNTIME_LINK_TYPE)
string(TOLOWER ${VCRUNTIME_LINK_TYPE} LINK_TYPE)
endif()

set(BUILD_TYPE "release")
if (DEFINED CMAKE_BUILD_TYPE)
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
endif()

find_library(
Datadog_LIBRARY
# Windows artifacts publish the library as datadog_profiling_ffi
# in {build_type}/{link_type} directory
NAMES ${DD_LIB_NAME} datadog_profiling_ffi
HINTS ${Datadog_ROOT}/lib ${Datadog_ROOT}/${BUILD_TYPE}/${LINK_TYPE})

# It could be either datadog_profiling or datadog_profiling_ffi, set it to the
# one that is found
get_filename_component(DD_LIB_NAME ${Datadog_LIBRARY} NAME_WE)
message(STATUS "Datadog library name: ${DD_LIB_NAME}")
else()
find_library(
Datadog_LIBRARY
NAMES ${DD_LIB_NAME}
HINTS ${Datadog_ROOT}/lib)
endif()

find_package_handle_standard_args(Datadog DEFAULT_MSG Datadog_LIBRARY
Datadog_INCLUDE_DIR)
Expand All @@ -24,15 +51,15 @@ if(Datadog_FOUND)
set(Datadog_LIBRARIES ${Datadog_LIBRARY} "@Datadog_LIBRARIES@")
mark_as_advanced(Datadog_ROOT Datadog_LIBRARY Datadog_INCLUDE_DIR)

add_library(datadog_profiling INTERFACE)
target_include_directories(datadog_profiling
add_library(${DD_LIB_NAME} INTERFACE)
target_include_directories(${DD_LIB_NAME}
INTERFACE ${Datadog_INCLUDE_DIRS})
target_link_libraries(datadog_profiling INTERFACE ${Datadog_LIBRARIES})
target_compile_features(datadog_profiling INTERFACE c_std_11)
target_link_libraries(${DD_LIB_NAME} INTERFACE ${Datadog_LIBRARIES})
target_compile_features(${DD_LIB_NAME} INTERFACE c_std_11)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_link_libraries(
datadog_profiling
${DD_LIB_NAME}
INTERFACE NtDll
UserEnv
Bcrypt
Expand All @@ -45,7 +72,7 @@ if(Datadog_FOUND)
PowrProf)
endif()

add_library(Datadog::Profiling ALIAS datadog_profiling)
add_library(Datadog::Profiling ALIAS ${DD_LIB_NAME})
else()
set(Datadog_ROOT
""
Expand Down

0 comments on commit f2fb806

Please sign in to comment.