Skip to content

Commit

Permalink
build: Partially revert AcademySoftwareFoundation#4193, the avoidance…
Browse files Browse the repository at this point in the history
… of add_blah wasn't necessary (AcademySoftwareFoundation#4273)

I misunderstood all along -- the add_compile_definitions,
add_compile_options, etc., aren't truly global, they are restricted to
targets in the same directory or below. They aren't really prone to
polluting "surrounding" projects when OIIO is used as a subproject.

So for simplicity, reverting that part and using the usual built-ins.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Jun 27, 2024
1 parent 3a58e63 commit 82f072a
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 142 deletions.
30 changes: 13 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,18 @@ message(STATUS "CMAKE_UNITY_BUILD_MODE = ${CMAKE_UNITY_BUILD_MODE}")
message(STATUS "CMAKE_UNITY_BUILD_BATCH_SIZE = ${CMAKE_UNITY_BUILD_BATCH_SIZE}")

option (OIIO_THREAD_ALLOW_DCLP "OIIO threads may use DCLP for speed" ON)
if (NOT OIIO_THREAD_ALLOW_DCLP)
add_compile_definitions (OIIO_THREAD_ALLOW_DCLP=0)
endif ()

set (TEX_BATCH_SIZE "" CACHE STRING "Force TextureSystem SIMD batch size (e.g. 16)")
if (TEX_BATCH_SIZE)
add_compile_definitions (OIIO_TEXTURE_SIMD_BATCH_WIDTH=${TEX_BATCH_SIZE})
endif ()
option (OIIO_TEX_IMPLEMENT_VARYINGREF "Implement the deprecated batch texture functions taking VaryingRef params" ON)
if (NOT OIIO_TEX_IMPLEMENT_VARYINGREF)
add_compile_definitions (OIIO_TEX_NO_IMPLEMENT_VARYINGREF=1)
endif ()

