Here is a cmake module and sample program to optimize architecture features such as a SIMD extensions.
- Module
CMakeHostSystemInformationExtra
/functioncmake_host_system_information_extra()
is production ready on x86_64 and ARM platforms.- Tested on Linux, Mac, Windows with gcc, clang and icc on x86_64.
- Tested on Linux on ARM using AWS EC2 A1 instance.
- Module
CMakeCompilerMachineOption()
is experimental status.
-
Place cmake scripts under
Modules
folder in your project and add search path in yourCMakeLists.txt
by settingCMAKE_MODULE_PATH
variable. -
Include script using
include(CMakeHostSystemInformationExtra)
include(GetCPUSIMDFeatures)
include(CMakeCompilerMachineOption)
in your CMakeLists.txt
-
Call function
cmake_host_system_information_extra(RESULT <output variable name> QUERY <query> ...)
to detect host system information. -
Optimize compiler options
Here is an example to optimize example project for skylake generation of Intel CPU.
set(TARGET_ARCHITECTURE skylake)
cmake_compiler_machine_option(ARCHITECTURE_FLAG ${TARGET_ARCHITECTURE})
message(STATUS "Use compiler option: ${ARCHITECTURE_FLAG}")
add_executable(example example.c)
target_compile_options(example PRIVATE ${ARCHITECTURE_FLAG})
Please see CMakeLists.txt for more details.
This is distributed under OSI-Approved 3-Clause BSD license.