66 VERSION 1.0.0
77 LANGUAGES CXX )
88
9- option (BUILD_WASM "Build for WebAssembly" OFF )
109option (BUILD_EXAMPLES "Build examples" ON )
1110option (BUILD_TESTS "Build tests" ON )
1211option (BENCHMARK "Build with benchmark mode" OFF )
@@ -16,11 +15,16 @@ set(CMAKE_CXX_STANDARD 17)
1615set (CMAKE_CXX_STANDARD_REQUIRED ON )
1716set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
1817
19- if (WIN32 )
20- # Forcing MSVC to use utf-8 encoding
21- add_compile_options ("$<$<C_COMPILER_ID :MSVC >:/utf -8>" )
22- add_compile_options ("$<$<CXX_COMPILER_ID :MSVC >:/utf -8>" )
23- endif (WIN32 )
18+ # Library target
19+ add_library (${PROJECT_NAME} INTERFACE )
20+
21+ target_include_directories (
22+ ${PROJECT_NAME}
23+ INTERFACE $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /include >
24+ $<INSTALL_INTERFACE :include >)
25+
26+ include (CheckLanguage )
27+ include (FetchContent )
2428
2529if (BUILD_WASM)
2630 # Ensure we're using Emscripten compiler
@@ -46,59 +50,59 @@ if(BUILD_WASM)
4650
4751 # Set output extension
4852 set (CMAKE_EXECUTABLE_SUFFIX .js)
49-
50- # Disable CUDA/Metal when building for web
51- set (CUDA_FOUND FALSE )
52- set (METAL_FOUND FALSE )
53- set (BUILD_TESTS FALSE )
5453else ()
55- include (CheckLanguage )
56- # Check for CUDA
57- check_language (CUDA )
58- if (CMAKE_CUDA_COMPILER)
59- enable_language (CUDA )
60- find_package (CUDA REQUIRED )
61- include_directories (${CUDA_INCLUDE_DIRS} )
62- set (CMAKE_CUDA_STANDARD 14)
63- target_compile_definitions (${PROJECT_NAME} PRIVATE USE_CUDA )
64- set (CUDA_FOUND TRUE )
65- message (STATUS "CUDA found. Building with CUDA support." )
54+ # Metal Support (macOS/iOS)
55+ if (APPLE )
56+ find_library (METAL_FRAMEWORK Metal )
57+ find_library (METALKIT_FRAMEWORK MetalKit )
58+ find_library (FOUNDATION_FRAMEWORK Foundation )
59+
60+ if (METAL_FRAMEWORK AND METALKIT_FRAMEWORK)
61+ message (STATUS "Apple Metal found. Building with Metal support" )
62+ enable_language (OBJCXX )
63+ set (CMAKE_OBJCXX_STANDARD 20)
64+ set (CMAKE_OBJCXX_STANDARD_REQUIRED ON )
65+ # Fetch Metal-cpp
66+ FetchContent_Declare (
67+ metal-cpp
68+ GIT_REPOSITORY https://github.com/rizajin/metal-cpp.git
69+ GIT_TAG "main"
70+ GIT_PROGRESS TRUE )
71+ FetchContent_MakeAvailable (metal-cpp)
72+ target_link_libraries (
73+ ${PROJECT_NAME} INTERFACE "-framework Metal" "-framework Foundation"
74+ "-framework QuartzCore" "-framework MetalKit" )
75+ add_compile_definitions ("__METAL__" )
76+ else ()
77+ message (STATUS "Apple Metal not found. Building without Metal support" )
78+ endif ()
79+
80+ # set(CMAKE_THREAD_LIBS_INIT "-lpthread")
81+ # set(CMAKE_HAVE_THREADS_LIBRARY 1)
82+ # set(CMAKE_USE_WIN32_THREADS_INIT 0)
83+ # set(CMAKE_USE_PTHREADS_INIT 1)
84+ # set(THREADS_PREFER_PTHREAD_FLAG ON)
6685 else ()
67- set (CUDA_FOUND FALSE )
68- message (STATUS "CUDA not found. Checking for Apple Metal support." )
69- endif ()
70-
71- # Check for Apple Metal (only if CUDA is not found)
72- if (NOT CUDA_FOUND AND APPLE )
73- set (CMAKE_THREAD_LIBS_INIT "-lpthread" )
74- set (CMAKE_HAVE_THREADS_LIBRARY 1)
75- set (CMAKE_USE_WIN32_THREADS_INIT 0)
76- set (CMAKE_USE_PTHREADS_INIT 1)
77- set (THREADS_PREFER_PTHREAD_FLAG ON )
78- # Set the SDK path set(CMAKE_OSX_SYSROOT
79- # /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk)
80- # find_library(METAL_LIBRARY Metal) find_library(FOUNDATION_LIBRARY
81- # Foundation) if(METAL_LIBRARY AND FOUNDATION_LIBRARY) set(METAL_FOUND TRUE)
82- # target_compile_definitions(${PROJECT_NAME} PRIVATE USE_METAL)
83- # message(STATUS "Apple Metal found. Building with Metal support.") else()
84- # message(WARNING "Neither CUDA nor Apple Metal found. Building without GPU
85- # acceleration.")
86+ if (WIN32 )
87+ # Forcing MSVC to use utf-8 encoding
88+ add_compile_options ("$<$<C_COMPILER_ID :MSVC >:/utf -8>" )
89+ add_compile_options ("$<$<CXX_COMPILER_ID :MSVC >:/utf -8>" )
90+ endif (WIN32 )
91+
92+ check_language (CUDA )
93+ if (CMAKE_CUDA_COMPILER)
94+ message (STATUS "CUDA found. Building with CUDA support" )
95+ enable_language (CUDA )
96+ set (CMAKE_CUDA_STANDARD 14)
97+ find_package (CUDA REQUIRED )
98+ include_directories (${CUDA_INCLUDE_DIRS} )
99+ add_compile_definitions ("__CUDA__" )
100+ else ()
101+ message (STATUS "CUDA not found. Building without CUDA support" )
102+ endif ()
86103 endif ()
87104endif ()
88105
89- # Library target
90- add_library (${PROJECT_NAME} INTERFACE )
91-
92- target_include_directories (
93- ${PROJECT_NAME}
94- INTERFACE $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /include >
95- $<INSTALL_INTERFACE :include >)
96-
97- # Optional builds
98- option (BUILD_EXAMPLES "Build examples" ON )
99- option (BUILD_TESTS "Build tests" ON )
100- option (BENCHMARK "Build with benchmark mode" OFF )
101-
102106# Benchmark mode
103107if (BENCHMARK)
104108 target_compile_definitions (${PROJECT_NAME} PRIVATE BENCHMARK_MODE )
@@ -128,7 +132,6 @@ endif()
128132# Tests
129133if (BUILD_TESTS)
130134 # Fetch GoogleTest
131- include (FetchContent )
132135 FetchContent_Declare (
133136 googletest
134137 GIT_REPOSITORY https://github.com/google/googletest.git
0 commit comments