Skip to content

Commit 82f072a

Browse files
committed
build: Partially revert AcademySoftwareFoundation#4193, the avoidance 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>
1 parent 3a58e63 commit 82f072a

File tree

23 files changed

+91
-142
lines changed

23 files changed

+91
-142
lines changed

CMakeLists.txt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,18 @@ message(STATUS "CMAKE_UNITY_BUILD_MODE = ${CMAKE_UNITY_BUILD_MODE}")
119119
message(STATUS "CMAKE_UNITY_BUILD_BATCH_SIZE = ${CMAKE_UNITY_BUILD_BATCH_SIZE}")
120120

121121
option (OIIO_THREAD_ALLOW_DCLP "OIIO threads may use DCLP for speed" ON)
122+
if (NOT OIIO_THREAD_ALLOW_DCLP)
123+
add_compile_definitions (OIIO_THREAD_ALLOW_DCLP=0)
124+
endif ()
122125

123126
set (TEX_BATCH_SIZE "" CACHE STRING "Force TextureSystem SIMD batch size (e.g. 16)")
127+
if (TEX_BATCH_SIZE)
128+
add_compile_definitions (OIIO_TEXTURE_SIMD_BATCH_WIDTH=${TEX_BATCH_SIZE})
129+
endif ()
124130
option (OIIO_TEX_IMPLEMENT_VARYINGREF "Implement the deprecated batch texture functions taking VaryingRef params" ON)
131+
if (NOT OIIO_TEX_IMPLEMENT_VARYINGREF)
132+
add_compile_definitions (OIIO_TEX_NO_IMPLEMENT_VARYINGREF=1)
133+
endif ()
125134

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

152+
# Define OIIO_INTERNAL symbol only when building OIIO itself, will not be
153+
# defined for downstream projects using OIIO.
154+
add_compile_definitions (OIIO_INTERNAL=1)
155+
143156
include (GNUInstallDirs)
144157

145158
# Utilities
@@ -177,23 +190,6 @@ include_directories (
177190
"${CMAKE_BINARY_DIR}/include/OpenImageIO"
178191
)
179192

180-
181-
# Define OIIO_INTERNAL symbol only when building OIIO itself, will not be
182-
# defined for downstream projects using OIIO.
183-
proj_add_compile_definitions (OIIO_INTERNAL=1)
184-
185-
if (NOT OIIO_THREAD_ALLOW_DCLP)
186-
proj_add_compile_definitions (OIIO_THREAD_ALLOW_DCLP=0)
187-
endif ()
188-
if (TEX_BATCH_SIZE)
189-
proj_add_compile_definitions (OIIO_TEXTURE_SIMD_BATCH_WIDTH=${TEX_BATCH_SIZE})
190-
endif ()
191-
if (NOT OIIO_TEX_IMPLEMENT_VARYINGREF)
192-
proj_add_compile_definitions (OIIO_TEX_NO_IMPLEMENT_VARYINGREF=1)
193-
endif ()
194-
195-
196-
197193
# Tell CMake to process the sub-directories
198194
add_subdirectory (src/libutil)
199195

src/cmake/add_oiio_plugin.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# [ SRC source1 ... ]
1313
# [ INCLUDE_DIRS include_dir1 ... ]
1414
# [ LINK_LIBRARIES external_lib1 ... ]
15-
# [ DEFINITIONS -DFOO=bar ... ])
15+
# [ DEFINITIONS FOO=bar ... ])
1616
#
1717
# The plugin name can be specified with NAME, otherwise is inferred from the
1818
# subdirectory name. The source files of the binary can be specified with

src/cmake/checked_find_package.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ endfunction ()
3939
# turned off explicitly from one of these sources.
4040
# * Print a message if the package is enabled but not found. This is based
4141
# on ${Pkgname}_FOUND or $PKGNAME_FOUND.
42-
# * Optional DEFINITIONS <string>... are passed to
43-
# proj_add_compile_definitions if the package is found.
42+
# * Optional DEFINITIONS <string>... are passed to add_compile_definitions
43+
# if the package is found.
4444
# * Optional SETVARIABLES <id>... is a list of CMake variables to set to
4545
# TRUE if the package is found (they will not be set or changed if the
4646
# package is not found).
@@ -153,7 +153,7 @@ macro (checked_find_package pkgname)
153153
endif ()
154154
endforeach ()
155155
message (STATUS "${ColorGreen}Found ${pkgname} ${${pkgname}_VERSION} ${_config_status}${ColorReset}")
156-
proj_add_compile_definitions (${_pkg_DEFINITIONS})
156+
add_compile_definitions (${_pkg_DEFINITIONS})
157157
foreach (_v IN LISTS _pkg_SETVARIABLES)
158158
set (${_v} TRUE)
159159
endforeach ()

