From 45c9ed825a51c05395fd28b376271324e0315d0c Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 27 Mar 2020 14:22:35 -0700 Subject: [PATCH] Formatting cmake (to lowercase without space for if/elseif/else/endif) (#35521) Summary: Running commands: ```bash shopt -s globstar sed -e 's/IF (/if(/g' -e 's/IF(/if(/g' -e 's/if (/if(/g' -e 's/ELSE (/else(/g' -e 's/ELSE(/else(/g' -e 's/else (/else(/g' -e 's/ENDif(/endif(/g' -e 's/ELSEif(/elseif(/g' -i CMakeLists.txt sed -e 's/IF (/if(/g' -e 's/IF(/if(/g' -e 's/if (/if(/g' -e 's/ELSE (/else(/g' -e 's/ELSE(/else(/g' -e 's/else (/else(/g' -e 's/ENDif(/endif(/g' -e 's/ELSEif(/elseif(/g' -i caffe2/**/CMakeLists.txt sed -e 's/IF (/if(/g' -e 's/IF(/if(/g' -e 's/if (/if(/g' -e 's/ELSE (/else(/g' -e 's/ELSE(/else(/g' -e 's/else (/else(/g' -e 's/ENDif(/endif(/g' -e 's/ELSEif(/elseif(/g' -i torch/**/CMakeLists.txt sed -e 's/IF (/if(/g' -e 's/IF(/if(/g' -e 's/if (/if(/g' -e 's/ELSE (/else(/g' -e 's/ELSE(/else(/g' -e 's/else (/else(/g' -e 's/ENDif(/endif(/g' -e 's/ELSEif(/elseif(/g' -i c10/**/CMakeLists.txt sed -e 's/IF (/if(/g' -e 's/IF(/if(/g' -e 's/if (/if(/g' -e 's/ELSE (/else(/g' -e 's/ELSE(/else(/g' -e 's/else (/else(/g' -e 's/ENDif(/endif(/g' -e 's/ELSEif(/elseif(/g' -i cmake/**/*.cmake sed -e 's/IF (/if(/g' -e 's/IF(/if(/g' -e 's/if (/if(/g' -e 's/ELSE (/else(/g' -e 's/ELSE(/else(/g' -e 's/else (/else(/g' -e 's/ENDif(/endif(/g' -e 's/ELSEif(/elseif(/g' -i cmake/**/*.cmake.in ``` We may further convert all the commands into lowercase according to the following issue: https://gitlab.kitware.com/cmake/cmake/commit/77543bde41b0e52c3959016698b529835945d62d. Pull Request resolved: https://github.com/pytorch/pytorch/pull/35521 Differential Revision: D20704382 Pulled By: malfet fbshipit-source-id: 42186b9b1660c34428ab7ceb8d3f7a0ced5d2e80 --- c10/CMakeLists.txt | 12 +- c10/benchmark/CMakeLists.txt | 4 +- c10/cuda/CMakeLists.txt | 4 +- c10/cuda/test/CMakeLists.txt | 4 +- c10/hip/CMakeLists.txt | 2 +- c10/test/CMakeLists.txt | 4 +- caffe2/contrib/CMakeLists.txt | 2 +- caffe2/contrib/nccl/CMakeLists.txt | 2 +- caffe2/contrib/prof/CMakeLists.txt | 2 +- caffe2/core/CMakeLists.txt | 4 +- caffe2/db/CMakeLists.txt | 6 +- caffe2/distributed/CMakeLists.txt | 2 +- caffe2/mobile/contrib/CMakeLists.txt | 2 +- caffe2/mobile/contrib/ios/CMakeLists.txt | 2 +- caffe2/mobile/contrib/nnapi/CMakeLists.txt | 2 +- caffe2/operators/CMakeLists.txt | 8 +- caffe2/operators/rnn/CMakeLists.txt | 4 +- caffe2/perfkernels/CMakeLists.txt | 10 +- caffe2/proto/CMakeLists.txt | 2 +- caffe2/quantization/server/CMakeLists.txt | 4 +- caffe2/share/CMakeLists.txt | 2 +- caffe2/share/contrib/CMakeLists.txt | 6 +- caffe2/utils/CMakeLists.txt | 4 +- cmake/Caffe2Config.cmake.in | 28 +- cmake/Caffe2ConfigVersion.cmake.in | 2 +- cmake/Codegen.cmake | 66 ++-- cmake/Dependencies.cmake | 334 ++++++++++----------- cmake/External/nccl.cmake | 6 +- cmake/External/nnpack.cmake | 10 +- cmake/External/rccl.cmake | 6 +- cmake/MiscCheck.cmake | 38 +-- cmake/ProtoBuf.cmake | 30 +- cmake/ProtoBufPatch.cmake | 4 +- cmake/TorchConfig.cmake.in | 24 +- cmake/TorchConfigVersion.cmake.in | 2 +- cmake/Utils.cmake | 6 +- cmake/Whitelist.cmake | 6 +- cmake/cmake_uninstall.cmake.in | 4 +- cmake/iOS.cmake | 50 +-- cmake/public/LoadHIP.cmake | 110 +++---- cmake/public/cuda.cmake | 32 +- cmake/public/gflags.cmake | 6 +- cmake/public/glog.cmake | 6 +- cmake/public/protobuf.cmake | 14 +- cmake/public/utils.cmake | 42 +-- torch/lib/libshm/CMakeLists.txt | 14 +- torch/lib/libshm_windows/CMakeLists.txt | 6 +- 47 files changed, 470 insertions(+), 470 deletions(-) diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt index a43122c750f6..cda08e384ae1 100644 --- a/c10/CMakeLists.txt +++ b/c10/CMakeLists.txt @@ -40,20 +40,20 @@ add_library(c10 ${C10_SRCS} ${C10_HEADERS}) # If building shared library, set dllimport/dllexport proper. target_compile_options(c10 PRIVATE "-DC10_BUILD_MAIN_LIB") # Enable hidden visibility if compiler supports it. -if (${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) +if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) target_compile_options(c10 PRIVATE "-fvisibility=hidden") endif() # ---[ Dependency of c10 -if (${USE_GFLAGS}) +if(${USE_GFLAGS}) target_link_libraries(c10 PUBLIC gflags) endif() -if (${USE_GLOG}) +if(${USE_GLOG}) target_link_libraries(c10 PUBLIC glog::glog) endif() -if (USE_NUMA) +if(USE_NUMA) message(STATUS "NUMA paths:") message(STATUS ${Numa_INCLUDE_DIR}) message(STATUS ${Numa_LIBRARIES}) @@ -63,7 +63,7 @@ else() message(STATUS "don't use NUMA") endif() -if (ANDROID) +if(ANDROID) target_link_libraries(c10 PRIVATE log) endif() @@ -97,6 +97,6 @@ install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} install(FILES ${CMAKE_BINARY_DIR}/c10/macros/cmake_macros.h DESTINATION include/c10/macros) -if (MSVC AND C10_BUILD_SHARED_LIBS) +if(MSVC AND C10_BUILD_SHARED_LIBS) install(FILES $ DESTINATION lib OPTIONAL) endif() diff --git a/c10/benchmark/CMakeLists.txt b/c10/benchmark/CMakeLists.txt index 710377337543..9658e6037616 100644 --- a/c10/benchmark/CMakeLists.txt +++ b/c10/benchmark/CMakeLists.txt @@ -1,13 +1,13 @@ # ---[ Benchmark binaries. file(GLOB_RECURSE C10_ALL_BENCH_FILES *.cpp) -if (BUILD_TEST) +if(BUILD_TEST) foreach(bench_src ${C10_ALL_BENCH_FILES}) get_filename_component(bench_file_name ${bench_src} NAME_WE) set(bench_name "c10_${bench_file_name}") add_executable(${bench_name} "${bench_src}") target_link_libraries(${bench_name} c10 benchmark) - if (INSTALL_TEST) + if(INSTALL_TEST) install(TARGETS ${bench_name} DESTINATION test) endif() endforeach() diff --git a/c10/cuda/CMakeLists.txt b/c10/cuda/CMakeLists.txt index e992a4e1bfda..26d96753c199 100644 --- a/c10/cuda/CMakeLists.txt +++ b/c10/cuda/CMakeLists.txt @@ -40,7 +40,7 @@ set(CUDA_LINK_LIBRARIES_KEYWORD) # If building shared library, set dllimport/dllexport proper. target_compile_options(c10_cuda PRIVATE "-DC10_CUDA_BUILD_MAIN_LIB") # Enable hidden visibility if compiler supports it. -if (${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) +if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) target_compile_options(c10_cuda PRIVATE "-fvisibility=hidden") endif() @@ -69,6 +69,6 @@ endforeach() install(FILES ${CMAKE_BINARY_DIR}/c10/cuda/impl/cuda_cmake_macros.h DESTINATION include/c10/cuda/impl) -if (MSVC AND C10_CUDA_BUILD_SHARED_LIBS) +if(MSVC AND C10_CUDA_BUILD_SHARED_LIBS) install(FILES $ DESTINATION lib OPTIONAL) endif() diff --git a/c10/cuda/test/CMakeLists.txt b/c10/cuda/test/CMakeLists.txt index 97e5f818e9af..30d60871b8f1 100644 --- a/c10/cuda/test/CMakeLists.txt +++ b/c10/cuda/test/CMakeLists.txt @@ -3,14 +3,14 @@ set(C10_CUDA_ALL_TEST_FILES impl/CUDATest.cpp ) -if (BUILD_TEST) +if(BUILD_TEST) foreach(test_src ${C10_CUDA_ALL_TEST_FILES}) get_filename_component(test_file_name ${test_src} NAME_WE) set(test_name "c10_cuda_${test_file_name}") add_executable(${test_name} "${test_src}") target_link_libraries(${test_name} c10_cuda gtest_main) add_test(NAME ${test_name} COMMAND $) - if (INSTALL_TEST) + if(INSTALL_TEST) install(TARGETS ${test_name} DESTINATION test) endif() endforeach() diff --git a/c10/hip/CMakeLists.txt b/c10/hip/CMakeLists.txt index 328d21470c2f..6a0e0e41a134 100644 --- a/c10/hip/CMakeLists.txt +++ b/c10/hip/CMakeLists.txt @@ -37,7 +37,7 @@ target_compile_options(c10_hip PRIVATE ${HIP_CXX_FLAGS}) # If building shared library, set dllimport/dllexport proper. target_compile_options(c10_hip PRIVATE "-DC10_HIP_BUILD_MAIN_LIB") # Enable hidden visibility if compiler supports it. -if (${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) +if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) target_compile_options(c10_hip PRIVATE "-fvisibility=hidden") endif() diff --git a/c10/test/CMakeLists.txt b/c10/test/CMakeLists.txt index ec2183809933..acd9b4ded438 100644 --- a/c10/test/CMakeLists.txt +++ b/c10/test/CMakeLists.txt @@ -1,14 +1,14 @@ # ---[ Test binaries. file(GLOB_RECURSE C10_ALL_TEST_FILES *.cpp) -if (BUILD_TEST) +if(BUILD_TEST) foreach(test_src ${C10_ALL_TEST_FILES}) get_filename_component(test_file_name ${test_src} NAME_WE) set(test_name "c10_${test_file_name}") add_executable(${test_name} "${test_src}") target_link_libraries(${test_name} c10 gmock gtest gtest_main) add_test(NAME ${test_name} COMMAND $) - if (INSTALL_TEST) + if(INSTALL_TEST) install(TARGETS ${test_name} DESTINATION test) endif() endforeach() diff --git a/caffe2/contrib/CMakeLists.txt b/caffe2/contrib/CMakeLists.txt index 86442ce76897..9122305834fd 100644 --- a/caffe2/contrib/CMakeLists.txt +++ b/caffe2/contrib/CMakeLists.txt @@ -3,7 +3,7 @@ add_subdirectory(nccl) add_subdirectory(opencl) add_subdirectory(prof) add_subdirectory(shm_mutex) -if (USE_TENSORRT) +if(USE_TENSORRT) add_subdirectory(tensorrt) endif() diff --git a/caffe2/contrib/nccl/CMakeLists.txt b/caffe2/contrib/nccl/CMakeLists.txt index 6d3ee5fb01ab..b58304886589 100644 --- a/caffe2/contrib/nccl/CMakeLists.txt +++ b/caffe2/contrib/nccl/CMakeLists.txt @@ -1,5 +1,5 @@ if(USE_NCCL) - if (USE_CUDA) + if(USE_CUDA) message(STATUS "Include NCCL operators") set(Caffe2_CONTRIB_NCCL_GPU_SRC "${CMAKE_CURRENT_SOURCE_DIR}/cuda_nccl_gpu.cc" diff --git a/caffe2/contrib/prof/CMakeLists.txt b/caffe2/contrib/prof/CMakeLists.txt index 81fee952c138..913cb6402190 100644 --- a/caffe2/contrib/prof/CMakeLists.txt +++ b/caffe2/contrib/prof/CMakeLists.txt @@ -1,4 +1,4 @@ -if (USE_PROF) +if(USE_PROF) set(Caffe2_CONTRIB_PROF_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/prof_dag_stats_op.cc" ) diff --git a/caffe2/core/CMakeLists.txt b/caffe2/core/CMakeLists.txt index 1a156eb63ccc..4003093f6357 100644 --- a/caffe2/core/CMakeLists.txt +++ b/caffe2/core/CMakeLists.txt @@ -1,4 +1,4 @@ -if (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) +if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/common.cc" ) @@ -8,7 +8,7 @@ endif() # ---[ GPU files # ------[ cuDNN -if (USE_CUDNN) +if(USE_CUDNN) file(GLOB tmp *_cudnn.cc) set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp}) endif() diff --git a/caffe2/db/CMakeLists.txt b/caffe2/db/CMakeLists.txt index 9c9ceda597a1..eef691ea3fd0 100644 --- a/caffe2/db/CMakeLists.txt +++ b/caffe2/db/CMakeLists.txt @@ -15,15 +15,15 @@ list(APPEND Caffe2_GPU_SRCS ${Caffe2_DB_COMMON_GPU_SRC}) list(APPEND Caffe2_HIP_SRCS ${Caffe2_DB_COMMON_HIP_SRC}) # DB specific files -if (USE_LMDB) +if(USE_LMDB) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/lmdb.cc") endif() -if (USE_LEVELDB) +if(USE_LEVELDB) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/leveldb.cc") endif() -if (USE_ZMQ) +if(USE_ZMQ) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/zmqdb.cc") endif() diff --git a/caffe2/distributed/CMakeLists.txt b/caffe2/distributed/CMakeLists.txt index 41373ef2d503..db8620ec0441 100644 --- a/caffe2/distributed/CMakeLists.txt +++ b/caffe2/distributed/CMakeLists.txt @@ -22,7 +22,7 @@ set(Caffe2_STORE_REDIS_GPU_SRC list(APPEND Caffe2_CPU_SRCS ${Caffe2_STORE_COMMON_SRC}) list(APPEND Caffe2_GPU_SRCS ${Caffe2_STORE_COMMON_GPU_SRC}) -if (USE_REDIS) +if(USE_REDIS) list(APPEND Caffe2_CPU_SRCS ${Caffe2_STORE_REDIS_SRC}) list(APPEND Caffe2_GPU_SRCS ${Caffe2_STORE_REDIS_GPU_SRC}) endif() diff --git a/caffe2/mobile/contrib/CMakeLists.txt b/caffe2/mobile/contrib/CMakeLists.txt index 617369f275e1..60daa19dc097 100644 --- a/caffe2/mobile/contrib/CMakeLists.txt +++ b/caffe2/mobile/contrib/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(ios) -if (USE_NNAPI) +if(USE_NNAPI) add_subdirectory(nnapi) endif() diff --git a/caffe2/mobile/contrib/ios/CMakeLists.txt b/caffe2/mobile/contrib/ios/CMakeLists.txt index 36a87f87511b..623bf771bf1a 100644 --- a/caffe2/mobile/contrib/ios/CMakeLists.txt +++ b/caffe2/mobile/contrib/ios/CMakeLists.txt @@ -8,7 +8,7 @@ if(IOS) ) set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${Caffe2_CONTRIB_IOS_SRC}) - if (USE_METAL) + if(USE_METAL) # metal/mpscnn files add_subdirectory(mpscnn) endif() diff --git a/caffe2/mobile/contrib/nnapi/CMakeLists.txt b/caffe2/mobile/contrib/nnapi/CMakeLists.txt index 403bbb8983e8..1144e4d819d8 100644 --- a/caffe2/mobile/contrib/nnapi/CMakeLists.txt +++ b/caffe2/mobile/contrib/nnapi/CMakeLists.txt @@ -1,4 +1,4 @@ -if (USE_NNAPI AND ANDROID) +if(USE_NNAPI AND ANDROID) set(Caffe2_CONTRIB_NNAPI_CPU_SRC "${CMAKE_CURRENT_SOURCE_DIR}/dlnnapi.c" "${CMAKE_CURRENT_SOURCE_DIR}/nnapi.cc" diff --git a/caffe2/operators/CMakeLists.txt b/caffe2/operators/CMakeLists.txt index 8f37176ce735..aefa51b4858d 100644 --- a/caffe2/operators/CMakeLists.txt +++ b/caffe2/operators/CMakeLists.txt @@ -1,6 +1,6 @@ # ---[ GPU files # ------[ cuDNN -if (USE_CUDNN) +if(USE_CUDNN) file(GLOB tmp *_cudnn.cc *_cudnn.cu) set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp}) endif() @@ -8,7 +8,7 @@ endif() file(GLOB tmp *_gpu.cc) set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp}) # ------[ TensorRT -if (USE_TENSORRT) +if(USE_TENSORRT) file(GLOB tmp *_trt.cc) set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp}) endif() @@ -42,7 +42,7 @@ exclude(tmp "${tmp}" ${tmp_cudnn}) set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${tmp}) # Add all files in experimental -if (NOT INTERN_BUILD_MOBILE) +if(NOT INTERN_BUILD_MOBILE) set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${CMAKE_CURRENT_LIST_DIR}/experimental/c10/cpu/flatten_cpu.cc) set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${CMAKE_CURRENT_LIST_DIR}/experimental/c10/cpu/averaged_loss_cpu.cc) set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${CMAKE_CURRENT_LIST_DIR}/experimental/c10/cpu/mul_cpu.cc) @@ -70,7 +70,7 @@ exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_GPU_SRCS} ${Caffe2_HIP_SRC # ---[ GPU test files # ------[ cuDNN -if (USE_CUDNN) +if(USE_CUDNN) file(GLOB tmp *_cudnn_test.cc) set(Caffe2_GPU_TEST_SRCS ${Caffe2_GPU_TEST_SRCS} ${tmp}) endif() diff --git a/caffe2/operators/rnn/CMakeLists.txt b/caffe2/operators/rnn/CMakeLists.txt index 589090eecdbb..ddf5cd3f134a 100644 --- a/caffe2/operators/rnn/CMakeLists.txt +++ b/caffe2/operators/rnn/CMakeLists.txt @@ -1,6 +1,6 @@ # ---[ GPU files # ------[ cuDNN -if (USE_CUDNN) +if(USE_CUDNN) file(GLOB tmp *_cudnn.cc) set(Caffe2_GPU_SRCS ${Caffe2_GPU_SRCS} ${tmp}) endif() @@ -38,7 +38,7 @@ exclude(Caffe2_CPU_SRCS "${Caffe2_CPU_SRCS}" ${Caffe2_GPU_SRCS} ${Caffe2_HIP_SRC # ---[ GPU test files # ------[ cuDNN -if (USE_CUDNN) +if(USE_CUDNN) file(GLOB tmp *_cudnn_test.cc) set(Caffe2_GPU_TEST_SRCS ${Caffe2_GPU_TEST_SRCS} ${tmp}) endif() diff --git a/caffe2/perfkernels/CMakeLists.txt b/caffe2/perfkernels/CMakeLists.txt index 42c5ddd3bc0b..23bd5d4cd722 100644 --- a/caffe2/perfkernels/CMakeLists.txt +++ b/caffe2/perfkernels/CMakeLists.txt @@ -1,4 +1,4 @@ -if (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) +if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) list(APPEND Caffe2_CPU_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/embedding_lookup_idx.cc" ) @@ -21,14 +21,14 @@ set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${common_srcs}) # We will only build the perf kernel files if the compiler supports avx2 # extensions. -if (CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) +if(CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) add_library(Caffe2_perfkernels_avx STATIC ${avx_srcs}) add_library(Caffe2_perfkernels_avx2 STATIC ${avx2_srcs}) add_dependencies(Caffe2_perfkernels_avx Caffe2_PROTO) add_dependencies(Caffe2_perfkernels_avx2 Caffe2_PROTO) target_link_libraries(Caffe2_perfkernels_avx PRIVATE c10) target_link_libraries(Caffe2_perfkernels_avx2 PRIVATE c10) - if (MSVC) + if(MSVC) target_compile_options(Caffe2_perfkernels_avx PRIVATE "/arch:AVX" PRIVATE "/D__F16C__") @@ -57,11 +57,11 @@ if (CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) Caffe2_DEPENDENCY_WHOLE_LINK_LIBS "Caffe2_perfkernels_avx2_interface") - if (CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS) + if(CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS) add_library(Caffe2_perfkernels_avx512 STATIC ${avx512_srcs}) add_dependencies(Caffe2_perfkernels_avx512 Caffe2_PROTO) target_link_libraries(Caffe2_perfkernels_avx512 PRIVATE c10) - if (MSVC) + if(MSVC) target_compile_options(Caffe2_perfkernels_avx512 PRIVATE "/D__AVX512F__" PRIVATE "/D__AVX512DQ__" diff --git a/caffe2/proto/CMakeLists.txt b/caffe2/proto/CMakeLists.txt index 7a84f1084895..ac48fd7e50a8 100644 --- a/caffe2/proto/CMakeLists.txt +++ b/caffe2/proto/CMakeLists.txt @@ -4,7 +4,7 @@ caffe2_protobuf_generate_cpp_py(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS Caffe2_PR add_library(Caffe2_PROTO OBJECT ${Caffe2_PROTO_HEADERS} ${Caffe2_PROTO_SRCS}) -if (MSVC) +if(MSVC) if(BUILD_SHARED_LIBS) set(Caffe2_API_DEFINE "-DCAFFE2_API=__declspec(dllexport)") else() diff --git a/caffe2/quantization/server/CMakeLists.txt b/caffe2/quantization/server/CMakeLists.txt index 24d3ae2fcdd2..e68013347288 100644 --- a/caffe2/quantization/server/CMakeLists.txt +++ b/caffe2/quantization/server/CMakeLists.txt @@ -60,13 +60,13 @@ list(APPEND Caffe2_CPU_SRCS #"${CMAKE_CURRENT_SOURCE_DIR}/sigmoid_test.cc") #"${CMAKE_CURRENT_SOURCE_DIR}/tanh_test.cc") -if (CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) +if(CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) add_library(caffe2_dnnlowp_avx2_ops OBJECT ${caffe2_dnnlowp_avx2_ops_SRCS}) add_dependencies(caffe2_dnnlowp_avx2_ops fbgemm Caffe2_PROTO c10) target_include_directories(caffe2_dnnlowp_avx2_ops BEFORE PRIVATE $) - if (MSVC) + if(MSVC) set_property(SOURCE ${caffe2_dnnlowp_avx2_ops_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " /arch:AVX2 ") else() diff --git a/caffe2/share/CMakeLists.txt b/caffe2/share/CMakeLists.txt index 73fd22b0821d..bbcca8fbb7be 100644 --- a/caffe2/share/CMakeLists.txt +++ b/caffe2/share/CMakeLists.txt @@ -1,6 +1,6 @@ # There is a linking issue that happens in some of the Windows builds. # TODO(Yangqing): after the module redesing, enable this back. -if (NOT MSVC) +if(NOT MSVC) add_subdirectory(contrib) endif() diff --git a/caffe2/share/contrib/CMakeLists.txt b/caffe2/share/contrib/CMakeLists.txt index 0fc3a4186f01..dca0439bd6b1 100644 --- a/caffe2/share/contrib/CMakeLists.txt +++ b/caffe2/share/contrib/CMakeLists.txt @@ -1,10 +1,10 @@ -if (USE_NNPACK AND BUILD_CAFFE2_OPS) +if(USE_NNPACK AND BUILD_CAFFE2_OPS) add_subdirectory(nnpack) endif() -if (USE_ZSTD) +if(USE_ZSTD) add_subdirectory(zstd) endif() -if (NOT MSVC) +if(NOT MSVC) add_subdirectory(depthwise) endif() diff --git a/caffe2/utils/CMakeLists.txt b/caffe2/utils/CMakeLists.txt index 27aabb131553..a83dcb151536 100644 --- a/caffe2/utils/CMakeLists.txt +++ b/caffe2/utils/CMakeLists.txt @@ -1,6 +1,6 @@ # TODO: Add ThreadPoolXNNPACK.cc when XNNPACK integration is updated # to pass the actual threadpool ptr instead of nullptr. -if (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) +if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) add_definitions(-DUSE_INTERNAL_THREADPOOL_IMPL) list(APPEND Caffe2_CPU_SRCS utils/string_utils.cc @@ -36,7 +36,7 @@ list(APPEND Caffe2_CPU_SRCS # ---[ threadpool/pthreadpool* is a local modification of the NNPACK # pthreadpool with a very similar interface. Neither NNPACK, nor this # thread pool supports Windows. -if (NOT MSVC) +if(NOT MSVC) add_definitions(-DUSE_INTERNAL_THREADPOOL_IMPL) set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} utils/threadpool/pthreadpool.cc diff --git a/cmake/Caffe2Config.cmake.in b/cmake/Caffe2Config.cmake.in index 7ab55bb4bee2..f9979008f520 100644 --- a/cmake/Caffe2Config.cmake.in +++ b/cmake/Caffe2Config.cmake.in @@ -18,9 +18,9 @@ include("${CMAKE_CURRENT_LIST_DIR}/public/threads.cmake") # Depending on whether Caffe2 uses gflags during compile time or # not, invoke gflags. -if (@USE_GFLAGS@) +if(@USE_GFLAGS@) include("${CMAKE_CURRENT_LIST_DIR}/public/gflags.cmake") - if (NOT TARGET gflags) + if(NOT TARGET gflags) message(FATAL_ERROR "Your installed Caffe2 version uses gflags but the gflags library " "cannot be found. Did you accidentally remove it, or have you set " @@ -32,9 +32,9 @@ endif() # Depending on whether Caffe2 uses glog during compile time or # not, invoke glog. -if (@USE_GLOG@) +if(@USE_GLOG@) include("${CMAKE_CURRENT_LIST_DIR}/public/glog.cmake") - if (NOT TARGET glog::glog) + if(NOT TARGET glog::glog) message(FATAL_ERROR "Your installed Caffe2 version uses glog but the glog library " "cannot be found. Did you accidentally remove it, or have you set " @@ -45,8 +45,8 @@ if (@USE_GLOG@) endif() # Protobuf -if (@CAFFE2_LINK_LOCAL_PROTOBUF@) - if (NOT TARGET protobuf::libprotobuf) +if(@CAFFE2_LINK_LOCAL_PROTOBUF@) + if(NOT TARGET protobuf::libprotobuf) # Define protobuf::libprotobuf as a dummy target to resolve references to # protobuf::libprotobuf in Caffe2Targets.cmake. add_library(dummy INTERFACE) @@ -54,7 +54,7 @@ if (@CAFFE2_LINK_LOCAL_PROTOBUF@) endif() else() include("${CMAKE_CURRENT_LIST_DIR}/public/protobuf.cmake") - if (NOT TARGET protobuf::libprotobuf) + if(NOT TARGET protobuf::libprotobuf) message(FATAL_ERROR "Your installed Caffe2 version uses protobuf but the protobuf library " "cannot be found. Did you accidentally remove it, or have you set " @@ -65,8 +65,8 @@ else() # If during build time we know the protobuf version, we will also do a sanity # check to ensure that the protobuf library that Caffe2 found is consistent # with the compiled version. - if (@CAFFE2_KNOWN_PROTOBUF_VERSION@) - if (NOT (${Protobuf_VERSION} VERSION_EQUAL @Protobuf_VERSION@)) + if(@CAFFE2_KNOWN_PROTOBUF_VERSION@) + if(NOT (${Protobuf_VERSION} VERSION_EQUAL @Protobuf_VERSION@)) message(FATAL_ERROR "Your installed Caffe2 is built with protobuf " "@Protobuf_VERSION@" @@ -78,7 +78,7 @@ else() endif() endif() -if (@USE_CUDA@) +if(@USE_CUDA@) # The file public/cuda.cmake exclusively uses CAFFE2_USE_*. # If Caffe2 was compiled with the libraries below, they must # be found again when including the Caffe2 target. @@ -86,19 +86,19 @@ if (@USE_CUDA@) set(CAFFE2_USE_CUDNN @USE_CUDNN@) set(CAFFE2_USE_TENSORRT @USE_TENSORRT@) include("${CMAKE_CURRENT_LIST_DIR}/public/cuda.cmake") - if (@CAFFE2_USE_CUDA@ AND NOT CAFFE2_USE_CUDA) + if(@CAFFE2_USE_CUDA@ AND NOT CAFFE2_USE_CUDA) message(FATAL_ERROR "Your installed Caffe2 version uses CUDA but I cannot find the CUDA " "libraries. Please set the proper CUDA prefixes and / or install " "CUDA.") endif() - if (@CAFFE2_USE_CUDNN@ AND NOT CAFFE2_USE_CUDNN) + if(@CAFFE2_USE_CUDNN@ AND NOT CAFFE2_USE_CUDNN) message(FATAL_ERROR "Your installed Caffe2 version uses cuDNN but I cannot find the cuDNN " "libraries. Please set the proper cuDNN prefixes and / or install " "cuDNN.") endif() - if (@CAFFE2_USE_TENSORRT@ AND NOT CAFFE2_USE_TENSORRT) + if(@CAFFE2_USE_TENSORRT@ AND NOT CAFFE2_USE_TENSORRT) message(FATAL_ERROR "Your installed Caffe2 version uses TensorRT but I cannot find the TensorRT " "libraries. Please set the proper TensorRT prefixes and / or install " @@ -108,7 +108,7 @@ endif() include("${CMAKE_CURRENT_LIST_DIR}/public/mkl.cmake") -if (@USE_MKLDNN@) +if(@USE_MKLDNN@) include("${CMAKE_CURRENT_LIST_DIR}/public/mkldnn.cmake") endif() diff --git a/cmake/Caffe2ConfigVersion.cmake.in b/cmake/Caffe2ConfigVersion.cmake.in index d130e12314c9..c13d3df1c094 100644 --- a/cmake/Caffe2ConfigVersion.cmake.in +++ b/cmake/Caffe2ConfigVersion.cmake.in @@ -5,7 +5,7 @@ if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_EXACT TRUE) endif() endif() diff --git a/cmake/Codegen.cmake b/cmake/Codegen.cmake index d4e3402a046a..bf037af16b32 100644 --- a/cmake/Codegen.cmake +++ b/cmake/Codegen.cmake @@ -43,7 +43,7 @@ configure_file( install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../caffe2 DESTINATION include FILES_MATCHING PATTERN "*.h") -if (NOT INTERN_BUILD_ATEN_OPS) +if(NOT INTERN_BUILD_ATEN_OPS) install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/core DESTINATION include/ATen FILES_MATCHING PATTERN "*.h") @@ -52,44 +52,44 @@ install(FILES ${CMAKE_BINARY_DIR}/caffe2/core/macros.h DESTINATION include/caffe2/core) # ---[ ATen specific -if (INTERN_BUILD_ATEN_OPS) - IF(MSVC) +if(INTERN_BUILD_ATEN_OPS) + if(MSVC) SET(OPT_FLAG "/fp:strict ") - ELSE(MSVC) + else(MSVC) SET(OPT_FLAG "-O3 ") - IF("${CMAKE_BUILD_TYPE}" MATCHES "Debug") + if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") SET(OPT_FLAG " ") - ENDIF() - ENDIF(MSVC) + endif() + endif(MSVC) - IF(C_AVX_FOUND) - IF(MSVC) + if(C_AVX_FOUND) + if(MSVC) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_LIST_DIR}/../aten/src/TH/vector/AVX.cpp PROPERTIES COMPILE_FLAGS "${OPT_FLAG}/arch:AVX ${CXX_AVX_FLAGS}") - ELSE(MSVC) + else(MSVC) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_LIST_DIR}/../aten/src/TH/vector/AVX.cpp PROPERTIES COMPILE_FLAGS "${OPT_FLAG} ${CXX_AVX_FLAGS}") - ENDIF(MSVC) - ENDIF(C_AVX_FOUND) + endif(MSVC) + endif(C_AVX_FOUND) - IF(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") + if(NOT MSVC AND NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_LIST_DIR}/../aten/src/TH/THAllocator.cpp PROPERTIES COMPILE_FLAGS "-fno-openmp") - ENDIF() + endif() FILE(GLOB cpu_kernel_cpp_in "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/cpu/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/quantized/cpu/kernels/*.cpp") LIST(APPEND CPU_CAPABILITY_NAMES "DEFAULT") LIST(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG}") - IF(CXX_AVX_FOUND) + if(CXX_AVX_FOUND) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_AVX_CPU_DEFINITION") LIST(APPEND CPU_CAPABILITY_NAMES "AVX") - IF(MSVC) + if(MSVC) LIST(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG}/arch:AVX") - ELSE(MSVC) + else(MSVC) LIST(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG} -mavx") - ENDIF(MSVC) - ENDIF(CXX_AVX_FOUND) + endif(MSVC) + endif(CXX_AVX_FOUND) - IF(CXX_AVX2_FOUND) + if(CXX_AVX2_FOUND) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_AVX2_CPU_DEFINITION") # Some versions of GCC pessimistically split unaligned load and store @@ -97,17 +97,17 @@ if (INTERN_BUILD_ATEN_OPS) # new Intel and AMD processors so we disable it when compiling with AVX2. # See https://stackoverflow.com/questions/52626726/why-doesnt-gcc-resolve-mm256-loadu-pd-as-single-vmovupd#tab-top check_cxx_compiler_flag("-mno-avx256-split-unaligned-load -mno-avx256-split-unaligned-store" COMPILER_SUPPORTS_NO_AVX256_SPLIT) - IF(COMPILER_SUPPORTS_NO_AVX256_SPLIT) + if(COMPILER_SUPPORTS_NO_AVX256_SPLIT) SET(CPU_NO_AVX256_SPLIT_FLAGS "-mno-avx256-split-unaligned-load -mno-avx256-split-unaligned-store") - ENDIF(COMPILER_SUPPORTS_NO_AVX256_SPLIT) + endif(COMPILER_SUPPORTS_NO_AVX256_SPLIT) LIST(APPEND CPU_CAPABILITY_NAMES "AVX2") - IF(MSVC) + if(MSVC) LIST(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG}/arch:AVX2") - ELSE(MSVC) + else(MSVC) LIST(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG} -mavx2 -mfma ${CPU_NO_AVX256_SPLIT_FLAGS}") - ENDIF(MSVC) - ENDIF(CXX_AVX2_FOUND) + endif(MSVC) + endif(CXX_AVX2_FOUND) list(LENGTH CPU_CAPABILITY_NAMES NUM_CPU_CAPABILITY_NAMES) math(EXPR NUM_CPU_CAPABILITY_NAMES "${NUM_CPU_CAPABILITY_NAMES}-1") @@ -120,11 +120,11 @@ if (INTERN_BUILD_ATEN_OPS) CONFIGURE_FILE(${IMPL} ${NEW_IMPL} COPYONLY) SET(cpu_kernel_cpp ${NEW_IMPL} ${cpu_kernel_cpp}) # Create list of copies LIST(GET CPU_CAPABILITY_FLAGS ${i} FLAGS) - IF(MSVC) + if(MSVC) SET(MACRO_FLAG "/DCPU_CAPABILITY=${CPU_CAPABILITY} /DCPU_CAPABILITY_${CPU_CAPABILITY}") - ELSE(MSVC) + else(MSVC) SET(MACRO_FLAG "-DCPU_CAPABILITY=${CPU_CAPABILITY} -DCPU_CAPABILITY_${CPU_CAPABILITY}") - ENDIF(MSVC) + endif(MSVC) SET_SOURCE_FILES_PROPERTIES(${NEW_IMPL} PROPERTIES COMPILE_FLAGS "${FLAGS} ${MACRO_FLAG}") ENDFOREACH() ENDFOREACH() @@ -139,13 +139,13 @@ if (INTERN_BUILD_ATEN_OPS) FILE(GLOB all_python "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/*.py") set(GEN_ROCM_FLAG) - if (USE_ROCM) + if(USE_ROCM) set(GEN_ROCM_FLAG --rocm) endif() set(CUSTOM_BUILD_FLAGS) - if (SELECTED_OP_LIST) - if (NOT USE_STATIC_DISPATCH AND NOT OP_DEPENDENCY) + if(SELECTED_OP_LIST) + if(NOT USE_STATIC_DISPATCH AND NOT OP_DEPENDENCY) message(FATAL_ERROR "Must provide op dependency graph .yaml file for custom build with dynamic dispatch!") endif() EXECUTE_PROCESS( @@ -176,7 +176,7 @@ if (INTERN_BUILD_ATEN_OPS) --output-dependencies ${CMAKE_BINARY_DIR}/aten/src/ATen/generated_cpp.txt RESULT_VARIABLE RETURN_VALUE ) - if (NOT RETURN_VALUE EQUAL 0) + if(NOT RETURN_VALUE EQUAL 0) message(STATUS ${generated_cpp}) message(FATAL_ERROR "Failed to get generated_cpp list") endif() diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index c0b30bbd6bcc..e47730d28fb1 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1,6 +1,6 @@ # RPATH stuff # see https://cmake.org/Wiki/CMake_RPATH_handling -if (APPLE) +if(APPLE) set(CMAKE_MACOSX_RPATH ON) set(_rpath_portable_origin "@loader_path") else() @@ -19,7 +19,7 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(UBSAN_FLAG "-fsanitize=undefined") macro(disable_ubsan) - if (CMAKE_C_FLAGS MATCHES ${UBSAN_FLAG} OR CMAKE_CXX_FLAGS MATCHES ${UBSAN_FLAG}) + if(CMAKE_C_FLAGS MATCHES ${UBSAN_FLAG} OR CMAKE_CXX_FLAGS MATCHES ${UBSAN_FLAG}) set(CAFFE2_UBSAN_ENABLED ON) string(REPLACE ${UBSAN_FLAG} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) string(REPLACE ${UBSAN_FLAG} "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) @@ -27,7 +27,7 @@ macro(disable_ubsan) endmacro() macro(enable_ubsan) - if (CAFFE2_UBSAN_ENABLED) + if(CAFFE2_UBSAN_ENABLED) set(CMAKE_C_FLAGS "${UBSAN_FLAG} ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "${UBSAN_FLAG} ${CMAKE_CXX_FLAGS}") endif() @@ -43,7 +43,7 @@ endif() # For MSVC, # 1. Replace /Zi and /ZI with /Z7 # 2. Switch off incremental linking in debug builds -if (MSVC) +if(MSVC) if(MSVC_Z7_OVERRIDE) foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE @@ -66,14 +66,14 @@ endif(MSVC) # ---[ Threads include(${CMAKE_CURRENT_LIST_DIR}/public/threads.cmake) -if (TARGET Threads::Threads) +if(TARGET Threads::Threads) list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS Threads::Threads) else() message(FATAL_ERROR "Cannot find threading library. Caffe2 requires Threads to compile.") endif() -if (USE_TBB) +if(USE_TBB) message(STATUS "Compiling TBB from source") # Unset our restrictive C++ flags here and reset them later. # Remove this once we use proper target_compile_options. @@ -151,14 +151,14 @@ else() message(FATAL_ERROR "Unrecognized BLAS option: " ${BLAS}) endif() -if (NOT INTERN_BUILD_MOBILE) +if(NOT INTERN_BUILD_MOBILE) set(AT_MKL_ENABLED 0) set(AT_MKL_MT 0) set(USE_BLAS 1) if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND)) message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library") find_package(BLAS) - if (NOT BLAS_FOUND) + if(NOT BLAS_FOUND) set(USE_BLAS 0) set(BLAS "" CACHE STRING "Selected BLAS library") else() @@ -166,12 +166,12 @@ if (NOT INTERN_BUILD_MOBILE) endif() endif() - if (MKL_FOUND) + if(MKL_FOUND) ADD_DEFINITIONS(-DTH_BLAS_MKL) - if ("${MKL_THREADING}" STREQUAL "SEQ") + if("${MKL_THREADING}" STREQUAL "SEQ") ADD_DEFINITIONS(-DTH_BLAS_MKL_SEQ=1) endif() - if (MSVC AND MKL_LIBRARIES MATCHES ".*libiomp5md\\.lib.*") + if(MSVC AND MKL_LIBRARIES MATCHES ".*libiomp5md\\.lib.*") ADD_DEFINITIONS(-D_OPENMP_NOFORCE_MANIFEST) set(AT_MKL_MT 1) endif() @@ -186,22 +186,22 @@ endif() # mismatch between these shared dependencies, explicitly declare our intent to these # libraries that we are interested in using the exact same source dependencies for all. -if (USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK) +if(USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK) set(DISABLE_NNPACK_AND_FAMILY OFF) # Sanity checks - Can we actually build NNPACK and family given the configuration provided? # Disable them and warn the user if not. - if (IOS) + if(IOS) list(LENGTH IOS_ARCH IOS_ARCH_COUNT) - if (IOS_ARCH_COUNT GREATER 1) + if(IOS_ARCH_COUNT GREATER 1) message(WARNING "Multi-architecture (${IOS_ARCH}) builds are not supported in {Q/X}NNPACK. " "Specify a single architecture in IOS_ARCH and re-configure, or " "turn this warning off by USE_{Q/X}NNPACK=OFF.") set(DISABLE_NNPACK_AND_FAMILY ON) endif() - if (NOT IOS_ARCH MATCHES "^(i386|x86_64|armv7.*|arm64.*)$") + if(NOT IOS_ARCH MATCHES "^(i386|x86_64|armv7.*|arm64.*)$") message(WARNING "Target architecture \"${IOS_ARCH}\" is not supported in {Q/X}NNPACK. " "Supported architectures are x86, x86-64, ARM, and ARM64. " @@ -209,14 +209,14 @@ if (USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK) set(DISABLE_NNPACK_AND_FAMILY ON) endif() else() - if (NOT IOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux|Darwin)$")) + if(NOT IOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux|Darwin)$")) message(WARNING "Target platform \"${CMAKE_SYSTEM_NAME}\" is not supported in {Q/X}NNPACK. " "Supported platforms are Android, iOS, Linux, and macOS. " "Turn this warning off by USE_{Q/X}NNPACK=OFF.") set(DISABLE_NNPACK_AND_FAMILY ON) endif() - if (NOT IOS AND NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|AMD64|x86_64|armv[0-9].*|arm64|aarch64)$")) + if(NOT IOS AND NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|AMD64|x86_64|armv[0-9].*|arm64|aarch64)$")) message(WARNING "Target architecture \"${CMAKE_SYSTEM_PROCESSOR}\" is not supported in {Q/X}NNPACK. " "Supported architectures are x86, x86-64, ARM, and ARM64. " @@ -225,7 +225,7 @@ if (USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK) endif() endif() - if (DISABLE_NNPACK_AND_FAMILY) + if(DISABLE_NNPACK_AND_FAMILY) set(USE_NNPACK OFF) set(USE_QNNPACK OFF) set(USE_PYTORCH_QNNPACK OFF) @@ -233,19 +233,19 @@ if (USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK) else() set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party") - if (NOT DEFINED CPUINFO_SOURCE_DIR) + if(NOT DEFINED CPUINFO_SOURCE_DIR) set(CPUINFO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/cpuinfo" CACHE STRING "cpuinfo source directory") endif() - if (NOT DEFINED FP16_SOURCE_DIR) + if(NOT DEFINED FP16_SOURCE_DIR) set(FP16_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FP16" CACHE STRING "FP16 source directory") endif() - if (NOT DEFINED FXDIV_SOURCE_DIR) + if(NOT DEFINED FXDIV_SOURCE_DIR) set(FXDIV_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FXdiv" CACHE STRING "FXdiv source directory") endif() - if (NOT DEFINED PSIMD_SOURCE_DIR) + if(NOT DEFINED PSIMD_SOURCE_DIR) set(PSIMD_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/psimd" CACHE STRING "PSimd source directory") endif() - if (NOT DEFINED PTHREADPOOL_SOURCE_DIR) + if(NOT DEFINED PTHREADPOOL_SOURCE_DIR) set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory") endif() @@ -279,39 +279,39 @@ if(INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE AND (USE_QNNPACK OR USE_NNPAC set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory") endif() - IF(NOT TARGET pthreadpool) + if(NOT TARGET pthreadpool) SET(PTHREADPOOL_BUILD_TESTS OFF CACHE BOOL "") SET(PTHREADPOOL_BUILD_BENCHMARKS OFF CACHE BOOL "") ADD_SUBDIRECTORY( "${PTHREADPOOL_SOURCE_DIR}" "${CONFU_DEPENDENCIES_BINARY_DIR}/pthreadpool" EXCLUDE_FROM_ALL) - ENDIF() + endif() endif() # XNNPACK has not option of like QNNPACK_CUSTOM_THREADPOOL # that allows us to hijack pthreadpool interface. # Thus not doing this ends up building pthreadpool as well as # the internal implemenation of pthreadpool which results in symbol conflicts. -if (USE_XNNPACK) +if(USE_XNNPACK) if(NOT DEFINED PTHREADPOOL_SOURCE_DIR) set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party") set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory") endif() - IF(NOT TARGET pthreadpool) + if(NOT TARGET pthreadpool) SET(PTHREADPOOL_BUILD_TESTS OFF CACHE BOOL "") SET(PTHREADPOOL_BUILD_BENCHMARKS OFF CACHE BOOL "") ADD_SUBDIRECTORY( "${PTHREADPOOL_SOURCE_DIR}" "${CONFU_DEPENDENCIES_BINARY_DIR}/pthreadpool" EXCLUDE_FROM_ALL) - ENDIF() + endif() endif() # ---[ Caffe2 uses cpuinfo library in the thread pool -if (NOT TARGET cpuinfo) - if (NOT DEFINED CPUINFO_SOURCE_DIR) +if(NOT TARGET cpuinfo) + if(NOT DEFINED CPUINFO_SOURCE_DIR) set(CPUINFO_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../third_party/cpuinfo" CACHE STRING "cpuinfo source directory") endif() @@ -322,7 +322,7 @@ if (NOT TARGET cpuinfo) set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "") set(CPUINFO_LOG_LEVEL "error" CACHE STRING "") if(MSVC) - if (CAFFE2_USE_MSVC_STATIC_RUNTIME) + if(CAFFE2_USE_MSVC_STATIC_RUNTIME) set(CPUINFO_RUNTIME_TYPE "static" CACHE STRING "") else() set(CPUINFO_RUNTIME_TYPE "shared" CACHE STRING "") @@ -343,7 +343,7 @@ list(APPEND Caffe2_DEPENDENCY_LIBS cpuinfo) if(USE_QNNPACK) set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party") - if (NOT DEFINED QNNPACK_SOURCE_DIR) + if(NOT DEFINED QNNPACK_SOURCE_DIR) set(QNNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/QNNPACK" CACHE STRING "QNNPACK source directory") endif() @@ -374,7 +374,7 @@ endif() # ---[ PYTORCH_QNNPACK if(USE_PYTORCH_QNNPACK) - if (NOT DEFINED PYTORCH_QNNPACK_SOURCE_DIR) + if(NOT DEFINED PYTORCH_QNNPACK_SOURCE_DIR) set(PYTORCH_QNNPACK_SOURCE_DIR "${PROJECT_SOURCE_DIR}/aten/src/ATen/native/quantized/cpu/qnnpack" CACHE STRING "QNNPACK source directory") endif() @@ -415,11 +415,11 @@ endif() # ---[ XNNPACK if(USE_XNNPACK) - if (NOT DEFINED XNNPACK_SOURCE_DIR) + if(NOT DEFINED XNNPACK_SOURCE_DIR) set(XNNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/XNNPACK" CACHE STRING "XNNPACK source directory") endif() - if (NOT DEFINED XNNPACK_INCLUDE_DIR) + if(NOT DEFINED XNNPACK_INCLUDE_DIR) set(XNNPACK_INCLUDE_DIR "${XNNPACK_SOURCE_DIR}/include" CACHE STRING "XNNPACK include directory") endif() @@ -452,7 +452,7 @@ endif() # ---[ gflags if(USE_GFLAGS) include(${CMAKE_CURRENT_LIST_DIR}/public/gflags.cmake) - if (NOT TARGET gflags) + if(NOT TARGET gflags) message(WARNING "gflags is not found. Caffe2 will build without gflags support but " "it is strongly recommended that you install gflags. Suppress this " @@ -464,7 +464,7 @@ endif() # ---[ Google-glog if(USE_GLOG) include(${CMAKE_CURRENT_LIST_DIR}/public/glog.cmake) - if (TARGET glog::glog) + if(TARGET glog::glog) set(CAFFE2_USE_GOOGLE_GLOG 1) include_directories(SYSTEM ${GLOG_INCLUDE_DIR}) list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS glog::glog) @@ -491,13 +491,13 @@ if(BUILD_TEST) set(INSTALL_GTEST OFF CACHE BOOL "Install gtest." FORCE) set(BUILD_GMOCK ON CACHE BOOL "Build gmock." FORCE) # For Windows, we will check the runtime used is correctly passed in. - if (NOT CAFFE2_USE_MSVC_STATIC_RUNTIME) + if(NOT CAFFE2_USE_MSVC_STATIC_RUNTIME) set(gtest_force_shared_crt ON CACHE BOOL "force shared crt on gtest" FORCE) endif() # We need to replace googletest cmake scripts too. # Otherwise, it will sometimes break the build. # To make the git clean after the build, we make a backup first. - if (MSVC AND MSVC_Z7_OVERRIDE) + if(MSVC AND MSVC_Z7_OVERRIDE) execute_process( COMMAND ${CMAKE_COMMAND} "-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake" @@ -537,7 +537,7 @@ if(BUILD_TEST) set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE) # To make the git clean after the build, we revert the changes here. - if (MSVC AND MSVC_Z7_OVERRIDE) + if(MSVC AND MSVC_Z7_OVERRIDE) execute_process( COMMAND ${CMAKE_COMMAND} "-DFILENAME=${CMAKE_CURRENT_LIST_DIR}/../third_party/googletest/googletest/cmake/internal_utils.cmake" @@ -606,7 +606,7 @@ if(USE_LMDB) endif() endif() -if (USE_OPENCL) +if(USE_OPENCL) message(INFO "USING OPENCL") find_package(OpenCL REQUIRED) include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS}) @@ -687,7 +687,7 @@ if(USE_OPENCV) if(OpenCV_FOUND) include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS}) list(APPEND Caffe2_DEPENDENCY_LIBS ${OpenCV_LIBS}) - if (MSVC AND USE_CUDA) + if(MSVC AND USE_CUDA) list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS ${OpenCV_LIBS}) endif() message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})") @@ -700,19 +700,19 @@ endif() # ---[ FFMPEG if(USE_FFMPEG) find_package(FFmpeg REQUIRED) - if (FFMPEG_FOUND) + if(FFMPEG_FOUND) message("Found FFMPEG/LibAV libraries") include_directories(SYSTEM ${FFMPEG_INCLUDE_DIR}) list(APPEND Caffe2_DEPENDENCY_LIBS ${FFMPEG_LIBRARIES}) - else () + else() message("Not compiling with FFmpeg. Suppress this warning with -DUSE_FFMPEG=OFF") caffe2_update_option(USE_FFMPEG OFF) - endif () + endif() endif() # ---[ Caffe2 depends on FP16 library for half-precision conversions -if (NOT TARGET fp16) - if (NOT DEFINED FP16_SOURCE_DIR) +if(NOT TARGET fp16) + if(NOT DEFINED FP16_SOURCE_DIR) set(FP16_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../third_party/FP16" CACHE STRING "FP16 source directory") endif() @@ -727,7 +727,7 @@ list(APPEND Caffe2_DEPENDENCY_LIBS fp16) # ---[ EIGEN # Due to license considerations, we will only use the MPL2 parts of Eigen. set(EIGEN_MPL2_ONLY 1) -if (USE_SYSTEM_EIGEN_INSTALL) +if(USE_SYSTEM_EIGEN_INSTALL) find_package(Eigen3) if(EIGEN3_FOUND) message(STATUS "Found system Eigen at " ${EIGEN3_INCLUDE_DIR}) @@ -749,7 +749,7 @@ if(BUILD_PYTHON) execute_process( COMMAND "which" "python" RESULT_VARIABLE _exitcode OUTPUT_VARIABLE _py_exe) if(${_exitcode} EQUAL 0) - if (NOT MSVC) + if(NOT MSVC) string(STRIP ${_py_exe} PYTHON_EXECUTABLE) endif() message(STATUS "Setting Python to ${PYTHON_EXECUTABLE}") @@ -790,7 +790,7 @@ if(BUILD_PYTHON) pycmd_no_exit(_py_lib _exitcode "from sysconfig import get_paths; print(get_paths()['stdlib'])") if("${_exitcode}" EQUAL 0 AND EXISTS "${_py_lib}" AND EXISTS "${_py_lib}") SET(PYTHON_LIBRARY "${_py_lib}") - if (MSVC) + if(MSVC) STRING(REPLACE "Lib" "libs" _py_static_lib ${_py_lib}) link_directories(${_py_static_lib}) endif() @@ -806,7 +806,7 @@ if(BUILD_PYTHON) # When building pytorch, we pass this in directly from setup.py, and # don't want to overwrite it because we trust python more than cmake - if (NUMPY_INCLUDE_DIR) + if(NUMPY_INCLUDE_DIR) set(NUMPY_FOUND ON) elseif(USE_NUMPY) find_package(NumPy) @@ -885,31 +885,31 @@ if(USE_OPENMP) SET(WITH_OPENMP ON CACHE BOOL "OpenMP support if available?") # macOS + GCC - IF (APPLE AND CMAKE_COMPILER_IS_GNUCC) + if(APPLE AND CMAKE_COMPILER_IS_GNUCC) EXEC_PROGRAM (uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION) STRING (REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION}) MESSAGE (STATUS "macOS Darwin version: ${DARWIN_VERSION}") - IF (DARWIN_VERSION GREATER 9) + if(DARWIN_VERSION GREATER 9) SET(APPLE_OPENMP_SUCKS 1) - ENDIF (DARWIN_VERSION GREATER 9) + endif(DARWIN_VERSION GREATER 9) EXECUTE_PROCESS (COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - IF (APPLE_OPENMP_SUCKS AND GCC_VERSION VERSION_LESS 4.6.2) + if(APPLE_OPENMP_SUCKS AND GCC_VERSION VERSION_LESS 4.6.2) MESSAGE(WARNING "Disabling OpenMP (unstable with this version of GCC). " "Install GCC >= 4.6.2 or change your OS to enable OpenMP.") add_compile_options(-Wno-unknown-pragmas) SET(WITH_OPENMP OFF CACHE BOOL "OpenMP support if available?" FORCE) - ENDIF() - ENDIF() + endif() + endif() - IF("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC" + if("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC" AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") MESSAGE(STATUS "Setting OpenMP flags for clang-cl") SET(OpenMP_CXX_FLAGS "-Xclang -fopenmp") SET(OpenMP_C_FLAGS "-Xclang -fopenmp") SET(CHECKED_OPENMP ON CACHE BOOL "already checked for OpenMP") SET(OPENMP_FOUND ON CACHE BOOL "OpenMP Support found") - if (NOT MKL_FOUND) + if(NOT MKL_FOUND) execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_version_output) string (REGEX REPLACE ".*InstalledDir: ([^\n]+).*" "\\1" CLANG_BINDIR ${clang_version_output}) @@ -926,24 +926,24 @@ if(USE_OPENMP) LIST(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::openmp) endif() - ENDIF() + endif() - IF (WITH_OPENMP AND NOT CHECKED_OPENMP) + if(WITH_OPENMP AND NOT CHECKED_OPENMP) FIND_PACKAGE(OpenMP QUIET) SET(CHECKED_OPENMP ON CACHE BOOL "already checked for OpenMP") # OPENMP_FOUND is not cached in FindOpenMP.cmake (all other variables are cached) # see https://github.com/Kitware/CMake/blob/master/Modules/FindOpenMP.cmake SET(OPENMP_FOUND ${OPENMP_FOUND} CACHE BOOL "OpenMP Support found") - ENDIF() + endif() if(OPENMP_FOUND) message(STATUS "Adding OpenMP CXX_FLAGS: " ${OpenMP_CXX_FLAGS}) - IF("${OpenMP_CXX_LIBRARIES}" STREQUAL "") + if("${OpenMP_CXX_LIBRARIES}" STREQUAL "") message(STATUS "No OpenMP library needs to be linked against") - ELSE() + else() message(STATUS "Will link against OpenMP libraries: ${OpenMP_CXX_LIBRARIES}") - ENDIF() + endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") else() @@ -959,18 +959,18 @@ if(ANDROID) endif() # ---[ LLVM -if (USE_LLVM) +if(USE_LLVM) message(STATUS "Looking for LLVM in ${USE_LLVM}") find_package(LLVM QUIET PATHS ${USE_LLVM} NO_DEFAULT_PATH) - if (LLVM_FOUND) + if(LLVM_FOUND) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") include_directories(${LLVM_INCLUDE_DIRS}) add_definitions(-DTORCH_ENABLE_LLVM ${LLVM_DEFINITIONS}) - endif (LLVM_FOUND) -endif (USE_LLVM) + endif(LLVM_FOUND) +endif(USE_LLVM) # ---[ CUDA if(USE_CUDA) @@ -1023,7 +1023,7 @@ if(USE_ROCM) message(INFO "Compiling with HIP for AMD.") caffe2_update_option(USE_ROCM ON) - if (USE_NCCL AND NOT USE_SYSTEM_NCCL) + if(USE_NCCL AND NOT USE_SYSTEM_NCCL) message(INFO "Forcing USE_SYSTEM_NCCL to ON since it's required by using RCCL") caffe2_update_option(USE_SYSTEM_NCCL ON) endif() @@ -1166,8 +1166,8 @@ if(USE_PROF) endif() endif() -if (USE_SNPE AND ANDROID) - if (SNPE_LOCATION AND SNPE_HEADERS) +if(USE_SNPE AND ANDROID) + if(SNPE_LOCATION AND SNPE_HEADERS) message(STATUS "Using SNPE location specified by -DSNPE_LOCATION: " ${SNPE_LOCATION}) message(STATUS "Using SNPE headers specified by -DSNPE_HEADERS: " ${SNPE_HEADERS}) include_directories(SYSTEM ${SNPE_HEADERS}) @@ -1179,29 +1179,29 @@ if (USE_SNPE AND ANDROID) endif() endif() -if (USE_METAL) - if (NOT IOS) +if(USE_METAL) + if(NOT IOS) message(WARNING "Metal is only used in ios builds.") caffe2_update_option(USE_METAL OFF) endif() endif() -if (USE_NNAPI AND NOT ANDROID) +if(USE_NNAPI AND NOT ANDROID) message(WARNING "NNApi is only used in android builds.") caffe2_update_option(USE_NNAPI OFF) endif() -if (NOT INTERN_BUILD_MOBILE AND BUILD_CAFFE2_OPS) - if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO) +if(NOT INTERN_BUILD_MOBILE AND BUILD_CAFFE2_OPS) + if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO) list(APPEND Caffe2_DEPENDENCY_LIBS aten_op_header_gen) - if (USE_CUDA) + if(USE_CUDA) list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS aten_op_header_gen) endif() include_directories(${PROJECT_BINARY_DIR}/caffe2/contrib/aten) endif() endif() -if (USE_ZSTD) +if(USE_ZSTD) list(APPEND Caffe2_DEPENDENCY_LIBS libzstd_static) include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/zstd/lib) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/zstd/build/cmake) @@ -1209,7 +1209,7 @@ if (USE_ZSTD) endif() # ---[ Onnx -if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) +if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) if(EXISTS "${CAFFE2_CUSTOM_PROTOC_EXECUTABLE}") set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${CAFFE2_CUSTOM_PROTOC_EXECUTABLE}) endif() @@ -1220,10 +1220,10 @@ if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) # If linking local protobuf, make sure ONNX has the same protobuf # patches as Caffe2 and Caffe proto. This forces some functions to # not be inline and instead route back to the statically-linked protobuf. - if (CAFFE2_LINK_LOCAL_PROTOBUF) + if(CAFFE2_LINK_LOCAL_PROTOBUF) set(ONNX_PROTO_POST_BUILD_SCRIPT ${PROJECT_SOURCE_DIR}/cmake/ProtoBufPatch.cmake) endif() - if (ONNX_ML) + if(ONNX_ML) add_definitions(-DONNX_ML=1) endif() # Add op schemas in "ai.onnx.pytorch" domain @@ -1236,7 +1236,7 @@ if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX) add_definitions(-DONNX_NAMESPACE=${ONNX_NAMESPACE}) # In mobile build we care about code size, and so we need drop # everything (e.g. checker, optimizer) in onnx but the pb definition. - if (ANDROID OR IOS) + if(ANDROID OR IOS) caffe2_interface_library(onnx_proto onnx_library) else() caffe2_interface_library(onnx onnx_library) @@ -1253,15 +1253,15 @@ function (add_onnx_tensorrt_subdir) set(CUDNN_INCLUDE_DIR "${CUDNN_INCLUDE_PATH}") set(CUDNN_LIBRARY "${CUDNN_LIBRARY_PATH}") set(CMAKE_VERSION_ORIG "{CMAKE_VERSION}") - if (FIND_CUDA_MODULE_DEPRECATED) + if(FIND_CUDA_MODULE_DEPRECATED) # TODO: this WAR is for https://github.com/pytorch/pytorch/issues/18524 set(CMAKE_VERSION "3.9.0") endif() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../third_party/onnx-tensorrt EXCLUDE_FROM_ALL) set(CMAKE_VERSION "{CMAKE_VERSION_ORIG}") endfunction() -if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO) - if (USE_TENSORRT) +if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO) + if(USE_TENSORRT) set(CMAKE_CUDA_COMPILER ${CUDA_NVCC_EXECUTABLE}) add_onnx_tensorrt_subdir() include_directories("${CMAKE_CURRENT_LIST_DIR}/../third_party/onnx-tensorrt") @@ -1272,7 +1272,7 @@ if (CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO) endif() # --[ ATen checks -if (NOT INTERN_BUILD_MOBILE) +if(NOT INTERN_BUILD_MOBILE) set(TORCH_CUDA_ARCH_LIST $ENV{TORCH_CUDA_ARCH_LIST}) set(TORCH_NVCC_FLAGS $ENV{TORCH_NVCC_FLAGS}) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) @@ -1290,63 +1290,63 @@ if (NOT INTERN_BUILD_MOBILE) # this, but since FindCUDA upstream is subsumed by first-class support # for CUDA language, it seemed not worth fixing. - IF (MSVC) + if(MSVC) # we want to respect the standard, and we are bored of those **** . ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE=1) # skip unwanted includes from windows.h ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN) LIST(APPEND CUDA_NVCC_FLAGS "-Xcompiler /wd4819 -Xcompiler /wd4503 -Xcompiler /wd4190 -Xcompiler /wd4244 -Xcompiler /wd4251 -Xcompiler /wd4275 -Xcompiler /wd4522") - ENDIF() + endif() - IF (NOT MSVC) - IF (CMAKE_VERSION VERSION_LESS "3.1") + if(NOT MSVC) + if(CMAKE_VERSION VERSION_LESS "3.1") SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}") - ELSE () + else() SET(CMAKE_C_STANDARD 11) - ENDIF () - ENDIF() + endif() + endif() LIST(APPEND CUDA_NVCC_FLAGS -Wno-deprecated-gpu-targets) LIST(APPEND CUDA_NVCC_FLAGS --expt-extended-lambda) - if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") SET(CMAKE_CXX_STANDARD 14) endif() LIST(APPEND CUDA_NVCC_FLAGS ${TORCH_NVCC_FLAGS}) LIST(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA}) - IF (CMAKE_POSITION_INDEPENDENT_CODE AND NOT MSVC) + if(CMAKE_POSITION_INDEPENDENT_CODE AND NOT MSVC) LIST(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-fPIC") - ENDIF() + endif() - IF (CUDA_HAS_FP16 OR NOT ${CUDA_VERSION} LESS 7.5) + if(CUDA_HAS_FP16 OR NOT ${CUDA_VERSION} LESS 7.5) MESSAGE(STATUS "Found CUDA with FP16 support, compiling with torch.cuda.HalfTensor") LIST(APPEND CUDA_NVCC_FLAGS "-DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__") add_compile_options(-DCUDA_HAS_FP16=1) - ELSE() + else() MESSAGE(STATUS "Could not find CUDA with FP16 support, compiling without torch.CudaHalfTensor") - ENDIF() + endif() STRING(APPEND CMAKE_C_FLAGS_RELEASE " -DNDEBUG") STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG") - IF (NOT GENERATOR_IS_MULTI_CONFIG) - IF (${CMAKE_BUILD_TYPE} STREQUAL "Release") + if(NOT GENERATOR_IS_MULTI_CONFIG) + if(${CMAKE_BUILD_TYPE} STREQUAL "Release") MESSAGE(STATUS "Adding -DNDEBUG to compile flags") STRING(APPEND CMAKE_C_FLAGS " -DNDEBUG") STRING(APPEND CMAKE_CXX_FLAGS " -DNDEBUG") - ELSE() + else() MESSAGE(STATUS "Removing -DNDEBUG from compile flags") STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS "" ${CMAKE_C_FLAGS}) STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_CXX_FLAGS "" ${CMAKE_CXX_FLAGS}) - ENDIF() - ENDIF() + endif() + endif() STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS_DEBUG "" ${CMAKE_C_FLAGS_DEBUG}) STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_CXX_FLAGS_DEBUG "" ${CMAKE_CXX_FLAGS_DEBUG}) SET(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF) FIND_PACKAGE(MAGMA) - IF (USE_CUDA AND MAGMA_FOUND) + if(USE_CUDA AND MAGMA_FOUND) INCLUDE_DIRECTORIES(SYSTEM ${MAGMA_INCLUDE_DIR}) SET(CMAKE_REQUIRED_INCLUDES "${MAGMA_INCLUDE_DIR};${CUDA_INCLUDE_DIRS}") INCLUDE(CheckPrototypeDefinition) @@ -1355,50 +1355,50 @@ if (NOT INTERN_BUILD_MOBILE) "0" "magma.h" MAGMA_V2) - IF (MAGMA_V2) + if(MAGMA_V2) add_definitions(-DMAGMA_V2) - ENDIF (MAGMA_V2) + endif(MAGMA_V2) SET(USE_MAGMA 1) MESSAGE(STATUS "Compiling with MAGMA support") MESSAGE(STATUS "MAGMA INCLUDE DIRECTORIES: ${MAGMA_INCLUDE_DIR}") MESSAGE(STATUS "MAGMA LIBRARIES: ${MAGMA_LIBRARIES}") MESSAGE(STATUS "MAGMA V2 check: ${MAGMA_V2}") - ELSE() + else() MESSAGE(STATUS "MAGMA not found. Compiling without MAGMA support") - ENDIF() + endif() # ARM specific flags FIND_PACKAGE(ARM) - IF (ASIMD_FOUND) + if(ASIMD_FOUND) MESSAGE(STATUS "asimd/Neon found with compiler flag : -D__NEON__") add_compile_options(-D__NEON__) - ELSEIF (NEON_FOUND) + elseif(NEON_FOUND) MESSAGE(STATUS "Neon found with compiler flag : -mfpu=neon -D__NEON__") add_compile_options(-mfpu=neon -D__NEON__) - ENDIF () - IF (CORTEXA8_FOUND) + endif() + if(CORTEXA8_FOUND) MESSAGE(STATUS "Cortex-A8 Found with compiler flag : -mcpu=cortex-a8") add_compile_options(-mcpu=cortex-a8 -fprefetch-loop-arrays) - ENDIF () - IF (CORTEXA9_FOUND) + endif() + if(CORTEXA9_FOUND) MESSAGE(STATUS "Cortex-A9 Found with compiler flag : -mcpu=cortex-a9") add_compile_options(-mcpu=cortex-a9) - ENDIF() + endif() CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H) # Check for a cpuid intrinsic - IF (HAVE_CPUID_H) + if(HAVE_CPUID_H) CHECK_C_SOURCE_COMPILES("#include int main() { unsigned int eax, ebx, ecx, edx; return __get_cpuid(0, &eax, &ebx, &ecx, &edx); }" HAVE_GCC_GET_CPUID) - ENDIF() - IF (HAVE_GCC_GET_CPUID) + endif() + if(HAVE_GCC_GET_CPUID) add_compile_options(-DHAVE_GCC_GET_CPUID) - ENDIF() + endif() CHECK_C_SOURCE_COMPILES("#include static inline void cpuid(uint32_t *eax, uint32_t *ebx, @@ -1414,124 +1414,124 @@ if (NOT INTERN_BUILD_MOBILE) return 0; }" NO_GCC_EBX_FPIC_BUG) - IF (NOT NO_GCC_EBX_FPIC_BUG) + if(NOT NO_GCC_EBX_FPIC_BUG) add_compile_options(-DUSE_GCC_GET_CPUID) - ENDIF() + endif() FIND_PACKAGE(AVX) # checks AVX and AVX2 # we don't set -mavx and -mavx2 flags globally, but only for specific files # however, we want to enable the AVX codepaths, so we still need to # add USE_AVX and USE_AVX2 macro defines - IF (C_AVX_FOUND) + if(C_AVX_FOUND) MESSAGE(STATUS "AVX compiler support found") add_compile_options(-DUSE_AVX) - ENDIF() - IF (C_AVX2_FOUND) + endif() + if(C_AVX2_FOUND) MESSAGE(STATUS "AVX2 compiler support found") add_compile_options(-DUSE_AVX2) - ENDIF() + endif() - IF (WIN32 AND NOT CYGWIN) + if(WIN32 AND NOT CYGWIN) SET(BLAS_INSTALL_LIBRARIES "OFF" CACHE BOOL "Copy the required BLAS DLLs into the TH install dirs") - ENDIF() + endif() FIND_PACKAGE(LAPACK) - IF (LAPACK_FOUND) + if(LAPACK_FOUND) SET(USE_LAPACK 1) - ENDIF() + endif() - if (NOT USE_CUDA) + if(NOT USE_CUDA) message("disabling CUDA because NOT USE_CUDA is set") SET(AT_CUDA_ENABLED 0) else() SET(AT_CUDA_ENABLED 1) endif() - IF (NOT USE_CUDNN) + if(NOT USE_CUDNN) MESSAGE(STATUS "USE_CUDNN is set to 0. Compiling without cuDNN support") set(AT_CUDNN_ENABLED 0) - ELSEIF (NOT CUDNN_FOUND) + elseif(NOT CUDNN_FOUND) MESSAGE(WARNING "CuDNN not found. Compiling without CuDNN support") set(AT_CUDNN_ENABLED 0) - ELSE() + else() include_directories(SYSTEM ${CUDNN_INCLUDE_PATH}) set(AT_CUDNN_ENABLED 1) - ENDIF() + endif() - IF (NOT USE_ROCM) + if(NOT USE_ROCM) message("disabling ROCM because NOT USE_ROCM is set") MESSAGE(STATUS "MIOpen not found. Compiling without MIOpen support") set(AT_ROCM_ENABLED 0) - ELSE() + else() INCLUDE_DIRECTORIES(BEFORE ${MIOPEN_INCLUDE_DIRS}) set(AT_ROCM_ENABLED 1) - ENDIF() + endif() SET(AT_MKLDNN_ENABLED 0) SET(CAFFE2_USE_MKLDNN OFF) - IF (USE_MKLDNN) + if(USE_MKLDNN) INCLUDE(${CMAKE_CURRENT_LIST_DIR}/public/mkldnn.cmake) - IF(MKLDNN_FOUND) + if(MKLDNN_FOUND) SET(AT_MKLDNN_ENABLED 1) INCLUDE_DIRECTORIES(AFTER SYSTEM ${MKLDNN_INCLUDE_DIR}) - IF(BUILD_CAFFE2_OPS) + if(BUILD_CAFFE2_OPS) SET(CAFFE2_USE_MKLDNN ON) LIST(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS caffe2::mkldnn) - ENDIF(BUILD_CAFFE2_OPS) - ELSE() + endif(BUILD_CAFFE2_OPS) + else() MESSAGE(WARNING "MKLDNN could not be found.") - ENDIF() - ELSE() + endif() + else() MESSAGE("disabling MKLDNN because USE_MKLDNN is not set") - ENDIF() + endif() - IF(UNIX AND NOT APPLE) + if(UNIX AND NOT APPLE) INCLUDE(CheckLibraryExists) # https://github.com/libgit2/libgit2/issues/2128#issuecomment-35649830 CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT) - IF(NEED_LIBRT) + if(NEED_LIBRT) list(APPEND Caffe2_DEPENDENCY_LIBS rt) SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt) - ENDIF(NEED_LIBRT) - ENDIF(UNIX AND NOT APPLE) + endif(NEED_LIBRT) + endif(UNIX AND NOT APPLE) - IF(UNIX) + if(UNIX) SET(CMAKE_EXTRA_INCLUDE_FILES "sys/mman.h") CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP) - IF(HAVE_MMAP) + if(HAVE_MMAP) ADD_DEFINITIONS(-DHAVE_MMAP=1) - ENDIF(HAVE_MMAP) + endif(HAVE_MMAP) # done for lseek: https://www.gnu.org/software/libc/manual/html_node/File-Position-Primitive.html ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) CHECK_FUNCTION_EXISTS(shm_open HAVE_SHM_OPEN) - IF(HAVE_SHM_OPEN) + if(HAVE_SHM_OPEN) ADD_DEFINITIONS(-DHAVE_SHM_OPEN=1) - ENDIF(HAVE_SHM_OPEN) + endif(HAVE_SHM_OPEN) CHECK_FUNCTION_EXISTS(shm_unlink HAVE_SHM_UNLINK) - IF(HAVE_SHM_UNLINK) + if(HAVE_SHM_UNLINK) ADD_DEFINITIONS(-DHAVE_SHM_UNLINK=1) - ENDIF(HAVE_SHM_UNLINK) + endif(HAVE_SHM_UNLINK) CHECK_FUNCTION_EXISTS(malloc_usable_size HAVE_MALLOC_USABLE_SIZE) - IF(HAVE_MALLOC_USABLE_SIZE) + if(HAVE_MALLOC_USABLE_SIZE) ADD_DEFINITIONS(-DHAVE_MALLOC_USABLE_SIZE=1) - ENDIF(HAVE_MALLOC_USABLE_SIZE) - ENDIF(UNIX) + endif(HAVE_MALLOC_USABLE_SIZE) + endif(UNIX) ADD_DEFINITIONS(-DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS) # Is __thread supported? - IF(NOT MSVC) + if(NOT MSVC) CHECK_C_SOURCE_COMPILES("static __thread int x = 1; int main() { return x; }" C_HAS_THREAD) - ELSE(NOT MSVC) + else(NOT MSVC) CHECK_C_SOURCE_COMPILES("static __declspec( thread ) int x = 1; int main() { return x; }" C_HAS_THREAD) - ENDIF(NOT MSVC) - IF(NOT C_HAS_THREAD) + endif(NOT MSVC) + if(NOT C_HAS_THREAD) MESSAGE(STATUS "Warning: __thread is not supported, generating thread-unsafe code") - ELSE(NOT C_HAS_THREAD) + else(NOT C_HAS_THREAD) add_compile_options(-DTH_HAVE_THREAD) - ENDIF(NOT C_HAS_THREAD) + endif(NOT C_HAS_THREAD) endif() # diff --git a/cmake/External/nccl.cmake b/cmake/External/nccl.cmake index f7f7d2194ef1..bf1a36e8e145 100644 --- a/cmake/External/nccl.cmake +++ b/cmake/External/nccl.cmake @@ -1,10 +1,10 @@ -if (NOT __NCCL_INCLUDED) +if(NOT __NCCL_INCLUDED) set(__NCCL_INCLUDED TRUE) - if (USE_SYSTEM_NCCL) + if(USE_SYSTEM_NCCL) # NCCL_ROOT, NCCL_LIB_DIR, NCCL_INCLUDE_DIR will be accounted in the following line. find_package(NCCL REQUIRED) - if (NCCL_FOUND) + if(NCCL_FOUND) add_library(__caffe2_nccl INTERFACE) target_link_libraries(__caffe2_nccl INTERFACE ${NCCL_LIBRARIES}) target_include_directories(__caffe2_nccl INTERFACE ${NCCL_INCLUDE_DIRS}) diff --git a/cmake/External/nnpack.cmake b/cmake/External/nnpack.cmake index f35c95542563..fcbc08f4fb53 100644 --- a/cmake/External/nnpack.cmake +++ b/cmake/External/nnpack.cmake @@ -1,9 +1,9 @@ -if (__NNPACK_INCLUDED) +if(__NNPACK_INCLUDED) return() endif() set(__NNPACK_INCLUDED TRUE) -if (NOT USE_NNPACK) +if(NOT USE_NNPACK) return() endif() @@ -17,7 +17,7 @@ endif() # (1) MSVC - unsupported ############################################################################## -if (MSVC) +if(MSVC) message(WARNING "NNPACK not supported on MSVC yet. Turn this warning off by USE_NNPACK=OFF.") set(USE_NNPACK OFF) return() @@ -40,7 +40,7 @@ endif() # (3) Android, iOS, Linux, macOS - supported ############################################################################## -if (ANDROID OR IOS OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") +if(ANDROID OR IOS OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") message(STATUS "Brace yourself, we are building NNPACK") set(CAFFE2_THIRD_PARTY_ROOT ${PROJECT_SOURCE_DIR}/third_party) @@ -48,7 +48,7 @@ if (ANDROID OR IOS OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NA set(PYTHON_SIX_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/python-six" CACHE STRING "six (Python package) source directory") set(PYTHON_ENUM_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/python-enum" CACHE STRING "enum34 (Python package) source directory") set(PYTHON_PEACHPY_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/python-peachpy" CACHE STRING "PeachPy (Python package) source directory") - if (NOT DEFINED CPUINFO_SOURCE_DIR) + if(NOT DEFINED CPUINFO_SOURCE_DIR) set(CPUINFO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/cpuinfo" CACHE STRING "cpuinfo source directory") endif() set(NNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/NNPACK" CACHE STRING "NNPACK source directory") diff --git a/cmake/External/rccl.cmake b/cmake/External/rccl.cmake index bc9265d4a3cc..d7d3db68b1f1 100644 --- a/cmake/External/rccl.cmake +++ b/cmake/External/rccl.cmake @@ -1,10 +1,10 @@ -if (NOT __NCCL_INCLUDED) +if(NOT __NCCL_INCLUDED) set(__NCCL_INCLUDED TRUE) - if (USE_SYSTEM_NCCL) + if(USE_SYSTEM_NCCL) # NCCL_ROOT, NCCL_LIB_DIR, NCCL_INCLUDE_DIR will be accounted in the following line. find_package(RCCL REQUIRED) - if (RCCL_FOUND) + if(RCCL_FOUND) message (STATUS "RCCL Found!") add_library(__caffe2_nccl INTERFACE) target_link_libraries(__caffe2_nccl INTERFACE ${PYTORCH_RCCL_LIBRARIES}) diff --git a/cmake/MiscCheck.cmake b/cmake/MiscCheck.cmake index 4bb1431d597a..e529557aa550 100644 --- a/cmake/MiscCheck.cmake +++ b/cmake/MiscCheck.cmake @@ -1,4 +1,4 @@ -if (UNIX) +if(UNIX) # prevent Unknown CMake command "check_function_exists". include(CheckFunctionExists) endif() @@ -37,7 +37,7 @@ if(EXISTS "/etc/os-release") endif() endif() -if (NOT INTERN_BUILD_MOBILE) +if(NOT INTERN_BUILD_MOBILE) # ---[ Check that our programs run. This is different from the native CMake # compiler check, which just tests if the program compiles and links. This is # important because with ASAN you might need to help the compiled library find @@ -46,7 +46,7 @@ if (NOT INTERN_BUILD_MOBILE) CHECK_C_SOURCE_RUNS(" int main() { return 0; } " COMPILER_WORKS) - if (NOT COMPILER_WORKS) + if(NOT COMPILER_WORKS) # Force cmake to retest next time around unset(COMPILER_WORKS CACHE) message(FATAL_ERROR @@ -59,7 +59,7 @@ if (NOT INTERN_BUILD_MOBILE) cmake_pop_check_state() endif() -if (NOT INTERN_BUILD_MOBILE) +if(NOT INTERN_BUILD_MOBILE) # ---[ Check if certain std functions are supported. Sometimes # _GLIBCXX_USE_C99 macro is not defined and some functions are missing. cmake_push_check_state(RESET) @@ -75,7 +75,7 @@ if (NOT INTERN_BUILD_MOBILE) return 0; }" SUPPORT_GLIBCXX_USE_C99) - if (NOT SUPPORT_GLIBCXX_USE_C99) + if(NOT SUPPORT_GLIBCXX_USE_C99) # Force cmake to retest next time around unset(SUPPORT_GLIBCXX_USE_C99 CACHE) message(FATAL_ERROR @@ -103,7 +103,7 @@ CHECK_CXX_SOURCE_COMPILES( } }" CAFFE2_EXCEPTION_PTR_SUPPORTED) -if (CAFFE2_EXCEPTION_PTR_SUPPORTED) +if(CAFFE2_EXCEPTION_PTR_SUPPORTED) message(STATUS "std::exception_ptr is supported.") set(CAFFE2_USE_EXCEPTION_PTR 1) else() @@ -132,9 +132,9 @@ endif() cmake_pop_check_state() # ---[ Check if the compiler has AVX/AVX2 support. We only check AVX2. -if (NOT INTERN_BUILD_MOBILE) +if(NOT INTERN_BUILD_MOBILE) cmake_push_check_state(RESET) - if (MSVC) + if(MSVC) set(CMAKE_REQUIRED_FLAGS "/arch:AVX2") else() set(CMAKE_REQUIRED_FLAGS "-mavx2") @@ -150,7 +150,7 @@ if (NOT INTERN_BUILD_MOBILE) _mm256_extract_epi64(x, 0); // we rely on this in our AVX2 code return 0; }" CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) - if (CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) + if(CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS) message(STATUS "Current compiler supports avx2 extension. Will build perfkernels.") # Also see CMakeLists.txt under caffe2/perfkernels. set(CAFFE2_PERF_WITH_AVX 1) @@ -160,7 +160,7 @@ if (NOT INTERN_BUILD_MOBILE) endif() # ---[ Check if the compiler has AVX512 support. cmake_push_check_state(RESET) -if (MSVC) +if(MSVC) # We could've used MSVC's hidden option /arch:AVX512 that defines __AVX512F__, # __AVX512DQ__, and __AVX512VL__, and /arch:AVX512F that defines __AVX512F__. # But, we chose not to do that not to rely on hidden options. @@ -194,7 +194,7 @@ CHECK_CXX_SOURCE_COMPILES( __mmask16 m = _mm512_cmp_epi32_mask(a, a, _MM_CMPINT_EQ); __m512i r = _mm512_andnot_si512(a, a); }" CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS) -if (CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS) +if(CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS) message(STATUS "Current compiler supports avx512f extension. Will build fbgemm.") # Also see CMakeLists.txt under caffe2/perfkernels. set(CAFFE2_PERF_WITH_AVX512 1) @@ -204,7 +204,7 @@ cmake_pop_check_state() # ---[ Checks if compiler supports -fvisibility=hidden check_cxx_compiler_flag("-fvisibility=hidden" COMPILER_SUPPORTS_HIDDEN_VISIBILITY) check_cxx_compiler_flag("-fvisibility-inlines-hidden" COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY) -if (${COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY}) +if(${COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY}) set(CAFFE2_VISIBILITY_FLAG "-fvisibility-inlines-hidden") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAFFE2_VISIBILITY_FLAG}") endif() @@ -214,7 +214,7 @@ endif() # -table. We need this to get symbols when generating backtrace at # -runtime. check_cxx_compiler_flag("-rdynamic" COMPILER_SUPPORTS_RDYNAMIC) -if (${COMPILER_SUPPORTS_RDYNAMIC}) +if(${COMPILER_SUPPORTS_RDYNAMIC}) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -rdynamic") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic") endif() @@ -225,7 +225,7 @@ endif() # a third party library (like Protobuf), mention it in the comment as # "THIRD_PARTY_NAME related" # From https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/ -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") add_compile_options( ########################################## # Protobuf related. Cannot remove. @@ -306,7 +306,7 @@ endif() # Also, we will turn off deprecated-declarations # due to protobuf. -if (IOS) +if(IOS) add_definitions("-mfpu=neon-fp16") add_definitions("-Wno-deprecated-declarations") endif() @@ -314,7 +314,7 @@ endif() # ---[ If we use asan, turn on the flags. # TODO: This only works with new style gcc and clang (not the old -faddress-sanitizer). # Change if necessary on old platforms. -if (USE_ASAN) +if(USE_ASAN) set(CAFFE2_ASAN_FLAG "-fsanitize=address -fPIE -pie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CAFFE2_ASAN_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAFFE2_ASAN_FLAG}") @@ -323,7 +323,7 @@ if (USE_ASAN) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CAFFE2_ASAN_FLAG}") endif() -if (USE_TSAN) +if(USE_TSAN) set(CAFFE2_TSAN_FLAG "-fsanitize=thread -fPIE -pie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CAFFE2_TSAN_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAFFE2_TSAN_FLAG}") @@ -335,9 +335,9 @@ endif() # ---[ Create CAFFE2_BUILD_SHARED_LIBS for macros.h.in usage. set(CAFFE2_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) -if (USE_NATIVE_ARCH) +if(USE_NATIVE_ARCH) check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) - if (COMPILER_SUPPORTS_MARCH_NATIVE) + if(COMPILER_SUPPORTS_MARCH_NATIVE) add_definitions("-march=native") else() message( diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake index 5629f0334427..973b478f6ed2 100644 --- a/cmake/ProtoBuf.cmake +++ b/cmake/ProtoBuf.cmake @@ -5,12 +5,12 @@ macro(custom_protobuf_find) option(protobuf_BUILD_TESTS "" OFF) option(protobuf_BUILD_EXAMPLES "" OFF) option(protobuf_WITH_ZLIB "" OFF) - if (APPLE) + if(APPLE) # Protobuf generated files triggers a deprecated atomic operation warning # so we turn it off here. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") endif() - if (${CAFFE2_LINK_LOCAL_PROTOBUF}) + if(${CAFFE2_LINK_LOCAL_PROTOBUF}) # If we are going to link protobuf locally, we will need to turn off # shared libs build for protobuf. option(protobuf_BUILD_SHARED_LIBS "" OFF) @@ -22,15 +22,15 @@ macro(custom_protobuf_find) # We will make sure that protobuf and caffe2 uses the same msvc runtime. option(protobuf_MSVC_STATIC_RUNTIME "" ${CAFFE2_USE_MSVC_STATIC_RUNTIME}) - if (${CAFFE2_LINK_LOCAL_PROTOBUF}) + if(${CAFFE2_LINK_LOCAL_PROTOBUF}) set(__caffe2_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS}) set(__caffe2_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF) set(BUILD_SHARED_LIBS OFF) - if (${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) + if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") endif() - if (${COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY}) + if(${COMPILER_SUPPORTS_HIDDEN_INLINE_VISIBILITY}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden") endif() endif() @@ -38,7 +38,7 @@ macro(custom_protobuf_find) set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) set(CMAKE_POSITION_INDEPENDENT_CODE ON) - if (MSVC) + if(MSVC) if(MSVC_Z7_OVERRIDE) foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE @@ -56,7 +56,7 @@ macro(custom_protobuf_find) set(CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE}) - if (${CAFFE2_LINK_LOCAL_PROTOBUF}) + if(${CAFFE2_LINK_LOCAL_PROTOBUF}) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${__caffe2_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS}) set(BUILD_SHARED_LIBS ON) set(CMAKE_CXX_FLAGS ${__caffe2_CMAKE_CXX_FLAGS}) @@ -64,13 +64,13 @@ macro(custom_protobuf_find) # Protobuf "namespaced" target is only added post protobuf 3.5.1. As a # result, for older versions, we will manually add alias. - if (NOT TARGET protobuf::libprotobuf) + if(NOT TARGET protobuf::libprotobuf) add_library(protobuf::libprotobuf ALIAS libprotobuf) add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite) # There is link error when cross compiling protoc on mobile: # https://github.com/protocolbuffers/protobuf/issues/2719 # And protoc is very unlikely needed for mobile builds. - if (NOT (ANDROID OR IOS)) + if(NOT (ANDROID OR IOS)) add_executable(protobuf::protoc ALIAS protoc) endif() endif() @@ -79,8 +79,8 @@ endmacro() # Main entry for protobuf. If we are building on Android, iOS or we have hard # coded BUILD_CUSTOM_PROTOBUF, we will hard code the use of custom protobuf # in the submodule. -if (ANDROID OR IOS) - if (NOT ${BUILD_CUSTOM_PROTOBUF}) +if(ANDROID OR IOS) + if(NOT ${BUILD_CUSTOM_PROTOBUF}) message(WARNING "For Android and iOS cross compilation, I am automatically using " "custom protobuf under third party. Note that this behavior may " @@ -94,14 +94,14 @@ if (ANDROID OR IOS) set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "" FORCE) custom_protobuf_find() set(protobuf_BUILD_PROTOC_BINARIES ${__caffe2_protobuf_BUILD_PROTOC_BINARIES} CACHE BOOL "" FORCE) -elseif (BUILD_CUSTOM_PROTOBUF) +elseif(BUILD_CUSTOM_PROTOBUF) message(STATUS "Building using own protobuf under third_party per request.") custom_protobuf_find() else() include(cmake/public/protobuf.cmake) endif() -if ((NOT TARGET protobuf::libprotobuf) AND (NOT TARGET protobuf::libprotobuf-lite)) +if((NOT TARGET protobuf::libprotobuf) AND (NOT TARGET protobuf::libprotobuf-lite)) message(WARNING "Protobuf cannot be found. Caffe2 will automatically switch to use " "own protobuf under third_party. Note that this behavior may change in " @@ -124,7 +124,7 @@ include_directories(BEFORE SYSTEM ${__tmp}) # If Protobuf_VERSION is known (true in most cases, false if we are building # local protobuf), then we will add a protobuf version check in # Caffe2Config.cmake.in. -if (DEFINED ${Protobuf_VERSION}) +if(DEFINED ${Protobuf_VERSION}) set(CAFFE2_KNOWN_PROTOBUF_VERSION TRUE) else() set(CAFFE2_KNOWN_PROTOBUF_VERSION FALSE) @@ -176,7 +176,7 @@ function(caffe2_protobuf_generate_cpp_py srcs_var hdrs_var python_var) # directory and are building it as part of the Caffe2 build. If # points to an existing path, it is a no-op. - if (${CAFFE2_LINK_LOCAL_PROTOBUF}) + if(${CAFFE2_LINK_LOCAL_PROTOBUF}) # We need to rewrite the pb.h files to route GetEmptyStringAlreadyInited # through our wrapper in proto_utils so the memory location test # is correct. diff --git a/cmake/ProtoBufPatch.cmake b/cmake/ProtoBufPatch.cmake index d36504e78c67..4bf1d734aefe 100644 --- a/cmake/ProtoBufPatch.cmake +++ b/cmake/ProtoBufPatch.cmake @@ -46,7 +46,7 @@ foreach(ns ${NAMESPACES}) set(search "namespace ${ns} {") string(LENGTH "${search}" search_len) string(FIND "${content}" "${search}" pos) - if (${pos} GREATER -1) + if(${pos} GREATER -1) math(EXPR pos "${pos}+${search_len}") string(SUBSTRING "${content}" 0 ${pos} content_pre) string(SUBSTRING "${content}" ${pos} -1 content_post) @@ -63,7 +63,7 @@ endforeach() # a link error that claims that the vftable is not found. Luckily, we # could move the definition into the source file to solve the problem. list(LENGTH NAMESPACES ns_count) -if ("${FILENAME}" MATCHES ".pb.h" AND ns_count EQUAL 1) +if("${FILENAME}" MATCHES ".pb.h" AND ns_count EQUAL 1) string(REPLACE ".pb.h" ".pb.cc" SOURCE_FILENAME ${FILENAME}) file(READ ${SOURCE_FILENAME} content_cc_origin) diff --git a/cmake/TorchConfig.cmake.in b/cmake/TorchConfig.cmake.in index 7716ccc106f2..66c4a43787b8 100644 --- a/cmake/TorchConfig.cmake.in +++ b/cmake/TorchConfig.cmake.in @@ -16,7 +16,7 @@ include(FindPackageHandleStandardArgs) -if (DEFINED ENV{TORCH_INSTALL_PREFIX}) +if(DEFINED ENV{TORCH_INSTALL_PREFIX}) set(TORCH_INSTALL_PREFIX $ENV{TORCH_INSTALL_PREFIX}) else() # Assume we are in /share/cmake/Torch/TorchConfig.cmake @@ -25,7 +25,7 @@ else() endif() # Include directories. -if (EXISTS "${TORCH_INSTALL_PREFIX}/include") +if(EXISTS "${TORCH_INSTALL_PREFIX}/include") set(TORCH_INCLUDE_DIRS ${TORCH_INSTALL_PREFIX}/include ${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include) @@ -36,7 +36,7 @@ else() endif() # Library dependencies. -if (@BUILD_SHARED_LIBS@) +if(@BUILD_SHARED_LIBS@) find_package(Caffe2 REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../Caffe2) set(TORCH_LIBRARIES torch ${Caffe2_MAIN_LIBS}) else() @@ -50,26 +50,26 @@ list(APPEND TORCH_LIBRARIES ${C10_LIBRARY}) # We need manually add dependent libraries when they are not linked into the # shared library. # TODO: this list might be incomplete. -if (NOT @BUILD_SHARED_LIBS@) +if(NOT @BUILD_SHARED_LIBS@) find_library(TORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib") list(APPEND TORCH_LIBRARIES ${TORCH_CPU_LIBRARY}) - if (@USE_NNPACK@) + if(@USE_NNPACK@) find_library(NNPACK_LIBRARY nnpack PATHS "${TORCH_INSTALL_PREFIX}/lib") list(APPEND TORCH_LIBRARIES ${NNPACK_LIBRARY}) endif() - if (@USE_PYTORCH_QNNPACK@) + if(@USE_PYTORCH_QNNPACK@) find_library(PYTORCH_QNNPACK_LIBRARY pytorch_qnnpack PATHS "${TORCH_INSTALL_PREFIX}/lib") list(APPEND TORCH_LIBRARIES ${PYTORCH_QNNPACK_LIBRARY}) endif() - if (@USE_XNNPACK@) + if(@USE_XNNPACK@) find_library(XNNPACK_LIBRARY XNNPACK PATHS "${TORCH_INSTALL_PREFIX}/lib") list(APPEND TORCH_LIBRARIES ${XNNPACK_LIBRARY}) endif() - if (@INTERN_USE_EIGEN_BLAS@) + if(@INTERN_USE_EIGEN_BLAS@) find_library(EIGEN_BLAS_LIBRARY eigen_blas PATHS "${TORCH_INSTALL_PREFIX}/lib") list(APPEND TORCH_LIBRARIES ${EIGEN_BLAS_LIBRARY}) endif() @@ -81,10 +81,10 @@ if (NOT @BUILD_SHARED_LIBS@) list(APPEND TORCH_LIBRARIES ${CLOG_LIBRARY}) endif() -if (@USE_CUDA@) +if(@USE_CUDA@) if(MSVC) set(NVTOOLEXT_HOME "C:/Program Files/NVIDIA Corporation/NvToolsExt") - if ($ENV{NVTOOLEXT_HOME}) + if($ENV{NVTOOLEXT_HOME}) set(NVTOOLEXT_HOME $ENV{NVTOOLEXT_HOME}) endif() set(TORCH_CUDA_LIBRARIES @@ -113,7 +113,7 @@ if (@USE_CUDA@) endif() # When we build libtorch with the old GCC ABI, dependent libraries must too. -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@") endif() @@ -123,7 +123,7 @@ set_target_properties(torch PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${TORCH_INCLUDE_DIRS}" CXX_STANDARD 14 ) -if (TORCH_CXX_FLAGS) +if(TORCH_CXX_FLAGS) set_property(TARGET torch PROPERTY INTERFACE_COMPILE_OPTIONS "${TORCH_CXX_FLAGS}") endif() diff --git a/cmake/TorchConfigVersion.cmake.in b/cmake/TorchConfigVersion.cmake.in index d9966d690dd4..2f0d2f073196 100644 --- a/cmake/TorchConfigVersion.cmake.in +++ b/cmake/TorchConfigVersion.cmake.in @@ -5,7 +5,7 @@ if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_EXACT TRUE) endif() endif() diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index b0f931f11c9b..ecef3b82e8eb 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -142,7 +142,7 @@ endfunction() # function(dedent outvar text) # Use PYTHON_EXECUTABLE if it is defined, otherwise default to python - if ("${PYTHON_EXECUTABLE}" STREQUAL "") + if("${PYTHON_EXECUTABLE}" STREQUAL "") set(_python_exe "python") else() set(_python_exe "${PYTHON_EXECUTABLE}") @@ -167,7 +167,7 @@ endfunction() function(pycmd_no_exit outvar exitcode cmd) # Use PYTHON_EXECUTABLE if it is defined, otherwise default to python - if ("${PYTHON_EXECUTABLE}" STREQUAL "") + if("${PYTHON_EXECUTABLE}" STREQUAL "") set(_python_exe "python") else() set(_python_exe "${PYTHON_EXECUTABLE}") @@ -232,7 +232,7 @@ function(print_target_properties tgt) foreach (prop ${CMAKE_PROPERTY_LIST}) string(REPLACE "" "${CMAKE_BUILD_TYPE}" prop ${prop}) get_property(propval TARGET ${tgt} PROPERTY ${prop} SET) - if (propval) + if(propval) get_target_property(propval ${tgt} ${prop}) message ("${tgt} ${prop} = ${propval}") endif() diff --git a/cmake/Whitelist.cmake b/cmake/Whitelist.cmake index a283c151f4b4..48ec040b92d3 100644 --- a/cmake/Whitelist.cmake +++ b/cmake/Whitelist.cmake @@ -1,12 +1,12 @@ -if (__caffe2_whitelist_included) +if(__caffe2_whitelist_included) return() endif() set (__caffe2_whitelist_included TRUE) set(CAFFE2_WHITELISTED_FILES) -if (NOT CAFFE2_WHITELIST) +if(NOT CAFFE2_WHITELIST) return() endif() @@ -24,7 +24,7 @@ macro(caffe2_do_whitelist output whitelist) set(_tmp) foreach(item ${${output}}) list(FIND ${whitelist} ${item} _index) - if (${_index} GREATER -1) + if(${_index} GREATER -1) set(_tmp ${_tmp} ${item}) endif() endforeach() diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in index d00a5166581a..38e826e24b9c 100644 --- a/cmake/cmake_uninstall.cmake.in +++ b/cmake/cmake_uninstall.cmake.in @@ -2,9 +2,9 @@ if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") -if (NOT DEFINED CMAKE_INSTALL_PREFIX) +if(NOT DEFINED CMAKE_INSTALL_PREFIX) set (CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") -endif () +endif() message(${CMAKE_INSTALL_PREFIX}) file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) diff --git a/cmake/iOS.cmake b/cmake/iOS.cmake index c97eaba903a5..7444a7f831b6 100644 --- a/cmake/iOS.cmake +++ b/cmake/iOS.cmake @@ -40,10 +40,10 @@ set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment # Determine the cmake host system version so we know where to find the iOS SDKs find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) -if (CMAKE_UNAME) +if(CMAKE_UNAME) exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION) string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") -endif (CMAKE_UNAME) +endif(CMAKE_UNAME) # Force the compilers to gcc for iOS set(CMAKE_C_COMPILER /usr/bin/gcc CACHE STRING "") @@ -53,35 +53,35 @@ set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) set(PKG_CONFIG_EXECUTABLE pkg-config CACHE FILEPATH "" FORCE) # Setup iOS platform unless specified manually with IOS_PLATFORM -if (NOT DEFINED IOS_PLATFORM) +if(NOT DEFINED IOS_PLATFORM) set (IOS_PLATFORM "OS") -endif (NOT DEFINED IOS_PLATFORM) +endif(NOT DEFINED IOS_PLATFORM) set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") # Check the platform selection and setup for developer root -if (${IOS_PLATFORM} STREQUAL "OS") +if(${IOS_PLATFORM} STREQUAL "OS") set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") set (XCODE_IOS_PLATFORM iphoneos) # This causes the installers to properly locate the output libraries set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") -elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") +elseif(${IOS_PLATFORM} STREQUAL "SIMULATOR") set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") set (XCODE_IOS_PLATFORM iphonesimulator) # This causes the installers to properly locate the output libraries set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") -elseif (${IOS_PLATFORM} STREQUAL "WATCHOS") +elseif(${IOS_PLATFORM} STREQUAL "WATCHOS") set (IOS_PLATFORM_LOCATION "WatchOS.platform") set (XCODE_IOS_PLATFORM watchos) # This causes the installers to properly locate the output libraries set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-watchos") -else (${IOS_PLATFORM} STREQUAL "OS") +else(${IOS_PLATFORM} STREQUAL "OS") message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. " "Please choose OS, SIMULATOR, or WATCHOS.") -endif () +endif() # All iOS/Darwin specific settings - some may be redundant set (CMAKE_SHARED_LIBRARY_PREFIX "lib") @@ -96,7 +96,7 @@ set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") -if (IOS_DEPLOYMENT_TARGET) +if(IOS_DEPLOYMENT_TARGET) set(XCODE_IOS_PLATFORM_VERSION_FLAGS "-m${XCODE_IOS_PLATFORM}-version-min=${IOS_DEPLOYMENT_TARGET}") endif() @@ -118,9 +118,9 @@ set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex -if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) +if(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) -endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) +endif(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) # Setup iOS deployment target set (IOS_DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET} CACHE STRING "Minimum iOS version") @@ -130,40 +130,40 @@ set (IOS_DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET} CACHE STRING "Minimum iOS ve exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR) set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer") set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") -if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) - if (EXISTS ${XCODE_POST_43_ROOT}) +if(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) + if(EXISTS ${XCODE_POST_43_ROOT}) set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) elseif(EXISTS ${XCODE_PRE_43_ROOT}) set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) - endif (EXISTS ${XCODE_POST_43_ROOT}) -endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) + endif(EXISTS ${XCODE_POST_43_ROOT}) +endif(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT -if (NOT DEFINED CMAKE_IOS_SDK_ROOT) +if(NOT DEFINED CMAKE_IOS_SDK_ROOT) file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") - if (_CMAKE_IOS_SDKS) + if(_CMAKE_IOS_SDKS) list (SORT _CMAKE_IOS_SDKS) list (REVERSE _CMAKE_IOS_SDKS) list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) - else (_CMAKE_IOS_SDKS) + else(_CMAKE_IOS_SDKS) message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") - endif (_CMAKE_IOS_SDKS) + endif(_CMAKE_IOS_SDKS) message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") -endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) +endif(NOT DEFINED CMAKE_IOS_SDK_ROOT) set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") # Set the sysroot default to the most recent SDK set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") # set the architecture for iOS -if (IOS_PLATFORM STREQUAL "OS") +if(IOS_PLATFORM STREQUAL "OS") set (DEFAULT_IOS_ARCH "arm64") -elseif (IOS_PLATFORM STREQUAL "SIMULATOR") +elseif(IOS_PLATFORM STREQUAL "SIMULATOR") set (DEFAULT_IOS_ARCH "x86_64") -elseif (IOS_PLATFORM STREQUAL "WATCHOS") +elseif(IOS_PLATFORM STREQUAL "WATCHOS") set (DEFAULT_IOS_ARCH "armv7k;arm64_32") -endif () +endif() set (IOS_ARCH ${DEFAULT_IOS_ARCH} CACHE string "Build architecture for iOS") set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS") diff --git a/cmake/public/LoadHIP.cmake b/cmake/public/LoadHIP.cmake index fd5e97d3e1e2..806c7510532a 100644 --- a/cmake/public/LoadHIP.cmake +++ b/cmake/public/LoadHIP.cmake @@ -1,125 +1,125 @@ set(PYTORCH_FOUND_HIP FALSE) -IF(NOT DEFINED ENV{ROCM_PATH}) +if(NOT DEFINED ENV{ROCM_PATH}) SET(ROCM_PATH /opt/rocm) -ELSE() +else() SET(ROCM_PATH $ENV{ROCM_PATH}) -ENDIF() +endif() # HIP_PATH -IF(NOT DEFINED ENV{HIP_PATH}) +if(NOT DEFINED ENV{HIP_PATH}) SET(HIP_PATH ${ROCM_PATH}/hip) -ELSE() +else() SET(HIP_PATH $ENV{HIP_PATH}) -ENDIF() +endif() -IF(NOT EXISTS ${HIP_PATH}) +if(NOT EXISTS ${HIP_PATH}) return() -ENDIF() +endif() # HCC_PATH -IF(NOT DEFINED ENV{HCC_PATH}) +if(NOT DEFINED ENV{HCC_PATH}) SET(HCC_PATH ${ROCM_PATH}/hcc) -ELSE() +else() SET(HCC_PATH $ENV{HCC_PATH}) -ENDIF() +endif() # HSA_PATH -IF(NOT DEFINED ENV{HSA_PATH}) +if(NOT DEFINED ENV{HSA_PATH}) SET(HSA_PATH ${ROCM_PATH}/hsa) -ELSE() +else() SET(HSA_PATH $ENV{HSA_PATH}) -ENDIF() +endif() # ROCBLAS_PATH -IF(NOT DEFINED ENV{ROCBLAS_PATH}) +if(NOT DEFINED ENV{ROCBLAS_PATH}) SET(ROCBLAS_PATH ${ROCM_PATH}/rocblas) -ELSE() +else() SET(ROCBLAS_PATH $ENV{ROCBLAS_PATH}) -ENDIF() +endif() # ROCFFT_PATH -IF(NOT DEFINED ENV{ROCFFT_PATH}) +if(NOT DEFINED ENV{ROCFFT_PATH}) SET(ROCFFT_PATH ${ROCM_PATH}/rocfft) -ELSE() +else() SET(ROCFFT_PATH $ENV{ROCFFT_PATH}) -ENDIF() +endif() # HIPSPARSE_PATH -IF(NOT DEFINED ENV{HIPSPARSE_PATH}) +if(NOT DEFINED ENV{HIPSPARSE_PATH}) SET(HIPSPARSE_PATH ${ROCM_PATH}/hipsparse) -ELSE() +else() SET(HIPSPARSE_PATH $ENV{HIPSPARSE_PATH}) -ENDIF() +endif() # THRUST_PATH -IF(DEFINED ENV{THRUST_PATH}) +if(DEFINED ENV{THRUST_PATH}) SET(THRUST_PATH $ENV{THRUST_PATH}) -ELSE() +else() SET(THRUST_PATH ${ROCM_PATH}/include) -ENDIF() +endif() # HIPRAND_PATH -IF(NOT DEFINED ENV{HIPRAND_PATH}) +if(NOT DEFINED ENV{HIPRAND_PATH}) SET(HIPRAND_PATH ${ROCM_PATH}/hiprand) -ELSE() +else() SET(HIPRAND_PATH $ENV{HIPRAND_PATH}) -ENDIF() +endif() # ROCRAND_PATH -IF(NOT DEFINED ENV{ROCRAND_PATH}) +if(NOT DEFINED ENV{ROCRAND_PATH}) SET(ROCRAND_PATH ${ROCM_PATH}/rocrand) -ELSE() +else() SET(ROCRAND_PATH $ENV{ROCRAND_PATH}) -ENDIF() +endif() # MIOPEN_PATH -IF(NOT DEFINED ENV{MIOPEN_PATH}) +if(NOT DEFINED ENV{MIOPEN_PATH}) SET(MIOPEN_PATH ${ROCM_PATH}/miopen) -ELSE() +else() SET(MIOPEN_PATH $ENV{MIOPEN_PATH}) -ENDIF() +endif() # RCCL_PATH -IF(NOT DEFINED ENV{RCCL_PATH}) +if(NOT DEFINED ENV{RCCL_PATH}) SET(RCCL_PATH ${ROCM_PATH}/rccl) -ELSE() +else() SET(RCCL_PATH $ENV{RCCL_PATH}) -ENDIF() +endif() # ROCPRIM_PATH -IF(NOT DEFINED ENV{ROCPRIM_PATH}) +if(NOT DEFINED ENV{ROCPRIM_PATH}) SET(ROCPRIM_PATH ${ROCM_PATH}/rocprim) -ELSE() +else() SET(ROCPRIM_PATH $ENV{ROCPRIM_PATH}) -ENDIF() +endif() # HIPCUB_PATH -IF(NOT DEFINED ENV{HIPCUB_PATH}) +if(NOT DEFINED ENV{HIPCUB_PATH}) SET(HIPCUB_PATH ${ROCM_PATH}/hipcub) -ELSE() +else() SET(HIPCUB_PATH $ENV{HIPCUB_PATH}) -ENDIF() +endif() # ROCTHRUST_PATH -IF(NOT DEFINED ENV{ROCTHRUST_PATH}) +if(NOT DEFINED ENV{ROCTHRUST_PATH}) SET(ROCTHRUST_PATH ${ROCM_PATH}/rocthrust) -ELSE() +else() SET(ROCTHRUST_PATH $ENV{ROCTHRUST_PATH}) -ENDIF() +endif() # ROCTRACER_PATH -IF(NOT DEFINED ENV{ROCTRACER_PATH}) +if(NOT DEFINED ENV{ROCTRACER_PATH}) SET(ROCTRACER_PATH ${ROCM_PATH}/roctracer) -ELSE() +else() SET(ROCTRACER_PATH $ENV{ROCTRACER_PATH}) -ENDIF() +endif() -IF(NOT DEFINED ENV{PYTORCH_ROCM_ARCH}) +if(NOT DEFINED ENV{PYTORCH_ROCM_ARCH}) SET(PYTORCH_ROCM_ARCH gfx803;gfx900;gfx906;gfx908) -ELSE() +else() SET(PYTORCH_ROCM_ARCH $ENV{PYTORCH_ROCM_ARCH}) -ENDIF() +endif() # Add HIP to the CMAKE Module Path set(CMAKE_MODULE_PATH ${HIP_PATH}/cmake ${CMAKE_MODULE_PATH}) @@ -135,7 +135,7 @@ endmacro() # Find the HIP Package find_package_and_print_version(HIP 1.0) -IF(HIP_FOUND) +if(HIP_FOUND) set(PYTORCH_FOUND_HIP TRUE) message("\n***** Library versions from dpkg *****\n") @@ -196,4 +196,4 @@ IF(HIP_FOUND) set(hcc_INCLUDE_DIRS ${HCC_PATH}/include) set(hsa_INCLUDE_DIRS ${HSA_PATH}/include) -ENDIF() +endif() diff --git a/cmake/public/cuda.cmake b/cmake/public/cuda.cmake index 22cf0f201c84..1609fc06a9aa 100644 --- a/cmake/public/cuda.cmake +++ b/cmake/public/cuda.cmake @@ -21,7 +21,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../Modules_CUDA_fix) # More details can be found in the following links. # https://github.com/pytorch/pytorch/issues/20635 # https://github.com/pytorch/pytorch/issues/17108 -if (NOT MSVC) +if(NOT MSVC) set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "") endif() @@ -207,7 +207,7 @@ if(CAFFE2_STATIC_LINK_CUDA) set_property( TARGET torch::cudart PROPERTY INTERFACE_LINK_LIBRARIES "${CUDA_cudart_static_LIBRARY}") - if (NOT WIN32) + if(NOT WIN32) set_property( TARGET torch::cudart APPEND PROPERTY INTERFACE_LINK_LIBRARIES rt dl) @@ -291,7 +291,7 @@ if(CAFFE2_STATIC_LINK_CUDA AND NOT WIN32) set_property( TARGET caffe2::cublas PROPERTY INTERFACE_LINK_LIBRARIES "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcublas_static.a") - if (CUDA_VERSION VERSION_GREATER_EQUAL 10.1) + if(CUDA_VERSION VERSION_GREATER_EQUAL 10.1) set_property( TARGET caffe2::cublas APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcublasLt_static.a") @@ -330,7 +330,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") endif() # Add onnx namepsace definition to nvcc -if (ONNX_NAMESPACE) +if(ONNX_NAMESPACE) list(APPEND CUDA_NVCC_FLAGS "-DONNX_NAMESPACE=${ONNX_NAMESPACE}") else() list(APPEND CUDA_NVCC_FLAGS "-DONNX_NAMESPACE=onnx_c2") @@ -341,9 +341,9 @@ endif() # them from compiling the std::tuple header of GCC 6. # See Sec. 2.2.1 of # https://developer.download.nvidia.com/compute/cuda/9.2/Prod/docs/sidebar/CUDA_Toolkit_Release_Notes.pdf -if ((CUDA_VERSION VERSION_EQUAL 9.0) OR +if((CUDA_VERSION VERSION_EQUAL 9.0) OR (CUDA_VERSION VERSION_GREATER 9.0 AND CUDA_VERSION VERSION_LESS 9.2)) - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND + if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0 AND CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER) message(FATAL_ERROR @@ -357,9 +357,9 @@ endif() # CUDA 9.0 / 9.1 require MSVC version < 19.12 # CUDA 9.2 require MSVC version < 19.13 # CUDA 10.0 require MSVC version < 19.20 -if ((CUDA_VERSION VERSION_EQUAL 9.0) OR +if((CUDA_VERSION VERSION_EQUAL 9.0) OR (CUDA_VERSION VERSION_GREATER 9.0 AND CUDA_VERSION VERSION_LESS 9.2)) - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.12 AND NOT DEFINED ENV{CUDAHOSTCXX}) message(FATAL_ERROR @@ -371,7 +371,7 @@ if ((CUDA_VERSION VERSION_EQUAL 9.0) OR "\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.11.25503\\bin\\HostX64\\x64\\cl.exe\"\n") endif() elseif(CUDA_VERSION VERSION_EQUAL 9.2) - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.13 AND NOT DEFINED ENV{CUDAHOSTCXX}) message(FATAL_ERROR @@ -383,7 +383,7 @@ elseif(CUDA_VERSION VERSION_EQUAL 9.2) "\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.12.25827\\bin\\HostX64\\x64\\cl.exe\"\n") endif() elseif(CUDA_VERSION VERSION_EQUAL 10.0) - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.20 AND NOT DEFINED ENV{CUDAHOSTCXX}) message(FATAL_ERROR @@ -428,7 +428,7 @@ endforeach() # Set C++14 support set(CUDA_PROPAGATE_HOST_FLAGS_BLACKLIST "-Werror") -if (MSVC) +if(MSVC) list(APPEND CUDA_PROPAGATE_HOST_FLAGS_BLACKLIST "/EHa") else() list(APPEND CUDA_NVCC_FLAGS "-std=c++14") @@ -436,10 +436,10 @@ else() endif() # OpenMP flags for NVCC with Clang-cl -if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC" +if("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC" AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") list(APPEND CUDA_PROPAGATE_HOST_FLAGS_BLACKLIST "-Xclang" "-fopenmp") - if (MSVC_TOOLSET_VERSION LESS 142) + if(MSVC_TOOLSET_VERSION LESS 142) list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-openmp") else() list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-openmp:experimental") @@ -447,13 +447,13 @@ if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC" endif() # Debug and Release symbol support -if (MSVC) - if (${CAFFE2_USE_MSVC_STATIC_RUNTIME}) +if(MSVC) + if(${CAFFE2_USE_MSVC_STATIC_RUNTIME}) list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MT$<$:d>") else() list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-MD$<$:d>") endif() -elseif (CUDA_DEVICE_DEBUG) +elseif(CUDA_DEVICE_DEBUG) list(APPEND CUDA_NVCC_FLAGS "-g" "-G") # -G enables device code debugging symbols endif() diff --git a/cmake/public/gflags.cmake b/cmake/public/gflags.cmake index ac4002efc088..a030fdd7d429 100644 --- a/cmake/public/gflags.cmake +++ b/cmake/public/gflags.cmake @@ -2,11 +2,11 @@ # We will try to use the config mode first, and then manual find. find_package(gflags CONFIG QUIET) -if (NOT TARGET gflags) +if(NOT TARGET gflags) find_package(gflags MODULE QUIET) endif() -if (TARGET gflags) +if(TARGET gflags) message(STATUS "Caffe2: Found gflags with new-style gflags target.") elseif(GFLAGS_FOUND) message(STATUS "Caffe2: Found gflags with old-style gflag starget.") @@ -75,7 +75,7 @@ else() endif() # After above, we should have the gflags target now. -if (NOT TARGET gflags) +if(NOT TARGET gflags) message(WARNING "Caffe2: gflags cannot be found. Depending on whether you are building " "Caffe2 or a Caffe2 dependent library, the next warning / error will " diff --git a/cmake/public/glog.cmake b/cmake/public/glog.cmake index f719da3e1fab..a067c8dc7875 100644 --- a/cmake/public/glog.cmake +++ b/cmake/public/glog.cmake @@ -2,11 +2,11 @@ # We will try to use the config mode first, and then manual find. find_package(glog CONFIG QUIET) -if (NOT TARGET glog::glog) +if(NOT TARGET glog::glog) find_package(glog MODULE QUIET) endif() -if (TARGET glog::glog) +if(TARGET glog::glog) message(STATUS "Caffe2: Found glog with new-style glog target.") elseif(GLOG_FOUND) message( @@ -62,7 +62,7 @@ else() endif() # After above, we should have the glog::glog target now. -if (NOT TARGET glog::glog) +if(NOT TARGET glog::glog) message(WARNING "Caffe2: glog cannot be found. Depending on whether you are building " "Caffe2 or a Caffe2 dependent library, the next warning / error will " diff --git a/cmake/public/protobuf.cmake b/cmake/public/protobuf.cmake index 094d222b189d..77ec3622b132 100644 --- a/cmake/public/protobuf.cmake +++ b/cmake/public/protobuf.cmake @@ -2,11 +2,11 @@ # We will try to use the config mode first, and then manual find. find_package(Protobuf CONFIG QUIET) -if (NOT Protobuf_FOUND) +if(NOT Protobuf_FOUND) find_package(Protobuf MODULE QUIET) endif() -if ((TARGET protobuf::libprotobuf OR TARGET protobuf::libprotobuf-lite) AND TARGET protobuf::protoc) +if((TARGET protobuf::libprotobuf OR TARGET protobuf::libprotobuf-lite) AND TARGET protobuf::protoc) # Hooray. This is the most ideal situation, meaning that you either have a # Protobuf config file installed (like on Windows), or you are using a # modern CMake that ships with a FindProtobuf.cmake file that produces @@ -16,7 +16,7 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND) # If the modern targets are not present, we will generate them for you for # backward compatibility. This is backported from CMake's new FindProtobuf.cmake # content. - if ((NOT PROTOBUF_LIBRARY) AND (NOT PROTOBUF_LITE_LIBRARY)) + if((NOT PROTOBUF_LIBRARY) AND (NOT PROTOBUF_LITE_LIBRARY)) message(FATAL_ERROR "Caffe2: Found protobuf with old style targets, but could not find targets." " PROTOBUF_LIBRARY: " ${PROTOBUF_LIBRARY} @@ -27,7 +27,7 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND) message(STATUS "Caffe2: Found protobuf with old-style protobuf targets.") if(PROTOBUF_LIBRARY) - if (NOT TARGET protobuf::libprotobuf) + if(NOT TARGET protobuf::libprotobuf) add_library(protobuf::libprotobuf UNKNOWN IMPORTED) set_target_properties(protobuf::libprotobuf PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_INCLUDE_DIRS}") @@ -51,7 +51,7 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND) endif() if(PROTOBUF_LITE_LIBRARY) - if (NOT TARGET protobuf::libprotobuf-lite) + if(NOT TARGET protobuf::libprotobuf-lite) add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED) set_target_properties(protobuf::libprotobuf-lite PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_INCLUDE_DIRS}") @@ -75,7 +75,7 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND) endif() if(PROTOBUF_PROTOC_EXECUTABLE) - if (NOT TARGET protobuf::protoc) + if(NOT TARGET protobuf::protoc) add_executable(protobuf::protoc IMPORTED) endif() set_property(TARGET protobuf::protoc PROPERTY @@ -84,7 +84,7 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND) endif() # After above, we should have the protobuf related target now. -if ((NOT TARGET protobuf::libprotobuf) AND (NOT TARGET protobuf::libprotobuf-lite)) +if((NOT TARGET protobuf::libprotobuf) AND (NOT TARGET protobuf::libprotobuf-lite)) message(WARNING "Protobuf cannot be found. Depending on whether you are building Caffe2 " "or a Caffe2 dependent library, the next warning / error will give you " diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake index 63484b323cbe..d7dd0ba60c69 100644 --- a/cmake/public/utils.cmake +++ b/cmake/public/utils.cmake @@ -44,7 +44,7 @@ macro(caffe2_interface_library SRC DST) get_target_property(__src_target_type ${SRC} TYPE) # Depending on the type of the source library, we will set up the # link command for the specific SRC library. - if (${__src_target_type} STREQUAL "STATIC_LIBRARY") + if(${__src_target_type} STREQUAL "STATIC_LIBRARY") # In the case of static library, we will need to add whole-static flags. if(APPLE) target_link_libraries( @@ -120,7 +120,7 @@ function(caffe2_binary_target target_name_or_src) # https://cmake.org/cmake/help/latest/command/function.html # Checking that ARGC is greater than # is the only way to ensure # that ARGV# was passed to the function as an extra argument. - if (ARGC GREATER 1) + if(ARGC GREATER 1) set(__target ${target_name_or_src}) prepend(__srcs "${CMAKE_CURRENT_SOURCE_DIR}/" "${ARGN}") else() @@ -130,17 +130,17 @@ function(caffe2_binary_target target_name_or_src) add_executable(${__target} ${__srcs}) target_link_libraries(${__target} ${Caffe2_MAIN_LIBS}) # If we have Caffe2_MODULES defined, we will also link with the modules. - if (DEFINED Caffe2_MODULES) + if(DEFINED Caffe2_MODULES) target_link_libraries(${__target} ${Caffe2_MODULES}) endif() - if (USE_TBB) + if(USE_TBB) target_include_directories(${__target} PUBLIC ${TBB_ROOT_DIR}/include) endif() install(TARGETS ${__target} DESTINATION bin) endfunction() function(caffe2_hip_binary_target target_name_or_src) - if (ARGC GREATER 1) + if(ARGC GREATER 1) set(__target ${target_name_or_src}) prepend(__srcs "${CMAKE_CURRENT_SOURCE_DIR}/" "${ARGN}") else() @@ -160,13 +160,13 @@ endfunction() # torch_cuda_based_add_executable(cuda_target) # macro(torch_cuda_based_add_executable cuda_target) - IF (USE_ROCM) + if(USE_ROCM) hip_add_executable(${cuda_target} ${ARGN}) - ELSEIF(USE_CUDA) + elseif(USE_CUDA) cuda_add_executable(${cuda_target} ${ARGN}) - ELSE() + else() - ENDIF() + endif() endmacro() @@ -176,12 +176,12 @@ endmacro() # torch_cuda_based_add_library(cuda_target) # macro(torch_cuda_based_add_library cuda_target) - IF (USE_ROCM) + if(USE_ROCM) hip_add_library(${cuda_target} ${ARGN}) - ELSEIF(USE_CUDA) + elseif(USE_CUDA) cuda_add_library(${cuda_target} ${ARGN}) - ELSE() - ENDIF() + else() + endif() endmacro() @@ -192,7 +192,7 @@ endmacro() # macro(torch_cuda_get_nvcc_gencode_flag store_var) # setting nvcc arch flags - if ((NOT EXISTS ${TORCH_CUDA_ARCH_LIST}) AND (DEFINED ENV{TORCH_CUDA_ARCH_LIST})) + if((NOT EXISTS ${TORCH_CUDA_ARCH_LIST}) AND (DEFINED ENV{TORCH_CUDA_ARCH_LIST})) message(WARNING "In the future we will require one to explicitly pass " "TORCH_CUDA_ARCH_LIST to cmake instead of implicitly setting it as an " @@ -200,7 +200,7 @@ macro(torch_cuda_get_nvcc_gencode_flag store_var) "pytorch.") set(TORCH_CUDA_ARCH_LIST $ENV{TORCH_CUDA_ARCH_LIST}) endif() - if (EXISTS ${CUDA_ARCH_NAME}) + if(EXISTS ${CUDA_ARCH_NAME}) message(WARNING "CUDA_ARCH_NAME is no longer used. Use TORCH_CUDA_ARCH_LIST instead. " "Right now, CUDA_ARCH_NAME is ${CUDA_ARCH_NAME} and " @@ -220,11 +220,11 @@ endmacro() function(torch_compile_options libname) set_property(TARGET ${libname} PROPERTY CXX_STANDARD 14) - if (NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE) + if(NOT INTERN_BUILD_MOBILE OR NOT BUILD_CAFFE2_MOBILE) # until they can be unified, keep these lists synced with setup.py if(MSVC) - if (MSVC_Z7_OVERRIDE) + if(MSVC_Z7_OVERRIDE) set(MSVC_DEBINFO_OPTION "/Z7") else() set(MSVC_DEBINFO_OPTION "/Zi") @@ -271,13 +271,13 @@ function(torch_compile_options libname) endif() - if (MSVC) - elseif (WERROR) + if(MSVC) + elseif(WERROR) target_compile_options(${libname} PRIVATE -Werror -Wno-strict-overflow) endif() endif() - if (NOT WIN32 AND NOT USE_ASAN) + if(NOT WIN32 AND NOT USE_ASAN) # Enable hidden visibility by default to make it easier to debug issues with # TORCH_API annotations. Hidden visibility with selective default visibility # behaves close enough to Windows' dllimport/dllexport. @@ -293,7 +293,7 @@ function(torch_compile_options libname) # ---[ Check if warnings should be errors. # TODO: Dedupe with WERROR check above - if (WERROR) + if(WERROR) target_compile_options(${libname} PRIVATE -Werror) endif() endfunction() diff --git a/torch/lib/libshm/CMakeLists.txt b/torch/lib/libshm/CMakeLists.txt index 65dcf483b059..3b747a4f0af7 100644 --- a/torch/lib/libshm/CMakeLists.txt +++ b/torch/lib/libshm/CMakeLists.txt @@ -5,22 +5,22 @@ CMAKE_POLICY(VERSION 2.6) set(TORCH_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../../) include(${TORCH_ROOT}/cmake/public/threads.cmake) -IF(NOT LIBSHM_INSTALL_LIB_SUBDIR) +if(NOT LIBSHM_INSTALL_LIB_SUBDIR) SET(LIBSHM_INSTALL_LIB_SUBDIR "lib" CACHE PATH "libshm install library directory") -ENDIF() +endif() # Flags # When using MSVC -IF(MSVC) +if(MSVC) # we want to respect the standard, and we are bored of those **** . ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE=1) -ENDIF(MSVC) +endif(MSVC) -IF (CMAKE_VERSION VERSION_LESS "3.1") +if(CMAKE_VERSION VERSION_LESS "3.1") SET(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}") -ELSE () +else() SET(CMAKE_CXX_STANDARD 14) -ENDIF () +endif() ADD_LIBRARY(shm SHARED core.cpp) diff --git a/torch/lib/libshm_windows/CMakeLists.txt b/torch/lib/libshm_windows/CMakeLists.txt index 58e9f1d83131..719e73a34fd8 100644 --- a/torch/lib/libshm_windows/CMakeLists.txt +++ b/torch/lib/libshm_windows/CMakeLists.txt @@ -1,7 +1,7 @@ -IF(NOT LIBSHM_INSTALL_LIB_SUBDIR) +if(NOT LIBSHM_INSTALL_LIB_SUBDIR) SET(LIBSHM_INSTALL_BIN_SUBDIR "bin" CACHE PATH "libshm install binary directory") SET(LIBSHM_INSTALL_LIB_SUBDIR "lib" CACHE PATH "libshm install library directory") -ENDIF() +endif() ADD_LIBRARY(shm SHARED core.cpp) @@ -23,6 +23,6 @@ TARGET_LINK_LIBRARIES(shm torch c10) INSTALL(TARGETS shm DESTINATION "${LIBSHM_INSTALL_LIB_SUBDIR}") INSTALL(FILES libshm.h DESTINATION "include") -if (MSVC AND BUILD_SHARED_LIBS) +if(MSVC AND BUILD_SHARED_LIBS) INSTALL(FILES $ DESTINATION "${LIBSHM_INSTALL_LIB_SUBDIR}" OPTIONAL) endif()