Skip to content

Commit 2b65c65

Browse files
authored
Partially revert commit 0733aeb to make dll.h a non-generated file (#1064)
Partial revert of "Revert "Revert "Hide most of non-public symbols by default (#984)" (#1038)" (#1045)" This reverts commit 0733aeb.
1 parent 328d2d8 commit 2b65c65

File tree

2 files changed

+65
-17
lines changed

2 files changed

+65
-17
lines changed

CMakeLists.txt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ include(CMakeDependentOption)
1414
include(CheckCXXCompilerFlag)
1515
include(GNUInstallDirs)
1616
include(CTest)
17-
include(GenerateExportHeader)
18-
19-
set(CMAKE_C_VISIBILITY_PRESET hidden)
20-
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
21-
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
2217

2318
find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format)
2419

@@ -36,11 +31,13 @@ cmake_dependent_option(YAML_MSVC_SHARED_RT
3631
"MSVC: Build yaml-cpp with shared runtime libs (/MD)" ON
3732
"MSVC" OFF)
3833

39-
set(yaml-cpp-type STATIC)
40-
set(yaml-cpp-label-postfix "static")
4134
if (YAML_BUILD_SHARED_LIBS)
4235
set(yaml-cpp-type SHARED)
4336
set(yaml-cpp-label-postfix "shared")
37+
else()
38+
set(yaml-cpp-type STATIC)
39+
set(yaml-cpp-label-postfix "static")
40+
add_definitions(-DYAML_CPP_STATIC_DEFINE)
4441
endif()
4542

4643
set(build-shared $<BOOL:${YAML_BUILD_SHARED_LIBS}>)
@@ -86,7 +83,6 @@ set_property(TARGET yaml-cpp
8683
target_include_directories(yaml-cpp
8784
PUBLIC
8885
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
89-
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
9086
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
9187
PRIVATE
9288
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
@@ -142,12 +138,6 @@ write_basic_package_version_file(
142138
"${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
143139
COMPATIBILITY AnyNewerVersion)
144140

145-
generate_export_header(yaml-cpp
146-
BASE_NAME YAML_CPP
147-
EXPORT_FILE_NAME "${PROJECT_BINARY_DIR}/include/yaml-cpp/dll.h"
148-
EXPORT_MACRO_NAME YAML_CPP_API
149-
)
150-
151141
configure_file(yaml-cpp.pc.in yaml-cpp.pc @ONLY)
152142

153143
if (YAML_CPP_INSTALL)
@@ -157,9 +147,6 @@ if (YAML_CPP_INSTALL)
157147
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
158148
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
159149
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
160-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
161-
FILES_MATCHING PATTERN "*.h")
162-
install(DIRECTORY ${PROJECT_BINARY_DIR}/include/
163150
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
164151
FILES_MATCHING PATTERN "*.h")
165152
install(EXPORT yaml-cpp-targets

include/yaml-cpp/dll.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2+
#define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3+
4+
// Definition YAML_CPP_STATIC_DEFINE using to building YAML-CPP as static
5+
// library (definition created by CMake or defined manually)
6+
7+
// Definition yaml_cpp_EXPORTS using to building YAML-CPP as dll/so library
8+
// (definition created by CMake or defined manually)
9+
10+
#ifdef YAML_CPP_STATIC_DEFINE
11+
# define YAML_CPP_API
12+
# define YAML_CPP_NO_EXPORT
13+
#else
14+
# if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
15+
# ifndef YAML_CPP_API
16+
# ifdef yaml_cpp_EXPORTS
17+
/* We are building this library */
18+
# pragma message( "Defining YAML_CPP_API for DLL export" )
19+
# define YAML_CPP_API __declspec(dllexport)
20+
# else
21+
/* We are using this library */
22+
# pragma message( "Defining YAML_CPP_API for DLL import" )
23+
# define YAML_CPP_API __declspec(dllimport)
24+
# endif
25+
# endif
26+
# ifndef YAML_CPP_NO_EXPORT
27+
# define YAML_CPP_NO_EXPORT
28+
# endif
29+
# else /* No _MSC_VER */
30+
# ifndef YAML_CPP_API
31+
# ifdef yaml_cpp_EXPORTS
32+
/* We are building this library */
33+
# define YAML_CPP_API __attribute__((visibility("default")))
34+
# else
35+
/* We are using this library */
36+
# define YAML_CPP_API __attribute__((visibility("default")))
37+
# endif
38+
# endif
39+
# ifndef YAML_CPP_NO_EXPORT
40+
# define YAML_CPP_NO_EXPORT __attribute__((visibility("hidden")))
41+
# endif
42+
# endif /* _MSC_VER */
43+
#endif /* YAML_CPP_STATIC_DEFINE */
44+
45+
#ifndef YAML_CPP_DEPRECATED
46+
# ifdef _MSC_VER
47+
# define YAML_CPP_DEPRECATED __declspec(deprecated)
48+
# else
49+
# define YAML_CPP_DEPRECATED __attribute__ ((__deprecated__))
50+
# endif
51+
#endif
52+
53+
#ifndef YAML_CPP_DEPRECATED_EXPORT
54+
# define YAML_CPP_DEPRECATED_EXPORT YAML_CPP_API YAML_CPP_DEPRECATED
55+
#endif
56+
57+
#ifndef YAML_CPP_DEPRECATED_NO_EXPORT
58+
# define YAML_CPP_DEPRECATED_NO_EXPORT YAML_CPP_NO_EXPORT YAML_CPP_DEPRECATED
59+
#endif
60+
61+
#endif /* DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 */

0 commit comments

Comments
 (0)