Skip to content

Commit e4e35df

Browse files
committed
Use namespaced CMake variables. Deprecated old values
This commit deprecates the old CMake variables in favor of variables that are namespaced with the AF_ prefix to avoid name conflicts with user code. If the old variables are used a warning is displayed and the new variable is set to the value. The old variable is unset to avoid showing the warning again.
1 parent 8bad836 commit e4e35df

18 files changed

Lines changed: 125 additions & 97 deletions

CMakeLists.txt

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,51 @@ find_package(MKL)
3636
find_package(glbinding QUIET)
3737
include(boost_package)
3838

39-
option(BUILD_CPU "Build ArrayFire with a CPU backend" ON)
40-
option(BUILD_CUDA "Build ArrayFire with a CUDA backend" ${CUDA_FOUND})
41-
option(BUILD_OPENCL "Build ArrayFire with a OpenCL backend" ${OpenCL_FOUND})
42-
option(BUILD_UNIFIED "Build Backend-Independent ArrayFire API" ON)
39+
option(AF_BUILD_CPU "Build ArrayFire with a CPU backend" ON)
40+
option(AF_BUILD_CUDA "Build ArrayFire with a CUDA backend" ${CUDA_FOUND})
41+
option(AF_BUILD_OPENCL "Build ArrayFire with a OpenCL backend" ${OpenCL_FOUND})
42+
option(AF_BUILD_UNIFIED "Build Backend-Independent ArrayFire API" ON)
43+
option(AF_BUILD_DOCS "Create ArrayFire Documentation" ${DOXYGEN_FOUND})
44+
option(AF_BUILD_EXAMPLES "Build Examples" ON)
4345

44-
option(BUILD_GRAPHICS "Build ArrayFire with Forge Graphics" $<AND:${OPENGL_FOUND},${Forge_FOUND},${glbinding_FOUND}>)
45-
option(BUILD_DOCS "Create ArrayFire Documentation" ${DOXYGEN_FOUND})
46-
option(BUILD_NONFREE "Build ArrayFire nonfree algorithms" OFF)
46+
option(AF_WITH_GRAPHICS "Build ArrayFire with Forge Graphics" $<AND:${OPENGL_FOUND},${Forge_FOUND},${glbinding_FOUND}>)
47+
option(AF_WITH_NONFREE "Build ArrayFire nonfree algorithms" OFF)
4748

48-
option(BUILD_EXAMPLES "Build Examples" ON)
49-
cmake_dependent_option(USE_RELATIVE_TEST_DIR "Use relative paths for the test data directory(For continious integration(CI) purposes only)" OFF
49+
cmake_dependent_option(AF_WITH_RELATIVE_TEST_DIR "Use relative paths for the test data directory(For continious integration(CI) purposes only)" OFF
5050
"BUILD_TESTING" OFF)
5151

52-
cmake_dependent_option(USE_SYSTEM_FORGE "Use system Forge" OFF
53-
"BUILD_GRAPHICS" OFF)
54-
cmake_dependent_option(WITH_IMAGEIO "Build ArrayFire with Image IO support" ${FreeImage_FOUND}
55-
"FreeImage_FOUND" OFF)
56-
cmake_dependent_option(BUILD_FRAMEWORK "Build an ArrayFire framework for Apple platforms.(Experimental)" OFF
57-
"APPLE" OFF)
58-
option(USE_FREEIMAGE_STATIC "Use Static FreeImage Lib" OFF)
59-
60-
set(USE_CPUID ON CACHE BOOL "Build with CPUID integration")
52+
cmake_dependent_option(AF_USE_SYSTEM_FORGE "Use system Forge" OFF
53+
"AF_WITH_GRAPHICS" OFF)
54+
cmake_dependent_option(AF_WITH_IMAGEIO "Build ArrayFire with Image IO support" ${FreeImage_FOUND}
55+
"FreeImage_FOUND" OFF)
56+
cmake_dependent_option(AF_BUILD_FRAMEWORK "Build an ArrayFire framework for Apple platforms.(Experimental)" OFF
57+
"APPLE" OFF)
58+
option(AF_WITH_STATIC_FREEIMAGE "Use Static FreeImage Lib" OFF)
59+
60+
set(AF_WITH_CPUID ON CACHE BOOL "Build with CPUID integration")
61+
62+
af_deprecate(BUILD_CPU AF_BUILD_CPU)
63+
af_deprecate(BUILD_CUDA AF_BUILD_CUDA)
64+
af_deprecate(BUILD_OPENCL AF_BUILD_OPENCL)
65+
af_deprecate(BUILD_UNIFIED AF_BUILD_UNIFIED)
66+
af_deprecate(BUILD_GRAPHICS AF_WITH_GRAPHICS)
67+
af_deprecate(BUILD_DOCS AF_BUILD_DOCS)
68+
af_deprecate(BUILD_NONFREE AF_WITH_NONFREE)
69+
af_deprecate(BUILD_EXAMPLES AF_WITH_EXAMPLES)
70+
af_deprecate(USE_RELATIVE_TEST_DIR AF_WITH_RELATIVE_TEST_DIR)
71+
af_deprecate(USE_FREEIMAGE_STATIC AF_WITH_STATIC_FREEIMAGE)
72+
af_deprecate(USE_CPUID AF_WITH_CPUID)
6173

6274
mark_as_advanced(
63-
BUILD_FRAMEWORK
64-
USE_SYSTEM_FORGE
65-
USE_CPUID)
75+
AF_BUILD_FRAMEWORK
76+
AF_USE_SYSTEM_FORGE
77+
AF_WITH_CPUID)
6678

