Skip to content

Commit f2fb806

Browse files
authored
profiling: update DatadogConfig cmake to be used for windows builds (#853)
1 parent e57ee81 commit f2fb806

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

cmake/DatadogConfig.cmake.in

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,37 @@ endif()
1111

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

14-
find_library(
15-
Datadog_LIBRARY
16-
NAMES datadog_profiling
17-
HINTS ${Datadog_ROOT}/lib)
14+
set(DD_LIB_NAME "datadog_profiling")
15+
16+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
17+
# Prefer static linking over dynamic unless specified
18+
set(LINK_TYPE "static")
19+
if (DEFINED VCRUNTIME_LINK_TYPE)
20+
string(TOLOWER ${VCRUNTIME_LINK_TYPE} LINK_TYPE)
21+
endif()
22+
23+
set(BUILD_TYPE "release")
24+
if (DEFINED CMAKE_BUILD_TYPE)
25+
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
26+
endif()
27+
28+
find_library(
29+
Datadog_LIBRARY
30+
# Windows artifacts publish the library as datadog_profiling_ffi
31+
# in {build_type}/{link_type} directory
32+
NAMES ${DD_LIB_NAME} datadog_profiling_ffi
33+
HINTS ${Datadog_ROOT}/lib ${Datadog_ROOT}/${BUILD_TYPE}/${LINK_TYPE})
34+
35+
# It could be either datadog_profiling or datadog_profiling_ffi, set it to the
36+
# one that is found
37+
get_filename_component(DD_LIB_NAME ${Datadog_LIBRARY} NAME_WE)
38+
message(STATUS "Datadog library name: ${DD_LIB_NAME}")
39+
else()
40+
find_library(
41+
Datadog_LIBRARY
42+
NAMES ${DD_LIB_NAME}
43+
HINTS ${Datadog_ROOT}/lib)
44+
endif()
1845

1946
find_package_handle_standard_args(Datadog DEFAULT_MSG Datadog_LIBRARY
2047
Datadog_INCLUDE_DIR)
@@ -24,15 +51,15 @@ if(Datadog_FOUND)
2451
set(Datadog_LIBRARIES ${Datadog_LIBRARY} "@Datadog_LIBRARIES@")
2552
mark_as_advanced(Datadog_ROOT Datadog_LIBRARY Datadog_INCLUDE_DIR)
2653

27-
add_library(datadog_profiling INTERFACE)
28-
target_include_directories(datadog_profiling
54+
add_library(${DD_LIB_NAME} INTERFACE)
55+
target_include_directories(${DD_LIB_NAME}
2956
INTERFACE ${Datadog_INCLUDE_DIRS})
30-
target_link_libraries(datadog_profiling INTERFACE ${Datadog_LIBRARIES})
31-
target_compile_features(datadog_profiling INTERFACE c_std_11)
57+
target_link_libraries(${DD_LIB_NAME} INTERFACE ${Datadog_LIBRARIES})
58+
target_compile_features(${DD_LIB_NAME} INTERFACE c_std_11)
3259

3360
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
3461
target_link_libraries(
35-
datadog_profiling
62+
${DD_LIB_NAME}
3663
INTERFACE NtDll
3764
UserEnv
3865
Bcrypt
@@ -45,7 +72,7 @@ if(Datadog_FOUND)
4572
PowrProf)
4673
endif()
4774

48-
add_library(Datadog::Profiling ALIAS datadog_profiling)
75+
add_library(Datadog::Profiling ALIAS ${DD_LIB_NAME})
4976
else()
5077
set(Datadog_ROOT
5178
""

0 commit comments

Comments
 (0)