# Set the default namespace
set (${PROJ_NAME}_NAMESPACE ${PROJECT_NAME} CACHE STRING
Expand All @@ -140,6 +149,10 @@ list (APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/src/cmake/modules"
"${PROJECT_SOURCE_DIR}/src/cmake")

# Define OIIO_INTERNAL symbol only when building OIIO itself, will not be
# defined for downstream projects using OIIO.
add_compile_definitions (OIIO_INTERNAL=1)

include (GNUInstallDirs)

# Utilities
Expand Down Expand Up @@ -177,23 +190,6 @@ include_directories (
"${CMAKE_BINARY_DIR}/include/OpenImageIO"
)


# Define OIIO_INTERNAL symbol only when building OIIO itself, will not be
# defined for downstream projects using OIIO.
proj_add_compile_definitions (OIIO_INTERNAL=1)

if (NOT OIIO_THREAD_ALLOW_DCLP)
proj_add_compile_definitions (OIIO_THREAD_ALLOW_DCLP=0)
endif ()
if (TEX_BATCH_SIZE)
proj_add_compile_definitions (OIIO_TEXTURE_SIMD_BATCH_WIDTH=${TEX_BATCH_SIZE})
endif ()
if (NOT OIIO_TEX_IMPLEMENT_VARYINGREF)
proj_add_compile_definitions (OIIO_TEX_NO_IMPLEMENT_VARYINGREF=1)
endif ()



# Tell CMake to process the sub-directories
add_subdirectory (src/libutil)

Expand Down
2 changes: 1 addition & 1 deletion src/cmake/add_oiio_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# [ SRC source1 ... ]
# [ INCLUDE_DIRS include_dir1 ... ]
# [ LINK_LIBRARIES external_lib1 ... ]
# [ DEFINITIONS -DFOO=bar ... ])
# [ DEFINITIONS FOO=bar ... ])
#
# The plugin name can be specified with NAME, otherwise is inferred from the
# subdirectory name. The source files of the binary can be specified with
Expand Down
6 changes: 3 additions & 3 deletions src/cmake/checked_find_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ endfunction ()
# turned off explicitly from one of these sources.
# * Print a message if the package is enabled but not found. This is based
# on ${Pkgname}_FOUND or $PKGNAME_FOUND.
# * Optional DEFINITIONS <string>... are passed to
# proj_add_compile_definitions if the package is found.
# * Optional DEFINITIONS <string>... are passed to add_compile_definitions
# if the package is found.
# * Optional SETVARIABLES <id>... is a list of CMake variables to set to
# TRUE if the package is found (they will not be set or changed if the
# package is not found).
Expand Down Expand Up @@ -153,7 +153,7 @@ macro (checked_find_package pkgname)
endif ()
endforeach ()
message (STATUS "${ColorGreen}Found ${pkgname} ${${pkgname}_VERSION} ${_config_status}${ColorReset}")
proj_add_compile_definitions (${_pkg_DEFINITIONS})
add_compile_definitions (${_pkg_DEFINITIONS})
foreach (_v IN LISTS _pkg_SETVARIABLES)
set (${_v} TRUE)
endforeach ()
Expand Down
120 changes: 49 additions & 71 deletions src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ message (STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message (VERBOSE "CMAKE_CXX_COMPILE_FEATURES = ${CMAKE_CXX_COMPILE_FEATURES}")


###########################################################################
# The proj_add_compile_definitions, proj_add_compile_options, and
# proj_add_link_options are like the global add_compile_definitions (etc), but
# they merely add to ${PROJECT_NAME}_blah lists, which are expected to be
# added to library and executable targets in our project. The point is that
# we really shouldn't be polluting the global definitions, in case our
# cmake files are included in an "outer" project.
#
macro (proj_add_compile_definitions)
list (APPEND ${PROJECT_NAME}_compile_definitions ${ARGN})
endmacro ()

macro (proj_add_compile_options)
list (APPEND ${PROJECT_NAME}_compile_options ${ARGN})
endmacro ()

macro (proj_add_link_options)
list (APPEND ${PROJECT_NAME}_link_options ${ARGN})
endmacro ()



###########################################################################
# C++ language standard
#
Expand Down Expand Up @@ -114,12 +92,12 @@ else ()
endif()
option (EXTRA_WARNINGS "Enable lots of extra pedantic warnings" OFF)
if (NOT MSVC)
proj_add_compile_options ("-Wall")
add_compile_options ("-Wall")
if (EXTRA_WARNINGS)
proj_add_compile_options ("-Wextra")
add_compile_options ("-Wextra")
endif ()
if (STOP_ON_WARNING)
proj_add_compile_options ("-Werror")
add_compile_options ("-Werror")
endif ()
endif ()

Expand Down Expand Up @@ -157,88 +135,88 @@ endif ()
#
if (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_APPLECLANG)
# Clang-specific options
proj_add_compile_options ("-Wno-unused-function")
proj_add_compile_options ("-Wno-overloaded-virtual")
proj_add_compile_options ("-Wno-unneeded-internal-declaration")
proj_add_compile_options ("-Wno-unused-private-field")
proj_add_compile_options ("-Wno-tautological-compare")
add_compile_options ("-Wno-unused-function")
add_compile_options ("-Wno-overloaded-virtual")
add_compile_options ("-Wno-unneeded-internal-declaration")
add_compile_options ("-Wno-unused-private-field")
add_compile_options ("-Wno-tautological-compare")
# disable warning about unused command line arguments
proj_add_compile_options ("-Qunused-arguments")
add_compile_options ("-Qunused-arguments")
# Don't warn if we ask it not to warn about warnings it doesn't know
proj_add_compile_options ("-Wunknown-warning-option")
add_compile_options ("-Wunknown-warning-option")
if (CLANG_VERSION_STRING VERSION_GREATER_EQUAL 3.6 OR
APPLECLANG_VERSION_STRING VERSION_GREATER 6.1)
proj_add_compile_options ("-Wno-unused-local-typedefs")
add_compile_options ("-Wno-unused-local-typedefs")
endif ()
if (CLANG_VERSION_STRING VERSION_GREATER_EQUAL 3.9)
# Don't warn about using unknown preprocessor symbols in `#if`
proj_add_compile_options ("-Wno-expansion-to-defined")
add_compile_options ("-Wno-expansion-to-defined")
endif ()
if (CMAKE_GENERATOR MATCHES "Xcode")
proj_add_compile_options ("-Wno-shorten-64-to-32")
add_compile_options ("-Wno-shorten-64-to-32")
endif ()
endif ()

if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_APPLECLANG))
# gcc specific options
proj_add_compile_options ("-Wno-unused-local-typedefs")
proj_add_compile_options ("-Wno-unused-result")
add_compile_options ("-Wno-unused-local-typedefs")
add_compile_options ("-Wno-unused-result")
if (NOT ${GCC_VERSION} VERSION_LESS 7.0)
proj_add_compile_options ("-Wno-aligned-new")
proj_add_compile_options ("-Wno-noexcept-type")
add_compile_options ("-Wno-aligned-new")
add_compile_options ("-Wno-noexcept-type")
endif ()
endif ()

