Skip to content

Commit a2a0ca3

Browse files
feat(cmake): add option to enable/disable SIMD optimizations for targets
1 parent e6d2298 commit a2a0ca3

3 files changed

Lines changed: 32 additions & 64 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ option(NFX_DATATYPES_BUILD_SAMPLES "Build samples" OFF)
4444
option(NFX_DATATYPES_BUILD_BENCHMARKS "Build benchmarks" OFF)
4545
option(NFX_DATATYPES_BUILD_DOCUMENTATION "Build Doxygen documentation" OFF)
4646

47+
# --- Performance options ---
48+
option(NFX_DATATYPES_ENABLE_NATIVE_OPTS "Enable native CPU optimizations" ON )
49+
4750
# --- Installation and packaging ---
4851
option(NFX_DATATYPES_INSTALL_PROJECT "Install project" OFF)
4952
option(NFX_DATATYPES_PACKAGE_SOURCE "Enable source package generation" OFF)

README.md

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,12 @@ option(NFX_DATATYPES_BUILD_SAMPLES "Build samples" O
8686
option(NFX_DATATYPES_BUILD_BENCHMARKS "Build benchmarks" OFF )
8787
option(NFX_DATATYPES_BUILD_DOCUMENTATION "Build Doxygen documentation" OFF )
8888
89-
# Installation
90-
option(NFX_DATATYPES_INSTALL_PROJECT "Install project" OFF )
89+
# Performance options
90+
option(NFX_DATATYPES_ENABLE_NATIVE_OPTS "Enable native CPU optimizations" ON )
9191
92-
# Packaging
92+
# Installation and packaging
93+
option(NFX_DATATYPES_INSTALL_PROJECT "Install project" OFF )
9394
option(NFX_DATATYPES_PACKAGE_SOURCE "Enable source package generation" OFF )
94-
option(NFX_DATATYPES_PACKAGE_ARCHIVE "Enable TGZ/ZIP package generation" OFF )
95-
option(NFX_DATATYPES_PACKAGE_DEB "Enable DEB package generation" OFF )
96-
option(NFX_DATATYPES_PACKAGE_RPM "Enable RPM package generation" OFF )
97-
option(NFX_DATATYPES_PACKAGE_WIX "Enable WiX MSI installer" OFF )
9895
```
9996

10097
### Using in Your Project
@@ -380,56 +377,6 @@ Sum: 1111111110111111111011111111100
380377
Equals 0.3? Yes
381378
```
382379

383-
## Installation & Packaging
384-
385-
nfx-datatypes provides packaging options for distribution.
386-
387-
### Package Generation
388-
389-
```bash
390-
# Configure with packaging options
391-
cmake .. -DCMAKE_BUILD_TYPE=Release \
392-
-DNFX_DATATYPES_BUILD_STATIC=ON \
393-
-DNFX_DATATYPES_BUILD_SHARED=ON \
394-
-DNFX_DATATYPES_PACKAGE_ARCHIVE=ON \
395-
-DNFX_DATATYPES_PACKAGE_DEB=ON \
396-
-DNFX_DATATYPES_PACKAGE_RPM=ON
397-
398-
# Generate binary packages
399-
cmake --build . --target package
400-
# or
401-
cd build && cpack
402-
403-
# Generate source packages
404-
cd build && cpack --config CPackSourceConfig.cmake
405-
```
406-
407-
### Supported Package Formats
408-
409-
| Format | Platform | Description | Requirements |
410-
| ----------- | -------------- | ---------------------------------- | ------------ |
411-
| **TGZ/ZIP** | Cross-platform | Compressed archive packages | None |
412-
| **DEB** | Debian/Ubuntu | Native Debian packages | `dpkg-dev` |
413-
| **RPM** | RedHat/SUSE | Native RPM packages | `rpm-build` |
414-
| **WiX** | Windows | Professional MSI installer | `WiX 3.11+` |
415-
| **Source** | Cross-platform | Source code distribution (TGZ+ZIP) | None |
416-
417-
### Installation
418-
419-
```bash
420-
# Linux (DEB-based systems)
421-
sudo dpkg -i nfx-datatypes_*_amd64.deb
422-
423-
# Linux (RPM-based systems)
424-
sudo rpm -ivh nfx-datatypes-*-Linux.rpm
425-
426-
# Windows (MSI installer)
427-
nfx-datatypes-0.1.0-MSVC.msi
428-
429-
# Manual installation (extract archive)
430-
tar -xzf nfx-datatypes-*-Linux.tar.gz -C /usr/local/
431-
```
432-
433380
## Project Structure
434381

435382
```
@@ -469,4 +416,4 @@ All dependencies are automatically fetched via CMake FetchContent when building
469416

470417
---
471418

472-
_Updated on November 24, 2025_
419+
_Updated on Februrary 15, 2026_

cmake/nfxDataTypesTargets.cmake

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ function(configure_target target_name)
5454
${NFX_DATATYPES_SOURCE_DIR}
5555
)
5656

57+
# --- C++20 standard ---
58+
target_compile_features(${target_name}
59+
PUBLIC
60+
cxx_std_20
61+
)
62+
5763
# --- Properties ---
5864
set_target_properties(${target_name}
5965
PROPERTIES
@@ -66,12 +72,14 @@ function(configure_target target_name)
6672
POSITION_INDEPENDENT_CODE ON
6773
)
6874

69-
# --- Enable specific CPU features ---
70-
target_compile_options(${target_name}
71-
PRIVATE
72-
$<$<CXX_COMPILER_ID:MSVC>:/arch:AVX2>
73-
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-march=native>
74-
)
75+
# --- CPU optimizations (Release/RelWithDebInfo only) ---
76+
if(NFX_DATATYPES_ENABLE_NATIVE_OPTS)
77+
target_compile_options(${target_name}
78+
PRIVATE
79+
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>>:/arch:AVX2>
80+
$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>,$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>>:-march=native>
81+
)
82+
endif()
7583

7684
# --- Compiler warnings ---
7785
target_compile_options(${target_name}
@@ -102,3 +110,13 @@ endif()
102110
if(NFX_DATATYPES_BUILD_STATIC)
103111
configure_target(${PROJECT_NAME}-static)
104112
endif()
113+
114+
#----------------------------------------------
115+
# Build configuration summary
116+
#----------------------------------------------
117+
118+
if(NFX_DATATYPES_ENABLE_NATIVE_OPTS)
119+
message(STATUS "nfx-datatypes: Native CPU optimizations enabled (Release/RelWithDebInfo builds)")
120+
else()
121+
message(STATUS "nfx-datatypes: Native CPU optimizations disabled (suitable for WebAssembly)")
122+
endif()

0 commit comments

Comments
 (0)