Skip to content

Commit 0310011

Browse files
committed
Merge pull request #59 from thewtex/visibility-hidden
ENH: Use hidden visibility on the CLI library.
2 parents 8741068 + 8d607ff commit 0310011

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CMake/SEMMacroBuildCLI.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ macro(SEMMacroBuildCLI)
128128

129129
add_library(${CLP}Lib ${cli_library_type} ${${CLP}_SOURCE})
130130
set_target_properties(${CLP}Lib PROPERTIES COMPILE_FLAGS "-Dmain=ModuleEntryPoint")
131+
if(NOT WIN32 AND NOT CYGWIN AND ${cli_library_type} STREQUAL "SHARED")
132+
include(GenerateExportHeader)
133+
# The generated export header is not used, but this call is required to
134+
# define COMPILER_HAS_HIDDEN_VISIBILITY and USE_COMPILER_HIDDEN_VISIBILITY
135+
generate_export_header(${CLP}Lib)
136+
if(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
137+
set_property(TARGET ${CLP}Lib
138+
APPEND_STRING PROPERTY COMPILE_FLAGS " -DMODULE_HIDDEN_VISIBILITY")
139+
set_target_properties(${CLP}Lib PROPERTIES CXX_VISIBILITY_PRESET hidden)
140+
set_target_properties(${CLP}Lib PROPERTIES C_VISIBILITY_PRESET hidden)
141+
set_target_properties(${CLP}Lib PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
142+
endif()
143+
endif()
131144
if(DEFINED LOCAL_SEM_TARGET_LIBRARIES)
132145
target_link_libraries(${CLP}Lib ${LOCAL_SEM_TARGET_LIBRARIES})
133146
endif()

GenerateCLP/GenerateCLP.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ void GenerateExports(std::ostream &sout)
666666
{
667667
sout << "#ifdef _WIN32" << std::endl;
668668
sout << "#define Module_EXPORT __declspec(dllexport)" << std::endl;
669+
sout << "#elif defined(MODULE_HIDDEN_VISIBILITY)" << std::endl;
670+
sout << "#define Module_EXPORT __attribute__((visibility(\"default\")))" << std::endl;
669671
sout << "#else" << std::endl;
670672
sout << "#define Module_EXPORT" << std::endl;
671673
sout << "#endif" << std::endl;

0 commit comments

Comments
 (0)