Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: export symbols selectively #619

Merged
merged 1 commit into from
Mar 30, 2021
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
49 changes: 18 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ endif (POLICY CMP0063)
project(glog VERSION 0.5.0 LANGUAGES C CXX)

set (CPACK_PACKAGE_NAME glog)
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Google logging library")
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})

option (WITH_GFLAGS "Use gflags" ON)
option (WITH_THREADS "Enable multithreading support" ON)
option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON)
option (BUILD_SHARED_LIBS "Build shared libraries" OFF)
option (PRINT_UNSYMBOLIZED_STACK_TRACES
"Print file offsets in traces instead of symbolizing" OFF)
option (WITH_GFLAGS "Use gflags" ON)
option (WITH_PKGCONFIG "Enable pkg-config support" ON)
option (WITH_UNWIND "Enable libunwind support" ON)
option (WITH_SYMBOLIZE "Enable symbolize module" ON)
option (WITH_THREADS "Enable multithreading support" ON)
option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON)
option (WITH_UNWIND "Enable libunwind support" ON)

if (NOT WITH_UNWIND)
set (CMAKE_DISABLE_FIND_PACKAGE_Unwind ON)
Expand All @@ -35,6 +35,9 @@ if (NOT WITH_THREADS)
set (CMAKE_DISABLE_FIND_PACKAGE_Threads ON)
endif (NOT WITH_THREADS)

set (CMAKE_C_VISIBILITY_PRESET hidden)
set (CMAKE_CXX_VISIBILITY_PRESET hidden)
set (CMAKE_VISIBILITY_INLINES_HIDDEN 1)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include (CheckCSourceCompiles)
Expand All @@ -53,6 +56,7 @@ include (CMakePushCheckState)
include (CPack)
include (CTest)
include (DetermineGflagsNamespace)
include (GenerateExportHeader)
include (GetCacheVariables)
include (GNUInstallDirs)

Expand Down Expand Up @@ -295,6 +299,7 @@ endif (STL_STD_NAMESPACE)
set (GOOGLE_NAMESPACE google)
set (_START_GOOGLE_NAMESPACE_ "namespace ${GOOGLE_NAMESPACE} {")
set (_END_GOOGLE_NAMESPACE_ "}")
set (ac_cv_have_glog_export 1)

if (HAVE___UINT16)
set (ac_cv_have___uint16 1)
Expand Down Expand Up @@ -442,6 +447,7 @@ configure_file (src/glog/logging.h.in glog/logging.h @ONLY)
configure_file (src/glog/raw_logging.h.in glog/raw_logging.h @ONLY)
configure_file (src/glog/stl_logging.h.in glog/stl_logging.h @ONLY)
configure_file (src/glog/vlog_is_on.h.in glog/vlog_is_on.h @ONLY)

if (WITH_PKGCONFIG)
set (VERSION ${PROJECT_VERSION})
set (prefix ${CMAKE_INSTALL_PREFIX})
Expand All @@ -462,10 +468,8 @@ if (WITH_PKGCONFIG)
unset (includedir)
endif (WITH_PKGCONFIG)

set (CMAKE_CXX_VISIBILITY_PRESET default)
set (CMAKE_VISIBILITY_INLINES_HIDDEN 1)

set (GLOG_PUBLIC_H
${CMAKE_CURRENT_BINARY_DIR}/glog/export.h
${CMAKE_CURRENT_BINARY_DIR}/glog/logging.h
${CMAKE_CURRENT_BINARY_DIR}/glog/raw_logging.h
${CMAKE_CURRENT_BINARY_DIR}/glog/stl_logging.h
Expand Down Expand Up @@ -545,7 +549,7 @@ add_library (glog
${_glog_BINARY_CMake_MODULES}
)

add_library(glog::glog ALIAS glog)
add_library (glog::glog ALIAS glog)

set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)

Expand Down Expand Up @@ -602,28 +606,11 @@ if (WIN32)
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows)
endif (WIN32)

set_target_properties (glog PROPERTIES DEFINE_SYMBOL LIBGLOG_EXPORTS)

if (NOT BUILD_SHARED_LIBS)
target_compile_definitions (glog PUBLIC GOOGLE_GLOG_DLL_DECL=)
else (NOT BUILD_SHARED_LIBS)
target_compile_definitions (glog PRIVATE GOOGLE_GLOG_IS_A_DLL=1)

if (HAVE___DECLSPEC)
set (_EXPORT "__declspec(dllexport)")
set (_IMPORT "__declspec(dllimport)")
elseif (HAVE___ATTRIBUTE__VISIBILITY_DEFAULT)
set (_EXPORT "__attribute__((visibility(\"default\")))")
set (_IMPORT "")
endif (HAVE___DECLSPEC)

target_compile_definitions (glog PRIVATE
"GOOGLE_GLOG_DLL_DECL=${_EXPORT}")
target_compile_definitions (glog INTERFACE
"GOOGLE_GLOG_DLL_DECL=${_IMPORT}")
target_compile_definitions (glog INTERFACE
"GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS=${_IMPORT}")
endif (NOT BUILD_SHARED_LIBS)
generate_export_header (glog
EXPORT_MACRO_NAME GOOGLE_GLOG_DLL_DECL
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/glog/export.h)

set_target_properties (glog PROPERTIES DEFINE_SYMBOL GOOGLE_GLOG_IS_A_DLL)

# Unit testing

Expand Down
6 changes: 5 additions & 1 deletion src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
#define GLOG_MSVC_POP_WARNING()
#endif

#if @ac_cv_have_glog_export@
#include "glog/export.h"
#endif

// Annoying stuff for windows -- makes sure clients can import these functions
#ifndef GOOGLE_GLOG_DLL_DECL
# if defined(_WIN32) && !defined(__CYGWIN__)
Expand Down Expand Up @@ -86,7 +90,7 @@
#include <gflags/gflags.h>
#endif

#if HAVE_CXX11_ATOMIC
#ifdef HAVE_CXX11_ATOMIC
#include <atomic>
#elif defined(OS_WINDOWS)
#include <Windows.h>
Expand Down
1 change: 1 addition & 0 deletions src/symbolize.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef int (*SymbolizeCallback)(int fd,
char* out,
size_t out_size,
uint64_t relocation);
GOOGLE_GLOG_DLL_DECL
void InstallSymbolizeCallback(SymbolizeCallback callback);

// Installs a callback function, which will be called instead of
Expand Down