if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
# Options common to gcc and clang

# Ensure this macro is set for stdint.h
proj_add_compile_definitions ("-D__STDC_LIMIT_MACROS")
proj_add_compile_definitions ("-D__STDC_CONSTANT_MACROS")
add_compile_definitions (__STDC_LIMIT_MACROS)
add_compile_definitions (__STDC_CONSTANT_MACROS)
endif ()

if (INTELCLANG_VERSION_STRING VERSION_GREATER_EQUAL 2022.1.0)
# New versions of icx warn about changing certain floating point options
proj_add_compile_options ("-Wno-overriding-t-option")
add_compile_options ("-Wno-overriding-t-option")
endif ()

if (MSVC)
# Microsoft specific options
proj_add_compile_options (/W1)
proj_add_compile_options (/MP)
proj_add_compile_definitions (-D_CRT_SECURE_NO_DEPRECATE)
proj_add_compile_definitions (-D_CRT_SECURE_NO_WARNINGS)
proj_add_compile_definitions (-D_CRT_NONSTDC_NO_WARNINGS)
proj_add_compile_definitions (-D_SCL_SECURE_NO_WARNINGS)
proj_add_compile_definitions (-DJAS_WIN_MSVC_BUILD)
add_compile_options (/W1)
add_compile_options (/MP)
add_compile_definitions (_CRT_SECURE_NO_DEPRECATE)
add_compile_definitions (_CRT_SECURE_NO_WARNINGS)
add_compile_definitions (_CRT_NONSTDC_NO_WARNINGS)
add_compile_definitions (_SCL_SECURE_NO_WARNINGS)
add_compile_definitions (JAS_WIN_MSVC_BUILD)
endif (MSVC)

if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"
AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
# For FreeBSD, minimum arch of i586 is needed for atomic cpu instructions
proj_add_compile_options (-march=i586)
add_compile_options (-march=i586)
endif ()

# Fast-math mode may go faster, but it breaks IEEE and also makes inconsistent
# results on different compilers/platforms, so we don't use it by default.
option (ENABLE_FAST_MATH "Use fast math (may break IEEE fp rules)" OFF)
if (ENABLE_FAST_MATH)
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
proj_add_compile_options ("-ffast-math")
add_compile_options ("-ffast-math")
elseif (MSVC)
proj_add_compile_options ("/fp:fast")
add_compile_options ("/fp:fast")
endif ()
else ()
if (CMAKE_COMPILER_IS_INTELCLANG)
# Intel icx is fast-math by default, so if we don't want that, we need
# to explicitly disable it.
proj_add_compile_options ("-fno-fast-math")
add_compile_options ("-fno-fast-math")
endif ()
endif ()

if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
# this allows native instructions to be used for sqrtf instead of a function call
proj_add_compile_options ("-fno-math-errno")
add_compile_options ("-fno-math-errno")
endif ()