6779
# TODO(umar): Add definitions should not be used. Instead use
6880
arrayfire_get_platform_definitions(platform_definitions)
6981
add_definitions(${platform_definitions})
7082

71-
if(BUILD_GRAPHICS)
83+
if(AF_WITH_GRAPHICS)
7284
include(build_forge)
7385
endif()
7486

@@ -77,7 +89,7 @@ configure_file(
7789
${ArrayFire_BINARY_DIR}/version.hpp
7890
)
7991

80-
if(BUILD_NONFREE)
92+
if(AF_WITH_NONFREE)
8193
message("Building with NONFREE requires the following patents")
8294
message("Method and apparatus for identifying scale invariant features\n"
8395
"in an image and use of same for locating an object in an image, David\n"
@@ -105,10 +117,10 @@ add_subdirectory(src/backend/common)
105117
add_subdirectory(src/api/c)
106118
add_subdirectory(src/api/cpp)
107119

108-
conditional_directory(BUILD_CPU src/backend/cpu)
109-
conditional_directory(BUILD_CUDA src/backend/cuda)
110-
conditional_directory(BUILD_OPENCL src/backend/opencl)
111-
conditional_directory(BUILD_UNIFIED src/api/unified)
120+
conditional_directory(AF_BUILD_CPU src/backend/cpu)
121+
conditional_directory(AF_BUILD_CUDA src/backend/cuda)
122+
conditional_directory(AF_BUILD_OPENCL src/backend/opencl)
123+
conditional_directory(AF_BUILD_UNIFIED src/api/unified)
112124

113125
if(TARGET af)
114126
list(APPEND built_backends af)
@@ -134,7 +146,7 @@ foreach(backend ${built_backends})
134146
target_compile_definitions(${backend} PRIVATE AFDLL)
135147
endforeach()
136148

137-
if(BUILD_FRAMEWORK)
149+
if(AF_BUILD_FRAMEWORK)
138150
set_target_properties(${built_backends}
139151
PROPERTIES
140152
FRAMEWORK TRUE
@@ -161,7 +173,7 @@ install(FILES
161173
COMPONENT headers
162174
)
163175

164-
if(Forge_FOUND AND NOT USE_SYSTEM_FORGE)
176+
if(Forge_FOUND AND NOT AF_USE_SYSTEM_FORGE)
165177
option(INSTALL_FORGE_DEV "Install Forge Header and Share Files with ArrayFire" OFF)
166178
install(DIRECTORY "${ArrayFire_BINARY_DIR}/third_party/forge/lib/"
167179
DESTINATION "${AF_INSTALL_LIB_DIR}"
@@ -179,10 +191,10 @@ if(Forge_FOUND AND NOT USE_SYSTEM_FORGE)
179191
endif()
180192
endif()
181193

182-
# install the examples irrespective of the BUILD_EXAMPLES value
194+
# install the examples irrespective of the AF_BUILD_EXAMPLES value
183195
# only the examples source files are installed, so the installation of these
184-
# source files does not depend on BUILD_EXAMPLES
185-
# when BUILD_EXAMPLES is OFF, the examples source is installed without
196+
# source files does not depend on AF_BUILD_EXAMPLES
197+
# when AF_BUILD_EXAMPLES is OFF, the examples source is installed without
186198
# building the example executables
187199
install(DIRECTORY examples/ #NOTE The slash at the end is important
188200
DESTINATION ${AF_INSTALL_EXAMPLE_DIR}
@@ -194,7 +206,7 @@ install(DIRECTORY assets/examples/ #NOTE The slash at the end is important
194206

195207
foreach(backend CPU CUDA OpenCL Unified)
196208
string(TOUPPER ${backend} upper_backend)
197-
if(BUILD_${upper_backend})
209+
if(AF_BUILD_${upper_backend})
198210
install(EXPORT ArrayFire${backend}Targets
199211
NAMESPACE ArrayFire::
200212
DESTINATION ${AF_INSTALL_CMAKE_DIR}
@@ -278,5 +290,5 @@ endif()
278290
conditional_directory(BUILD_TESTING test)
279291

280292
set(ASSETS_DIR "${ArrayFire_SOURCE_DIR}/assets")
281-
conditional_directory(BUILD_EXAMPLES examples)
282-
conditional_directory(BUILD_DOCS docs)
293+
conditional_directory(AF_BUILD_EXAMPLES examples)
294+
conditional_directory(AF_BUILD_DOCS docs)

CMakeModules/CPackConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ set(CPACK_PACKAGE_VERSION ${ArrayFire_VERSION})
2323
set(CPACK_PACKAGE_VERSION_MAJOR "${ArrayFire_VERSION_MAJOR}")
2424
set(CPACK_PACKAGE_VERSION_MINOR "${ArrayFire_VERSION_MINOR}")
2525
set(CPACK_PACKAGE_VERSION_PATCH "${ArrayFire_VERSION_PATCH}")
26-
if(BUILD_GRAPHICS)
26+
if(AF_WITH_GRAPHICS)
2727
set(CPACK_PACKAGE_FILE_NAME
2828
${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})
2929
else()

CMakeModules/InternalUtils.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ function(arrayfire_get_cuda_cxx_flags cuda_flags)
3636
endif()
3737
endfunction()
3838

39+
function(__af_deprecate_var var access value)
40+
if(access STREQUAL "READ_ACCESS")
41+
message(DEPRECATION "Variable ${var} is deprecated. Use AF_${var} instead.")
42+
endif()
43+
endfunction()
44+
45+
function(af_deprecate var newvar)
46+
if(DEFINED ${var})
47+
message(DEPRECATION "Variable ${var} is deprecated. Use ${newvar} instead.")
48+
get_property(doc CACHE ${newvar} PROPERTY HELPSTRING)
49+
set(${newvar} ${${var}} CACHE BOOL "${doc}" FORCE)
50+
unset(${var} CACHE)
51+
endif()
52+
variable_watch(${var} __af_deprecate_var)
53+
endfunction()
54+
3955
macro(arrayfire_set_cmake_default_variables)
4056
set(CMAKE_PREFIX_PATH "${ArrayFire_BINARY_DIR}/cmake;${CMAKE_PREFIX_PATH}")
4157
set(BUILD_SHARED_LIBS ON)

CMakeModules/osx_install/OSXInstaller.cmake

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ADD_CUSTOM_TARGET(OSX_INSTALL_SETUP_DOC
9090
COMMENT "Copying documentation files to temporary OSX Install Dir"
9191
)
9292

93-
IF(BUILD_GRAPHICS)
93+
IF(AF_WITH_GRAPHICS)
9494
MAKE_DIRECTORY("${OSX_TEMP}/Forge")
9595

9696
# Forge library versions for setting up symlinks
@@ -157,7 +157,7 @@ IF(BUILD_GRAPHICS)
157157
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
158158
COMMENT "Copying documentation files to temporary OSX Install Dir"
159159
)
160-
ENDIF(BUILD_GRAPHICS)
160+
ENDIF(AF_WITH_GRAPHICS)
161161
################################################################################
162162

163163
FUNCTION(PKG_BUILD)
@@ -190,11 +190,11 @@ ENDFUNCTION(PKG_BUILD)
190190

191191
FUNCTION(PRODUCT_BUILD)
192192
CMAKE_PARSE_ARGUMENTS(ARGS "" "" "DEPENDS" ${ARGN})
193-
IF(BUILD_GRAPHICS)
193+
IF(AF_WITH_GRAPHICS)
194194
SET(DISTRIBUTION_FILE "${OSX_INSTALL_SOURCE}/distribution.dist")
195-
ELSE(BUILD_GRAPHICS)
195+
ELSE(AF_WITH_GRAPHICS)
196196
SET(DISTRIBUTION_FILE "${OSX_INSTALL_SOURCE}/distribution-no-gl.dist")
197-
ENDIF(BUILD_GRAPHICS)
197+
ENDIF(AF_WITH_GRAPHICS)
198198

199199
SET(DISTRIBUTION_FILE_OUT "${CMAKE_CURRENT_BINARY_DIR}/distribution.dist.out")
200200

@@ -209,11 +209,11 @@ FUNCTION(PRODUCT_BUILD)
209209
CONFIGURE_FILE(${WELCOME_FILE} ${WELCOME_FILE_OUT})
210210
CONFIGURE_FILE(${README_FILE} ${README_FILE_OUT})
211211

212-
IF(BUILD_GRAPHICS)
212+
IF(AF_WITH_GRAPHICS)
213213
SET(PACKAGE_NAME "arrayfire-${AF_VERSION}.pkg")
214-
ELSE(BUILD_GRAPHICS)
214+
ELSE(AF_WITH_GRAPHICS)
215215
SET(PACKAGE_NAME "arrayfire-no-gl-${AF_VERSION}.pkg")
216-
ENDIF(BUILD_GRAPHICS)
216+
ENDIF(AF_WITH_GRAPHICS)
217217

218218
ADD_CUSTOM_COMMAND( OUTPUT ${PACKAGE_NAME}
219219
DEPENDS ${ARGS_DEPENDS}
@@ -289,7 +289,7 @@ PKG_BUILD( PKG_NAME ArrayFireDoc
289289
PATH_TO_FILES ${OSX_TEMP}/doc
290290
FILTERS cmake)
291291

292-
IF(BUILD_GRAPHICS)
292+
IF(AF_WITH_GRAPHICS)
293293
PKG_BUILD( PKG_NAME ForgeLibrary
294294
DEPENDS OSX_INSTALL_SETUP_FORGE_LIB
295295
TARGETS forge_lib_package
@@ -328,16 +328,16 @@ IF(BUILD_GRAPHICS)
328328
IDENTIFIER com.arrayfire.pkg.forge.cmake
329329
PATH_TO_FILES ${OSX_TEMP}/Forge/cmake
330330
)
331-
ENDIF(BUILD_GRAPHICS)
331+
ENDIF(AF_WITH_GRAPHICS)
332332

333-
IF(BUILD_GRAPHICS)
333+
IF(AF_WITH_GRAPHICS)
334334
PRODUCT_BUILD(DEPENDS ${cpu_package} ${cuda_package} ${opencl_package} ${unified_package}
335335
${common_package} ${header_package} ${examples_package} ${doc_package}
336336
${forge_lib_package} ${forge_header_package} ${forge_examples_package} ${forge_doc_package} ${forge_cmake_package}
337337
)
338-
ELSE(BUILD_GRAPHICS)
338+
ELSE(AF_WITH_GRAPHICS)
339339
PRODUCT_BUILD(DEPENDS ${cpu_package} ${cuda_package} ${opencl_package} ${unified_package}
340340
${common_package} ${header_package} ${examples_package} ${doc_package}
341341
)
342-
ENDIF(BUILD_GRAPHICS)
342+
ENDIF(AF_WITH_GRAPHICS)
343343

examples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ process; however, the compiled examples are not packaged in the ArrayFire
1111
installer. After compiling ArrayFire, the examples will be in subdirectories
1212
located in the `build/examples` directory.
1313

14-
If you wish to disable example compilation, simply set the `BUILD_EXAMPLES`
14+
If you wish to disable example compilation, simply set the `AF_BUILD_EXAMPLES`
1515
variable to `OFF` in the CMake GUI or `ccmake` curses wrapper. If you are
1616
using the command-line version of `cmake`, simply specify
17-
`-DBUILD_EXAMPLES=OFF` as an argument.
17+
`-DAF_BUILD_EXAMPLES=OFF` as an argument.
1818

1919
## Building examples as a stand-alone project
2020

src/api/c/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ target_sources(c_api_interface
152152
${CMAKE_CURRENT_SOURCE_DIR}/ycbcr_rgb.cpp
153153
)
154154

155-
if(FreeImage_FOUND AND WITH_IMAGEIO)
155+
if(FreeImage_FOUND AND AF_WITH_IMAGEIO)
156156
target_compile_definitions(c_api_interface INTERFACE WITH_FREEIMAGE)
157157
target_link_libraries( c_api_interface INTERFACE FreeImage::FreeImage)
158158
endif()
159159

160-
if(BUILD_GRAPHICS)
160+
if(AF_WITH_GRAPHICS)
161161
add_dependencies(c_api_interface forge-ext)
162162
target_compile_definitions(c_api_interface INTERFACE WITH_GRAPHICS)
163163
endif()

src/api/c/sift.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ af_err af_sift(af_features* feat, af_array* desc, const af_array in, const unsig
5454
const bool double_input, const float img_scale, const float feature_ratio)
5555
{
5656
try {
57-
#ifdef AF_BUILD_NONFREE_SIFT
57+
#ifdef AF_WITH_NONFREE_SIFT
5858
const ArrayInfo& info = getInfo(in);
5959
af::dim4 dims = info.dims();
6060

@@ -95,7 +95,7 @@ af_err af_gloh(af_features* feat, af_array* desc, const af_array in, const unsig
9595
const bool double_input, const float img_scale, const float feature_ratio)
9696
{
9797
try {
98-
#ifdef AF_BUILD_NONFREE_SIFT
98+
#ifdef AF_WITH_NONFREE_SIFT
9999
const ArrayInfo& info = getInfo(in);
100100
af::dim4 dims = info.dims();
101101

src/backend/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ target_include_directories(afcommon_interface
3737

3838
add_library(afcommon_lapack_interface INTERFACE)
3939

40-
if(BUILD_GRAPHICS)
40+
if(AF_WITH_GRAPHICS)
4141
dependency_check(glbinding_FOUND "glbinding not found.")
4242

4343
target_include_directories(afcommon_interface

src/backend/cpu/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ target_sources(afcpu
242242
kernel/wrap.hpp
243243
)
244244

245-
if (USE_CPUID)
246-
target_compile_definitions(afcpu PRIVATE -DUSE_CPUID)
247-
endif(USE_CPUID)
245+
if (AF_WITH_CPUID)
246+
target_compile_definitions(afcpu PRIVATE -DAF_WITH_CPUID)
247+
endif(AF_WITH_CPUID)
248248

249249
target_sources(afcpu
250250
PRIVATE
@@ -257,12 +257,12 @@ endif()
257257

258258
include("${CMAKE_CURRENT_SOURCE_DIR}/kernel/sort_by_key/CMakeLists.txt")
259259

260-
if(BUILD_NONFREE)
260+
if(AF_WITH_NONFREE)
261261
target_sources(afcpu PRIVATE kernel/sift_nonfree.hpp)
262-
target_compile_definitions(afcpu PRIVATE AF_BUILD_NONFREE_SIFT)
262+
target_compile_definitions(afcpu PRIVATE AF_WITH_NONFREE_SIFT)
263263
endif()
264264

265-
if(BUILD_GRAPHICS)
265+
if(AF_WITH_GRAPHICS)
266266
add_dependencies(afcpu forge-ext)
267267
target_sources(afcpu
268268
PRIVATE

src/backend/cpu/platform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <memory.hpp>
1717
#include <queue.hpp>
1818

19-
#if defined(USE_CPUID) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(_WIN64))
19+
#if defined(AF_WITH_CPUID) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(_WIN64))
2020
#define CPUID_CAPABLE
2121
#endif
2222

0 commit comments

Comments
 (0)