VisibilityInlinesHidden: only apply -fvisibility-inlines-hidden to C++ sources
This commit is contained in:
parent
f35c01e2a5
commit
efdcebddbd
|
@ -2187,7 +2187,11 @@ void cmLocalGenerator
|
|||
return;
|
||||
}
|
||||
AddVisibilityCompileOption(flags, target, this, lang);
|
||||
|
||||
if(strcmp(lang, "CXX") == 0)
|
||||
{
|
||||
AddInlineVisibilityCompileOption(flags, target, this);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -400,6 +400,29 @@ if(BUILD_TESTING)
|
|||
ADD_TEST_MACRO(PositionIndependentTargets PositionIndependentTargets)
|
||||
endif()
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND
|
||||
(NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 4.2) AND
|
||||
(CMAKE_SYSTEM_NAME MATCHES "Linux"))
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag(
|
||||
-fvisibility-inlines-hidden run_inlines_hidden_test)
|
||||
endif()
|
||||
|
||||
if(run_inlines_hidden_test)
|
||||
add_test(VisibilityInlinesHidden ${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/VisibilityInlinesHidden"
|
||||
"${CMake_BINARY_DIR}/Tests/VisibilityInlinesHidden"
|
||||
${build_generator_args}
|
||||
--build-project VisibilityInlinesHidden
|
||||
--build-options ${build_options}
|
||||
)
|
||||
list(APPEND TEST_BUILD_DIRS
|
||||
"${CMake_BINARY_DIR}/Tests/VisibilityInlinesHidden"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_test(LinkFlags-prepare
|
||||
${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
|
||||
--build-and-test
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(VisibilityInlinesHidden)
|
||||
|
||||
add_library(inlines_hidden SHARED foo.cpp bar.c)
|
||||
set_property(TARGET inlines_hidden PROPERTY VISIBILITY_INLINES_HIDDEN ON)
|
||||
target_compile_options(inlines_hidden PRIVATE -Werror)
|
||||
|
||||
add_custom_command(TARGET inlines_hidden POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DCMAKE_NM=${CMAKE_NM}
|
||||
-DTEST_LIBRARY_PATH=$<TARGET_FILE:inlines_hidden>
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/verify.cmake
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
void bar() {}
|
|
@ -0,0 +1,11 @@
|
|||
class Foo
|
||||
{
|
||||
public:
|
||||
void bar() {}
|
||||
};
|
||||
|
||||
void baz()
|
||||
{
|
||||
Foo foo;
|
||||
foo.bar();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
execute_process(COMMAND ${CMAKE_NM} -D ${TEST_LIBRARY_PATH}
|
||||
RESULT_VARIABLE RESULT
|
||||
OUTPUT_VARIABLE OUTPUT
|
||||
ERROR_VARIABLE ERROR
|
||||
)
|
||||
|
||||
if(NOT "${RESULT}" STREQUAL "0")
|
||||
message(FATAL_ERROR "nm failed [${RESULT}] [${OUTPUT}] [${ERROR}]")
|
||||
endif()
|
||||
|
||||
if(${OUTPUT} MATCHES "Foo[^\\n]*bar")
|
||||
message(FATAL_ERROR
|
||||
"Found Foo::bar() which should have been hidden [${OUTPUT}]")
|
||||
endif()
|
Loading…
Reference in New Issue