Skip to content

Commit

Permalink
Use CMake visibility flags (AcademySoftwareFoundation#1411)
Browse files Browse the repository at this point in the history
* Update install doc minimal version numbers

Signed-off-by: Rémi Achard <remiachard@gmail.com>

* Use CMake visibility presets variables

Signed-off-by: Rémi Achard <remiachard@gmail.com>

* Fix python package case

Signed-off-by: Rémi Achard <remiachard@gmail.com>

* Allow advanced user to override symbol visibility

Signed-off-by: Rémi Achard <remiachard@gmail.com>

Co-authored-by: Patrick Hodoul <patrick.hodoul@autodesk.com>
Signed-off-by: Patrick Hodoul <Patrick.Hodoul@autodesk.com>
  • Loading branch information
remia and hodoulp committed Jun 28, 2021
1 parent 80d2d4e commit 09f4d22
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 36 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ option(OCIO_WARNING_AS_ERROR "Set build error level for CI testing" OFF)
# Optimization / internal linking preferences

option(OCIO_USE_SSE "Specify whether to enable SSE CPU performance optimizations" ON)
option(OCIO_INLINES_HIDDEN "Specify whether to build with -fvisibility-inlines-hidden" ${UNIX})


###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions docs/quick_start/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ default, cmake will try to install all of the items labelled with * and so
it is not necessary to install those items manually:

- cmake >= 3.12
- \*Expat >= 2.2.5 (XML parser for CDL/CLF/CTF)
- \*Expat >= 2.2.8 (XML parser for CDL/CLF/CTF)
- \*yaml-cpp >= 0.6.3 (YAML parser for Configs)
- \*IlmBase (Half only) >= 2.3.0 (for half domain LUTs)
- \*IlmBase (Half only) >= 2.4.0 (for half domain LUTs)
- \*pystring >= 1.1.3

Some optional components also depend on:

- \*Little CMS >= 2.2 (for ociobakelut ICC profile baking)
- \*pybind11 >= 2.4.3 (for the Python bindings)
- \*pybind11 >= 2.6.1 (for the Python bindings)
- Python >= 2.7 (for the Python bindings)
- Python 3.7 or 3.8 (for the docs, with the following PyPi packages)
- Sphinx
Expand Down
13 changes: 13 additions & 0 deletions share/cmake/macros/VariableUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.
#
# General CMake utility macros.
#

macro(set_unless_defined var_name var_default)
if(NOT DEFINED ${var_name})
set(${var_name} ${var_default})
else()
message(STATUS "Variable explicitly defined: ${var_name} = ${${var_name}}")
endif()
endmacro()
10 changes: 3 additions & 7 deletions share/cmake/modules/FindHalf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ if(NOT Half_FOUND)
"${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}Half-${_Half_LIB_VER}${_Half_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")

if(_Half_TARGET_CREATE)
if(UNIX)
set(Half_CXX_FLAGS "${Half_CXX_FLAGS} -fvisibility=hidden -fPIC")
if(OCIO_INLINES_HIDDEN)
set(Half_CXX_FLAGS "${Half_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()
endif()

if(MSVC)
set(Half_CXX_FLAGS "${Half_CXX_FLAGS} /EHsc")
endif()
Expand All @@ -173,6 +166,9 @@ if(NOT Half_FOUND)

set(Half_CMAKE_ARGS
${Half_CMAKE_ARGS}
-DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET}
-DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_FLAGS=${Half_CXX_FLAGS}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
Expand Down
13 changes: 5 additions & 8 deletions share/cmake/modules/Findexpat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ if(NOT expat_FOUND)
"${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}expat${_expat_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")

if(_expat_TARGET_CREATE)
if(UNIX)
set(EXPAT_C_FLAGS "${EXPAT_C_FLAGS} -fvisibility=hidden -fPIC")
set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} -fvisibility=hidden -fPIC")
if(OCIO_INLINES_HIDDEN)
set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()
endif()

if(MSVC)
set(EXPAT_C_FLAGS "${EXPAT_C_FLAGS} /EHsc")
set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} /EHsc")
Expand All @@ -172,6 +164,11 @@ if(NOT expat_FOUND)

set(EXPAT_CMAKE_ARGS
${EXPAT_CMAKE_ARGS}
-DCMAKE_POLICY_DEFAULT_CMP0063=NEW
-DCMAKE_C_VISIBILITY_PRESET=${CMAKE_C_VISIBILITY_PRESET}
-DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET}
-DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS=${EXPAT_C_FLAGS}
-DCMAKE_CXX_FLAGS=${EXPAT_CXX_FLAGS}
Expand Down
10 changes: 3 additions & 7 deletions share/cmake/modules/Findpystring.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ if(NOT pystring_FOUND)
"${_EXT_DIST_ROOT}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}pystring${CMAKE_STATIC_LIBRARY_SUFFIX}")

if(_pystring_TARGET_CREATE)
if(UNIX)
set(pystring_CXX_FLAGS "${pystring_CXX_FLAGS} -fvisibility=hidden -fPIC")
if(OCIO_INLINES_HIDDEN)
set(pystring_CXX_FLAGS "${pystring_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()
endif()

if(MSVC)
set(pystring_CXX_FLAGS "${pystring_CXX_FLAGS} /EHsc")
endif()
Expand All @@ -103,6 +96,9 @@ if(NOT pystring_FOUND)

set(pystring_CMAKE_ARGS
${pystring_CMAKE_ARGS}
-DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET}
-DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_FLAGS=${pystring_CXX_FLAGS}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
Expand Down
10 changes: 4 additions & 6 deletions share/cmake/modules/Findyaml-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ if(NOT yaml-cpp_FOUND)
endif()

if(UNIX)
set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} -fvisibility=hidden -fPIC")

if(OCIO_INLINES_HIDDEN)
set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} -fvisibility-inlines-hidden")
endif()

if(USE_CLANG)
# Remove some global 'shadow' warnings.
set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} -Wno-shadow")
Expand All @@ -175,6 +169,10 @@ if(NOT yaml-cpp_FOUND)

set(yaml-cpp_CMAKE_ARGS
${yaml-cpp_CMAKE_ARGS}
-DCMAKE_POLICY_DEFAULT_CMP0063=NEW
-DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET}
-DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_FLAGS=${yaml-cpp_CXX_FLAGS}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
Expand Down
14 changes: 10 additions & 4 deletions share/cmake/utils/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ if(USE_GCC OR USE_CLANG)
set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -Werror")
endif()

if(OCIO_INLINES_HIDDEN)
set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -fvisibility-inlines-hidden")
endif()

if(APPLE)
# TODO: There are still some deprecated methods.
set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -Wno-deprecated-declarations")
Expand All @@ -72,6 +68,16 @@ endif()
mark_as_advanced(PLATFORM_COMPILE_FLAGS)


###############################################################################
# Define hidden symbol visibility by default for all targets.

include(VariableUtils)

set_unless_defined(CMAKE_C_VISIBILITY_PRESET hidden)
set_unless_defined(CMAKE_CXX_VISIBILITY_PRESET hidden)
set_unless_defined(CMAKE_VISIBILITY_INLINES_HIDDEN YES)


###############################################################################
# Define if SSE2 can be used.

Expand Down

0 comments on commit 09f4d22

Please sign in to comment.