Skip to content

Commit 534b59e

Browse files
committed
cmake: Set default visibility to hidden, if supported
1 parent fe60e96 commit 534b59e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occ
7676
option(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON)
7777
option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
7878
option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
79+
option(JSONCPP_VISIBILITY_HIDDEN "Build with default hidden visibility" ON)
7980
option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
8081

8182
# Enable runtime search path support for dynamic libraries on OSX
@@ -148,6 +149,16 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
148149
endif()
149150
endif()
150151

152+
include(CheckCXXCompilerFlag)
153+
154+
# Set default symbol visibility to 'hidden'
155+
if(JSONCPP_VISIBILITY_HIDDEN)
156+
check_cxx_compiler_flag("-fvisibility=hidden" VISIBILITY_HIDDEN_SUPPORTED)
157+
if (VISIBILITY_HIDDEN_SUPPORTED)
158+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
159+
endif()
160+
endif()
161+
151162
find_program(CCACHE_FOUND ccache)
152163
if(CCACHE_FOUND)
153164
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)

0 commit comments

Comments
 (0)