Skip to content

Commit aa02a72

Browse files
hkareldavemccann
authored andcommitted
Partially revert commit 0733aeb to make dll.h a non-generated file (jbeder#1064)
Partial revert of "Revert "Revert "Hide most of non-public symbols by default (jbeder#984)" (jbeder#1038)" (jbeder#1045)" This reverts commit 0733aeb.
1 parent 70e1416 commit aa02a72

File tree

2 files changed

+58
-43
lines changed

2 files changed

+58
-43
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: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,61 @@
11
#ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
22
#define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
33

4-
#if defined(_MSC_VER) || \
5-
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6-
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7-
#pragma once
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
851
#endif
952

10-
// The following ifdef block is the standard way of creating macros which make
11-
// exporting from a DLL simpler. All files within this DLL are compiled with the
12-
// yaml_cpp_EXPORTS symbol defined on the command line. This symbol should not
13-
// be defined on any project that uses this DLL. This way any other project
14-
// whose source files include this file see YAML_CPP_API functions as being
15-
// imported from a DLL, whereas this DLL sees symbols defined with this macro as
16-
// being exported.
17-
#undef YAML_CPP_API
53+
#ifndef YAML_CPP_DEPRECATED_EXPORT
54+
# define YAML_CPP_DEPRECATED_EXPORT YAML_CPP_API YAML_CPP_DEPRECATED
55+
#endif
1856

19-
#ifdef YAML_CPP_DLL // Using or Building YAML-CPP DLL (definition defined
20-
// manually)
21-
#ifdef yaml_cpp_EXPORTS // Building YAML-CPP DLL (definition created by CMake
22-
// or defined manually)
23-
// #pragma message( "Defining YAML_CPP_API for DLL export" )
24-
#define YAML_CPP_API __declspec(dllexport)
25-
#else // yaml_cpp_EXPORTS
26-
// #pragma message( "Defining YAML_CPP_API for DLL import" )
27-
#define YAML_CPP_API __declspec(dllimport)
28-
#endif // yaml_cpp_EXPORTS
29-
#else // YAML_CPP_DLL
30-
#define YAML_CPP_API
31-
#endif // YAML_CPP_DLL
57+
#ifndef YAML_CPP_DEPRECATED_NO_EXPORT
58+
# define YAML_CPP_DEPRECATED_NO_EXPORT YAML_CPP_NO_EXPORT YAML_CPP_DEPRECATED
59+
#endif
3260

33-
#endif // DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
61+
#endif /* DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 */

0 commit comments

Comments
 (0)