src/cmake/compiler.cmake

Lines changed: 49 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,6 @@ message (STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
2323
message (VERBOSE "CMAKE_CXX_COMPILE_FEATURES = ${CMAKE_CXX_COMPILE_FEATURES}")
2424

2525

26-
###########################################################################
27-
# The proj_add_compile_definitions, proj_add_compile_options, and
28-
# proj_add_link_options are like the global add_compile_definitions (etc), but
29-
# they merely add to ${PROJECT_NAME}_blah lists, which are expected to be
30-
# added to library and executable targets in our project. The point is that
31-
# we really shouldn't be polluting the global definitions, in case our
32-
# cmake files are included in an "outer" project.
33-
#
34-
macro (proj_add_compile_definitions)
35-
list (APPEND ${PROJECT_NAME}_compile_definitions ${ARGN})
36-
endmacro ()
37-
38-
macro (proj_add_compile_options)
39-
list (APPEND ${PROJECT_NAME}_compile_options ${ARGN})
40-
endmacro ()
41-
42-
macro (proj_add_link_options)
43-
list (APPEND ${PROJECT_NAME}_link_options ${ARGN})
44-
endmacro ()
45-
46-
47-
4826
###########################################################################
4927
# C++ language standard
5028
#
@@ -114,12 +92,12 @@ else ()
11492
endif()
11593
option (EXTRA_WARNINGS "Enable lots of extra pedantic warnings" OFF)
11694
if (NOT MSVC)
117-
proj_add_compile_options ("-Wall")
95+
add_compile_options ("-Wall")
11896
if (EXTRA_WARNINGS)
119-
proj_add_compile_options ("-Wextra")
97+
add_compile_options ("-Wextra")
12098
endif ()
12199
if (STOP_ON_WARNING)
122-
proj_add_compile_options ("-Werror")
100+
add_compile_options ("-Werror")
123101
endif ()
124102
endif ()
125103

@@ -157,88 +135,88 @@ endif ()
157135
#
158136
if (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_APPLECLANG)
159137
# Clang-specific options
160-
proj_add_compile_options ("-Wno-unused-function")
161-
proj_add_compile_options ("-Wno-overloaded-virtual")
162-
proj_add_compile_options ("-Wno-unneeded-internal-declaration")
163-
proj_add_compile_options ("-Wno-unused-private-field")
164-
proj_add_compile_options ("-Wno-tautological-compare")
138+
add_compile_options ("-Wno-unused-function")
139+
add_compile_options ("-Wno-overloaded-virtual")
140+
add_compile_options ("-Wno-unneeded-internal-declaration")
141+
add_compile_options ("-Wno-unused-private-field")
142+
add_compile_options ("-Wno-tautological-compare")
165143
# disable warning about unused command line arguments
166-
proj_add_compile_options ("-Qunused-arguments")
144+
add_compile_options ("-Qunused-arguments")
167145
# Don't warn if we ask it not to warn about warnings it doesn't know
168-
proj_add_compile_options ("-Wunknown-warning-option")
146+
add_compile_options ("-Wunknown-warning-option")
169147
if (CLANG_VERSION_STRING VERSION_GREATER_EQUAL 3.6 OR
170148
APPLECLANG_VERSION_STRING VERSION_GREATER 6.1)
171-
proj_add_compile_options ("-Wno-unused-local-typedefs")
149+
add_compile_options ("-Wno-unused-local-typedefs")
172150
endif ()
173151
if (CLANG_VERSION_STRING VERSION_GREATER_EQUAL 3.9)
174152
# Don't warn about using unknown preprocessor symbols in `#if`
175-
proj_add_compile_options ("-Wno-expansion-to-defined")
153+
add_compile_options ("-Wno-expansion-to-defined")
176154
endif ()
177155
if (CMAKE_GENERATOR MATCHES "Xcode")
178-
proj_add_compile_options ("-Wno-shorten-64-to-32")
156+
add_compile_options ("-Wno-shorten-64-to-32")
179157
endif ()
180158
endif ()
181159

182160
if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_APPLECLANG))
183161
# gcc specific options
184-
proj_add_compile_options ("-Wno-unused-local-typedefs")
185-
proj_add_compile_options ("-Wno-unused-result")
162+
add_compile_options ("-Wno-unused-local-typedefs")
163+
add_compile_options ("-Wno-unused-result")
186164
if (NOT ${GCC_VERSION} VERSION_LESS 7.0)
187-
proj_add_compile_options ("-Wno-aligned-new")
188-
proj_add_compile_options ("-Wno-noexcept-type")
165+
add_compile_options ("-Wno-aligned-new")
166+
add_compile_options ("-Wno-noexcept-type")
189167
endif ()
190168
endif ()
191169

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

