Skip to content

Commit 64000b4

Browse files
authored
build: CMake: replace deprecated add_definitions with preferred add_compile_definitions (#1821)
Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 3a42777 commit 64000b4

File tree

10 files changed

+36
-36
lines changed

10 files changed

+36
-36
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,28 @@ option (OSL_USTRINGREP_IS_HASH "Always use ustringhash for strings" OFF)
118118

119119
set (OSL_NO_DEFAULT_TEXTURESYSTEM OFF CACHE BOOL "Do not use create a raw OIIO::TextureSystem")
120120
if (OSL_NO_DEFAULT_TEXTURESYSTEM)
121-
add_definitions ("-DOSL_NO_DEFAULT_TEXTURESYSTEM=1")
121+
add_compile_definitions (OSL_NO_DEFAULT_TEXTURESYSTEM=1)
122122
endif ()
123123

124124
option (USE_FAST_MATH "Use fast math approximations (if no, then use system math library)" ON)
125125
if (USE_FAST_MATH)
126-
add_definitions ("-DOSL_FAST_MATH=1")
126+
add_compile_definitions (OSL_FAST_MATH=1)
127127
else ()
128-
add_definitions ("-DOSL_FAST_MATH=0")
128+
add_compile_definitions (OSL_FAST_MATH=0)
129129
endif ()
130130

131131
option (OIIO_FMATH_SIMD_FRIENDLY "Make sure OIIO fmath functions are SIMD-friendly" OFF)
132132
if (OIIO_FMATH_SIMD_FRIENDLY)
133-
add_definitions (-DOIIO_FMATH_SIMD_FRIENDLY=1)
133+
add_compile_definitions (OIIO_FMATH_SIMD_FRIENDLY=1)
134134
endif ()
135135

136136
# Define OSL_INTERNAL symbol only when building OSL itself, will not be
137137
# defined for downstream projects using OSL.
138-
add_definitions (-DOSL_INTERNAL=1)
138+
add_compile_definitions (OSL_INTERNAL=1)
139139

140140
# To make sure we aren't relying on deprecated OIIO features, we define
141141
# OIIO_DISABLE_DEPRECATED before including any OIIO headers.
142-
add_definitions (-DOIIO_DISABLE_DEPRECATED=900000)
142+
add_compile_definitions (OIIO_DISABLE_DEPRECATED=900000)
143143

144144
# Set the default namespace. For symbol hiding reasons, it's important that
145145
# the project name is a subset of the namespace name.

doc/build_install/windows/build_osl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def InstallPtex_Windows(context, force, buildArgs):
896896
)
897897
PatchFile(
898898
"src\\tests\\CMakeLists.txt",
899-
[("add_definitions(-DPTEX_STATIC)", "# add_definitions(-DPTEX_STATIC)")],
899+
[("add_compile_definitions(PTEX_STATIC)", "# add_compile_definitions(PTEX_STATIC)")],
900900
)
901901

902902
# Patch Ptex::String to export symbol for operator<<

src/cmake/checked_find_package.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ endfunction ()
3737
# turned off explicitly from one of these sources.
3838
# * Print a message if the package is enabled but not found. This is based
3939
# on ${Pkgname}_FOUND or $PKGNAME_FOUND.
40-
# * Optional DEFINITIONS <string>... are passed to add_definitions if the
40+
# * Optional DEFINITIONS <string>... are passed to add_compile_definitions if the
4141
# package is found.
4242
# * Optional SETVARIABLES <id>... is a list of CMake variables to set to
4343
# TRUE if the package is found (they will not be set or changed if the
@@ -155,7 +155,7 @@ macro (checked_find_package pkgname)
155155
endif ()
156156
endforeach ()
157157
message (STATUS "${ColorGreen}Found ${pkgname} ${${pkgname}_VERSION} ${_config_status}${ColorReset}")
158-
add_definitions (${_pkg_DEFINITIONS})
158+
add_compile_definitions (${_pkg_DEFINITIONS})
159159
foreach (_v IN LISTS _pkg_SETVARIABLES)
160160
set (${_v} TRUE)
161161
endforeach ()

