Do not define MLX_VERSION globally (#1966)

This commit is contained in:
Cheng
2025-03-18 23:12:40 +09:00
committed by GitHub
parent 45ad06aac8
commit 0a9777aa5c
3 changed files with 7 additions and 9 deletions

View File

@@ -17,9 +17,13 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/transforms.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linalg.cpp
${CMAKE_CURRENT_SOURCE_DIR}/version.cpp
${CMAKE_CURRENT_SOURCE_DIR}/backend/metal/metal.h)
# Define MLX_VERSION only in the version.cpp file.
add_library(mlx_version STATIC ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
target_compile_definitions(mlx_version PRIVATE MLX_VERSION="${MLX_VERSION}")
target_link_libraries(mlx PRIVATE $<BUILD_INTERFACE:mlx_version>)
if(MSVC)
# Disable some MSVC warnings to speed up compilation.
target_compile_options(mlx PUBLIC /wd4068 /wd4244 /wd4267 /wd4804)

View File

@@ -2,15 +2,10 @@
#include <string>
#include "mlx/version.h"
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
namespace mlx::core {
std::string version() {
return TOSTRING(MLX_VERSION);
return MLX_VERSION;
}
} // namespace mlx::core