195173
# Ensure this macro is set for stdint.h
196-
proj_add_compile_definitions ("-D__STDC_LIMIT_MACROS")
197-
proj_add_compile_definitions ("-D__STDC_CONSTANT_MACROS")
174+
add_compile_definitions (__STDC_LIMIT_MACROS)
175+
add_compile_definitions (__STDC_CONSTANT_MACROS)
198176
endif ()
199177

200178
if (INTELCLANG_VERSION_STRING VERSION_GREATER_EQUAL 2022.1.0)
201179
# New versions of icx warn about changing certain floating point options
202-
proj_add_compile_options ("-Wno-overriding-t-option")
180+
add_compile_options ("-Wno-overriding-t-option")
203181
endif ()
204182

205183
if (MSVC)
206184
# Microsoft specific options
207-
proj_add_compile_options (/W1)
208-
proj_add_compile_options (/MP)
209-
proj_add_compile_definitions (-D_CRT_SECURE_NO_DEPRECATE)
210-
proj_add_compile_definitions (-D_CRT_SECURE_NO_WARNINGS)
211-
proj_add_compile_definitions (-D_CRT_NONSTDC_NO_WARNINGS)
212-
proj_add_compile_definitions (-D_SCL_SECURE_NO_WARNINGS)
213-
proj_add_compile_definitions (-DJAS_WIN_MSVC_BUILD)
185+
add_compile_options (/W1)
186+
add_compile_options (/MP)
187+
add_compile_definitions (_CRT_SECURE_NO_DEPRECATE)
188+
add_compile_definitions (_CRT_SECURE_NO_WARNINGS)
189+
add_compile_definitions (_CRT_NONSTDC_NO_WARNINGS)
190+
add_compile_definitions (_SCL_SECURE_NO_WARNINGS)
191+
add_compile_definitions (JAS_WIN_MSVC_BUILD)
214192
endif (MSVC)
215193

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

222200
# Fast-math mode may go faster, but it breaks IEEE and also makes inconsistent
223201
# results on different compilers/platforms, so we don't use it by default.
224202
option (ENABLE_FAST_MATH "Use fast math (may break IEEE fp rules)" OFF)
225203
if (ENABLE_FAST_MATH)
226204
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
227-
proj_add_compile_options ("-ffast-math")
205+
add_compile_options ("-ffast-math")
228206
elseif (MSVC)
229-
proj_add_compile_options ("/fp:fast")
207+
add_compile_options ("/fp:fast")
230208
endif ()
231209
else ()
232210
if (CMAKE_COMPILER_IS_INTELCLANG)
233211
# Intel icx is fast-math by default, so if we don't want that, we need
234212
# to explicitly disable it.
235-
proj_add_compile_options ("-fno-fast-math")
213+
add_compile_options ("-fno-fast-math")
236214
endif ()
237215
endif ()
238216

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

244222

