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

Port from master to RB-2.0 - Use CMake visibility flags (#1411) #1428

Merged
merged 3 commits into from
Jul 13, 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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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 (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()
7 changes: 3 additions & 4 deletions share/cmake/modules/FindHalf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,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} -fPIC")
endif()

if(MSVC)
set(Half_CXX_FLAGS "${Half_CXX_FLAGS} /EHsc")
endif()
Expand All @@ -174,6 +170,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
10 changes: 5 additions & 5 deletions share/cmake/modules/Findexpat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,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} -fPIC")
set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} -fPIC")
endif()

if(MSVC)
set(EXPAT_C_FLAGS "${EXPAT_C_FLAGS} /EHsc")
set(EXPAT_CXX_FLAGS "${EXPAT_CXX_FLAGS} /EHsc")
Expand All @@ -173,6 +168,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 @@ -92,13 +92,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 @@ -107,6 +100,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: 7 additions & 3 deletions share/cmake/modules/Findyaml-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,20 @@ 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")
if(USE_CLANG)
# Remove some global 'shadow' warnings.
set(yaml-cpp_CXX_FLAGS "${yaml-cpp_CXX_FLAGS} -Wno-shadow")
endif()
endif()

string(STRIP "${yaml-cpp_CXX_FLAGS}" yaml-cpp_CXX_FLAGS)

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 @@ -54,10 +54,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)
# Mute the deprecated warning for some GLUT methods.
set(PLATFORM_COMPILE_FLAGS "${PLATFORM_COMPILE_FLAGS} -Wno-deprecated-declarations")
Expand All @@ -70,6 +66,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