Expand Down Expand Up @@ -307,7 +285,7 @@ endif ()
set (GLIBCXX_USE_CXX11_ABI "" CACHE STRING "For gcc, use the new C++11 library ABI (0|1)")
if (CMAKE_COMPILER_IS_GNUCC AND ${GCC_VERSION} VERSION_GREATER_EQUAL 5.0)
if (NOT ${GLIBCXX_USE_CXX11_ABI} STREQUAL "")
proj_add_compile_definitions ("-D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
add_compile_definitions (_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
endif ()
endif ()

Expand Down Expand Up @@ -358,7 +336,7 @@ if (NOT USE_SIMD STREQUAL "")
# off by default except when we explicitly use madd. At some
# future time, we should look at this again carefully and
# see if we want to use it more widely by ffp-contract=fast.
proj_add_compile_options ("-ffp-contract=off")
add_compile_options ("-ffp-contract=off")
endif ()
endforeach()

Expand All @@ -376,7 +354,7 @@ if (NOT USE_SIMD STREQUAL "")
endif ()
unset(_highest_msvc_arch)
endif ()
proj_add_compile_options (${SIMD_COMPILE_FLAGS})
add_compile_options (${SIMD_COMPILE_FLAGS})
endif ()


Expand Down Expand Up @@ -436,10 +414,10 @@ endif ()
if (USE_STD_FILESYSTEM)
# Note: std::filesystem seems unreliable for gcc until 9
message (STATUS "Compiler supports std::filesystem")
proj_add_compile_definitions (-DUSE_STD_FILESYSTEM)
add_compile_definitions (USE_STD_FILESYSTEM)
else ()
message (STATUS "Using Boost::filesystem")
proj_add_compile_definitions (-DUSE_BOOST_FILESYSTEM)
add_compile_definitions (USE_BOOST_FILESYSTEM)
endif ()
cmake_pop_check_state ()

Expand All @@ -450,9 +428,9 @@ cmake_pop_check_state ()
option (CODECOV "Build code coverage tests" OFF)
if (CODECOV AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
message (STATUS "Compiling for code coverage analysis")
proj_add_compile_options (-ftest-coverage -fprofile-arcs)
proj_add_link_options (-ftest-coverage -fprofile-arcs)
proj_add_compile_definitions ("-D${PROJ_NAME}_CODE_COVERAGE=1")
add_compile_options (-ftest-coverage -fprofile-arcs)
add_link_options (-ftest-coverage -fprofile-arcs)
add_compile_definitions (${PROJ_NAME}_CODE_COVERAGE=1)
endif ()


Expand All @@ -465,15 +443,15 @@ if (SANITIZE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
string (REPLACE "," ";" SANITIZE_FEATURE_LIST ${SANITIZE})
foreach (feature ${SANITIZE_FEATURE_LIST})
message (STATUS " sanitize feature: ${feature}")
proj_add_compile_options (-fsanitize=${feature})
proj_add_link_options (-fsanitize=${feature})
add_compile_options (-fsanitize=${feature})
add_link_options (-fsanitize=${feature})
endforeach()
proj_add_compile_options (-g -fno-omit-frame-pointer)
add_compile_options (-g -fno-omit-frame-pointer)
if (CMAKE_COMPILER_IS_GNUCC)
# turn on glibcxx extra annotations to find vector writes past end
proj_add_compile_definitions ("-D_GLIBCXX_SANITIZE_VECTOR=1")
add_compile_definitions (_GLIBCXX_SANITIZE_VECTOR=1)
endif ()
proj_add_compile_definitions ("-D${PROJECT_NAME}_SANITIZE=1")
add_compile_definitions (${PROJECT_NAME}_SANITIZE=1)
endif ()


Expand All @@ -496,7 +474,7 @@ endif ()
set (FORTIFY_SOURCE "0" CACHE STRING "Turn on Fortification level (0, 1, 2, 3)")
if (FORTIFY_SOURCE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
message (STATUS "Compiling with _FORTIFY_SOURCE=${FORTIFY_SOURCE}")
proj_add_compile_options (-D_FORTIFY_SOURCE=${FORTIFY_SOURCE})
add_compile_options (-D_FORTIFY_SOURCE=${FORTIFY_SOURCE})
endif ()


Expand Down Expand Up @@ -595,7 +573,7 @@ endif ()
set (EXTRA_CPP_ARGS "" CACHE STRING "Extra C++ command line definitions")
if (EXTRA_CPP_ARGS)
message (STATUS "Extra C++ args: ${EXTRA_CPP_ARGS}")
proj_add_compile_options (${EXTRA_CPP_ARGS})
add_compile_options (${EXTRA_CPP_ARGS})
endif()
set (EXTRA_DSO_LINK_ARGS "" CACHE STRING "Extra command line definitions when building DSOs")

Expand Down Expand Up @@ -623,7 +601,7 @@ message(VERBOSE "Setting SOVERSION to: ${SOVERSION}")
#
option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)
if (NOT BUILD_SHARED_LIBS)
proj_add_compile_definitions (-D${PROJ_NAME}_STATIC_DEFINE=1)
add_compile_definitions (${PROJ_NAME}_STATIC_DEFINE=1)
endif ()


Expand All @@ -648,7 +626,7 @@ endif ()
# We expect our own CI runs to define env variable ${PROJECT_NAME}_CI
#
if (DEFINED ENV{${PROJECT_NAME}_CI})
proj_add_compile_definitions (-D${PROJ_NAME}_CI=1 -DBUILD_CI=1)
add_compile_definitions (${PROJ_NAME}_CI=1 BUILD_CI=1)
if (APPLE)
# Keep Mono framework from being incorrectly searched for include
# files on GitHub Actions CI.
Expand Down
Loading

0 comments on commit 82f072a

Please sign in to comment.