@@ -307,7 +285,7 @@ endif ()
307285
set (GLIBCXX_USE_CXX11_ABI "" CACHE STRING "For gcc, use the new C++11 library ABI (0|1)")
308286
if (CMAKE_COMPILER_IS_GNUCC AND ${GCC_VERSION} VERSION_GREATER_EQUAL 5.0)
309287
if (NOT ${GLIBCXX_USE_CXX11_ABI} STREQUAL "")
310-
proj_add_compile_definitions ("-D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
288+
add_compile_definitions (_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
311289
endif ()
312290
endif ()
313291

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

@@ -376,7 +354,7 @@ if (NOT USE_SIMD STREQUAL "")
376354
endif ()
377355
unset(_highest_msvc_arch)
378356
endif ()
379-
proj_add_compile_options (${SIMD_COMPILE_FLAGS})
357+
add_compile_options (${SIMD_COMPILE_FLAGS})
380358
endif ()
381359

382360

@@ -436,10 +414,10 @@ endif ()
436414
if (USE_STD_FILESYSTEM)
437415
# Note: std::filesystem seems unreliable for gcc until 9
438416
message (STATUS "Compiler supports std::filesystem")
439-
proj_add_compile_definitions (-DUSE_STD_FILESYSTEM)
417+
add_compile_definitions (USE_STD_FILESYSTEM)
440418
else ()
441419
message (STATUS "Using Boost::filesystem")
442-
proj_add_compile_definitions (-DUSE_BOOST_FILESYSTEM)
420+
add_compile_definitions (USE_BOOST_FILESYSTEM)
443421
endif ()
444422
cmake_pop_check_state ()
445423

@@ -450,9 +428,9 @@ cmake_pop_check_state ()
450428
option (CODECOV "Build code coverage tests" OFF)
451429
if (CODECOV AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
452430
message (STATUS "Compiling for code coverage analysis")
453-
proj_add_compile_options (-ftest-coverage -fprofile-arcs)
454-
proj_add_link_options (-ftest-coverage -fprofile-arcs)
455-
proj_add_compile_definitions ("-D${PROJ_NAME}_CODE_COVERAGE=1")
431+
add_compile_options (-ftest-coverage -fprofile-arcs)
432+
add_link_options (-ftest-coverage -fprofile-arcs)
433+
add_compile_definitions (${PROJ_NAME}_CODE_COVERAGE=1)
456434
endif ()
457435

458436

@@ -465,15 +443,15 @@ if (SANITIZE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
465443
string (REPLACE "," ";" SANITIZE_FEATURE_LIST ${SANITIZE})
466444
foreach (feature ${SANITIZE_FEATURE_LIST})
467445
message (STATUS " sanitize feature: ${feature}")
468-
proj_add_compile_options (-fsanitize=${feature})
469-
proj_add_link_options (-fsanitize=${feature})
446+
add_compile_options (-fsanitize=${feature})
447+
add_link_options (-fsanitize=${feature})
470448
endforeach()
471-
proj_add_compile_options (-g -fno-omit-frame-pointer)
449+
add_compile_options (-g -fno-omit-frame-pointer)
472450
if (CMAKE_COMPILER_IS_GNUCC)
473451
# turn on glibcxx extra annotations to find vector writes past end
474-
proj_add_compile_definitions ("-D_GLIBCXX_SANITIZE_VECTOR=1")
452+
add_compile_definitions (_GLIBCXX_SANITIZE_VECTOR=1)
475453
endif ()
476-
proj_add_compile_definitions ("-D${PROJECT_NAME}_SANITIZE=1")
454+
add_compile_definitions (${PROJECT_NAME}_SANITIZE=1)
477455
endif ()
478456

479457

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

502480

@@ -595,7 +573,7 @@ endif ()
595573
set (EXTRA_CPP_ARGS "" CACHE STRING "Extra C++ command line definitions")
596574
if (EXTRA_CPP_ARGS)
597575
message (STATUS "Extra C++ args: ${EXTRA_CPP_ARGS}")
598-
proj_add_compile_options (${EXTRA_CPP_ARGS})
576+
add_compile_options (${EXTRA_CPP_ARGS})
599577
endif()
600578
set (EXTRA_DSO_LINK_ARGS "" CACHE STRING "Extra command line definitions when building DSOs")
601579

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

629607

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

0 commit comments

Comments
 (0)