src/cmake/compiler.cmake

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
183183
# Options common to gcc and clang
184184

185185
# Ensure this macro is set for stdint.h
186-
add_definitions ("-D__STDC_LIMIT_MACROS")
187-
add_definitions ("-D__STDC_CONSTANT_MACROS")
186+
add_compile_definitions (__STDC_LIMIT_MACROS)
187+
add_compile_definitions (__STDC_CONSTANT_MACROS)
188188
# this allows native instructions to be used for sqrtf instead of a function call
189189
add_compile_options ("-fno-math-errno")
190190
endif ()
@@ -197,11 +197,11 @@ endif ()
197197
if (MSVC)
198198
# Microsoft specific options
199199
string (REGEX REPLACE "/W[1-4]" "/W1" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
200-
add_definitions (-D_CRT_SECURE_NO_DEPRECATE)
201-
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
202-
add_definitions (-D_CRT_NONSTDC_NO_WARNINGS)
203-
add_definitions (-D_SCL_SECURE_NO_WARNINGS)
204-
add_definitions (-DJAS_WIN_MSVC_BUILD)
200+
add_compile_definitions (_CRT_SECURE_NO_DEPRECATE)
201+
add_compile_definitions (_CRT_SECURE_NO_WARNINGS)
202+
add_compile_definitions (_CRT_NONSTDC_NO_WARNINGS)
203+
add_compile_definitions (_SCL_SECURE_NO_WARNINGS)
204+
add_compile_definitions (JAS_WIN_MSVC_BUILD)
205205
endif (MSVC)
206206

207207
if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"
@@ -284,7 +284,7 @@ endif ()
284284
set (GLIBCXX_USE_CXX11_ABI "" CACHE STRING "For gcc, use the new C++11 library ABI (0|1)")
285285
if (CMAKE_COMPILER_IS_GNUCC AND ${GCC_VERSION} VERSION_GREATER_EQUAL 5.0)
286286
if (NOT ${GLIBCXX_USE_CXX11_ABI} STREQUAL "")
287-
add_definitions ("-D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
287+
add_compile_definitions (_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
288288
endif ()
289289
endif ()
290290

@@ -368,7 +368,7 @@ option (CODECOV "Build code coverage tests" OFF)
368368
if (CODECOV AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
369369
message (STATUS "Compiling for code coverage analysis")
370370
add_compile_options (-ftest-coverage -fprofile-arcs)
371-
add_definitions ("-D${PROJ_NAME}_CODE_COVERAGE=1")
371+
add_compile_definitions (${PROJ_NAME}_CODE_COVERAGE=1)
372372
link_libraries(gcov)
373373
endif ()
374374

@@ -388,9 +388,9 @@ if (SANITIZE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
388388
add_compile_options (-g -fno-omit-frame-pointer)
389389
if (CMAKE_COMPILER_IS_GNUCC)
390390
# turn on glibcxx extra annotations to find vector writes past end
391-
add_definitions ("-D_GLIBCXX_SANITIZE_VECTOR=1")
391+
add_compile_definitions (_GLIBCXX_SANITIZE_VECTOR=1)
392392
endif ()
393-
add_definitions ("-D${PROJECT_NAME}_SANITIZE=1")
393+
add_compile_definitions (${PROJECT_NAME}_SANITIZE=1)
394394
endif ()
395395

396396

@@ -524,7 +524,7 @@ message(VERBOSE "Setting SOVERSION to: ${SOVERSION}")
524524
#
525525
option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)
526526
if (NOT BUILD_SHARED_LIBS)
527-
add_definitions (-D${PROJECT_NAME}_STATIC_DEFINE=1)
527+
add_compile_definitions (${PROJECT_NAME}_STATIC_DEFINE=1)
528528
endif ()
529529

530530

@@ -549,7 +549,7 @@ endif ()
549549
# We expect our own CI runs to define env variable ${PROJECT_NAME}_CI
550550
#
551551
if (DEFINED ENV{${PROJECT_NAME}_CI})
552-
add_definitions (-D${PROJ_NAME}_CI=1 -DBUILD_CI=1)
552+
add_compile_definitions (${PROJ_NAME}_CI=1 BUILD_CI=1)
553553
if (APPLE)
554554
# Keep Mono framework from being incorrectly searched for include
555555
# files on GitHub Actions CI.

src/cmake/cuda_macros.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set (CUDA_OPT_FLAG_CLANG "-O3" CACHE STRING "The optimization level to use when
1111
# host behavior, etc.
1212
set (CUDA_NO_FTZ OFF CACHE BOOL "Do not enable force-to-zero when compiling for CUDA")
1313
if (CUDA_NO_FTZ)
14-
add_definitions ("-DOSL_CUDA_NO_FTZ=1")
14+
add_compile_definitions (DOSL_CUDA_NO_FTZ=1)
1515
endif ()
1616

1717
# Compile a CUDA file to PTX using NVCC

src/cmake/externalpackages.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ checked_find_package (OpenEXR REQUIRED
5050
# install version of 2.x.
5151
include_directories(BEFORE ${IMATH_INCLUDES})
5252
if (MSVC AND NOT LINKSTATIC)
53-
add_definitions (-DOPENEXR_DLL) # Is this needed for new versions?
53+
add_compile_definitions (OPENEXR_DLL) # Is this needed for new versions?
5454
endif ()
5555

5656
if (OPENEXR_VERSION VERSION_GREATER_EQUAL 2.5.99)
@@ -63,7 +63,7 @@ endif ()
6363
# OpenImageIO
6464
checked_find_package (OpenImageIO REQUIRED
6565
VERSION_MIN 2.4
66-
DEFINITIONS -DOIIO_HIDE_FORMAT=1)
66+
DEFINITIONS OIIO_HIDE_FORMAT=1)
6767

6868
checked_find_package (pugixml REQUIRED
6969
VERSION_MIN 1.8)
@@ -80,10 +80,10 @@ link_directories ("${LLVM_LIB_DIR}")
8080
# Extract and concatenate major & minor, remove wayward patches,
8181
# dots, and "svn" or other suffixes.
8282
string (REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1\\2" OSL_LLVM_VERSION ${LLVM_VERSION})
83-
add_definitions (-DOSL_LLVM_VERSION=${OSL_LLVM_VERSION})
84-
add_definitions (-DOSL_LLVM_FULL_VERSION="${LLVM_VERSION}")
83+
add_compile_definitions (OSL_LLVM_VERSION=${OSL_LLVM_VERSION})
84+
add_compile_definitions (OSL_LLVM_FULL_VERSION="${LLVM_VERSION}")
8585
if (LLVM_NAMESPACE)
86-
add_definitions ("-DLLVM_NAMESPACE=${LLVM_NAMESPACE}")
86+
add_compile_definitions (LLVM_NAMESPACE=${LLVM_NAMESPACE})
8787
endif ()
8888
if (APPLE AND LLVM_VERSION VERSION_EQUAL 10.0.1 AND EXISTS "/usr/local/Cellar/llvm")
8989
message (WARNING
@@ -118,15 +118,15 @@ endif ()
118118
# Use opaque pointers starting with LLVM 16
119119
if (${LLVM_VERSION} VERSION_GREATER_EQUAL 16.0)
120120
set(LLVM_OPAQUE_POINTERS ON)
121-
add_definitions (-DOSL_LLVM_OPAQUE_POINTERS)
121+
add_compile_definitions (OSL_LLVM_OPAQUE_POINTERS)
122122
else()
123123
set(LLVM_OPAQUE_POINTERS OFF)
124124
endif()
125125

126126
# Enable new pass manager for LLVM 16+
127127
if (${LLVM_VERSION} VERSION_GREATER_EQUAL 16.0)
128128
set(LLVM_NEW_PASS_MANAGER ON)
129-
add_definitions (-DOSL_LLVM_NEW_PASS_MANAGER)
129+
add_compile_definitions (OSL_LLVM_NEW_PASS_MANAGER)
130130
else()
131131
set(LLVM_NEW_PASS_MANAGER OFF)
132132
endif()
@@ -215,7 +215,7 @@ if (OSL_USE_OPTIX)
215215
function (osl_optix_target TARGET)
216216
target_include_directories (${TARGET} BEFORE PRIVATE ${CUDA_INCLUDES} ${OPTIX_INCLUDES})
217217
## XXX: Should -DPTX_PATH point to (or include) CMAKE_CURRENT_BINARY_DIR so tests can run before installation ?
218-
target_compile_definitions (${TARGET} PRIVATE "-DPTX_PATH=\"${OSL_PTX_INSTALL_DIR}\"")
218+
target_compile_definitions (${TARGET} PRIVATE PTX_PATH="${OSL_PTX_INSTALL_DIR}")
219219
target_link_libraries (${TARGET} PRIVATE ${CUDA_LIBRARIES} ${CUDA_EXTRA_LIBS} ${OPTIX_LIBRARIES} ${OPTIX_EXTRA_LIBS})
220220
endfunction()
221221
else ()

src/cmake/flexbison.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if ( FLEX_EXECUTABLE AND BISON_EXECUTABLE )
4141
macro ( FLEX_BISON flexsrc bisonsrc prefix srclist compiler_headers )
4242
# mangle osoparse & oslparse symbols to avoid multiple library conflicts
4343
# XXX: This may be excessive now that OSL::pvt::ExtraArg is mangled into the function signature
44-
add_definitions(-D${prefix}parse=${PROJ_NAMESPACE_V}_${prefix}parse)
44+
add_compile_definitions(${prefix}parse=${PROJ_NAMESPACE_V}_${prefix}parse)
4545

4646
message (VERBOSE "FLEX_BISON flex=${flexsrc} bison=${bisonsrc} prefix=${prefix}")
4747
get_filename_component ( bisonsrc_we ${bisonsrc} NAME_WE )

src/liboslexec/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ if (USE_LLVM_BITCODE)
211211
EMBED_LLVM_BITCODE_IN_CPP ( "${rs_dependent_ops_srcs}" "_host_rs" "osl_llvm_compiled_rs_dependent_ops" lib_src "" "${include_dirs}")
212212

213213
if (CUDA_FOUND)
214-
add_definitions (-DOSL_LLVM_CUDA_BITCODE)
214+
add_compile_definitions (OSL_LLVM_CUDA_BITCODE)
215215

216216
# The shadeops are compiled to both LLVM bitcode and PTX, and embedded
217217
# in liboslexec in binary format. The bitcode is used to seed the LLVM
@@ -255,7 +255,7 @@ else ()
255255
# With MSVC/Mingw, we don't compile llvm_ops.cpp to LLVM bitcode, due
256256
# to clang being unable to compile MSVC C++ header files at this time.
257257
# Instead it is part of the regular build process.
258-
add_definitions (-DOSL_LLVM_NO_BITCODE)
258+
add_compile_definitions (OSL_LLVM_NO_BITCODE)
259259
set (lib_src ${lib_src} llvm_ops.cpp)
260260
endif ()
261261

src/testrender/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (OSL_USE_OPTIX)
3333
endforeach ()
3434

3535
# Compile the renderer-supplied shadeops (rend_lib) to LLVM bitcode and PTX
36-
add_definitions (-DOSL_LLVM_CUDA_BITCODE)
36+
add_compile_definitions (OSL_LLVM_CUDA_BITCODE)
3737
CUDA_SHADEOPS_COMPILE ( "rend_lib_testrender"
3838
rend_lib_bc
3939
rend_lib_ptx

src/testshade/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (OSL_USE_OPTIX)
3838
endforeach ()
3939

4040
# Compile the renderer-supplied shadeops (rend_lib) to LLVM bitcode and PTX
41-
add_definitions (-DOSL_LLVM_CUDA_BITCODE)
41+
add_compile_definitions (OSL_LLVM_CUDA_BITCODE)
4242
CUDA_SHADEOPS_COMPILE ( "rend_lib_testshade"
4343
rend_lib_bc
4444
rend_lib_ptx

0 commit comments

Comments
 (0)