Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
COMPATIBILITY AnyNewerVersion)

if (YAML_BUILD_SHARED_LIBS)
set(YAML_CPP_PKG_CONFIG_CFLAGS_PRIVATE "")
else()
set(YAML_CPP_PKG_CONFIG_CFLAGS_PRIVATE "-DYAML_CPP_STATIC_DEFINE")
endif()
configure_file(yaml-cpp.pc.in yaml-cpp.pc @ONLY)

if (YAML_CPP_INSTALL)
Expand Down
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ add_test(
COMMAND ${CMAKE_COMMAND}
-D YAML_CPP_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-P ${PROJECT_SOURCE_DIR}/test/cmake/verify-source-list.cmake)
add_test(
NAME yaml-cpp::pkg-config
COMMAND ${CMAKE_COMMAND}
-D YAML_CPP_PC_FILE=${PROJECT_BINARY_DIR}/yaml-cpp.pc
-D YAML_BUILD_SHARED_LIBS=${YAML_BUILD_SHARED_LIBS}
-P ${PROJECT_SOURCE_DIR}/test/cmake/verify-pkg-config.cmake)

if (build-windows-dll)
add_custom_command(
Expand Down
17 changes: 17 additions & 0 deletions test/cmake/verify-pkg-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if(NOT DEFINED YAML_CPP_PC_FILE)
message(FATAL_ERROR "YAML_CPP_PC_FILE is required")
endif()

file(READ "${YAML_CPP_PC_FILE}" yaml_cpp_pc)
set(static_define "Cflags.private: -DYAML_CPP_STATIC_DEFINE")
string(FIND "${yaml_cpp_pc}" "${static_define}" static_define_pos)

if(YAML_BUILD_SHARED_LIBS)
if(NOT static_define_pos EQUAL -1)
message(FATAL_ERROR
"Shared-library pkg-config metadata contains ${static_define}")
endif()
elseif(static_define_pos EQUAL -1)
message(FATAL_ERROR
"Static-library pkg-config metadata does not contain ${static_define}")
endif()
1 change: 1 addition & 0 deletions yaml-cpp.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Version: @YAML_CPP_VERSION@
Requires:
Libs: -L${libdir} -lyaml-cpp
Cflags: -I${includedir}
Cflags.private: @YAML_CPP_PKG_CONFIG_CFLAGS_PRIVATE@