From 6c45e362c917c4b8b314670134b17cdc88f5140c Mon Sep 17 00:00:00 2001 From: christopher Date: Tue, 20 Feb 2018 15:08:41 +0100 Subject: [PATCH 1/3] include simd checks --- CMakeLists.txt | 386 ++++++++++++++-------------- cmake/CheckSimd.cmake | 87 +++++++ source/examples/simd/CMakeLists.txt | 252 +++++++++--------- 3 files changed, 409 insertions(+), 316 deletions(-) create mode 100644 cmake/CheckSimd.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c759ed3..0d9b89f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,193 +1,193 @@ - -# -# CMake options -# - -# CMake version -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) - -# -# Configure CMake environment -# - -# Register general cmake commands -include(cmake/Custom.cmake) - -# Set policies -set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. -set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. -set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. -set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. - -# Include cmake modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - -include(GenerateExportHeader) - -# Include custom cmake modules -include(cmake/GetGitRevisionDescription.cmake) -include(cmake/HealthCheck.cmake) -include(cmake/GenerateTemplateExportHeader.cmake) - - -# -# Project description and (meta) information -# - -# Get git revision -get_git_head_revision(GIT_REFSPEC GIT_SHA1) -string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) -if(NOT GIT_SHA1) - set(GIT_REV "0") -endif() - -# Meta information about the project -set(META_PROJECT_NAME "cppassist") -set(META_PROJECT_DESCRIPTION "C++ sanctuary for small but powerful and frequently required, stand alone features.") -set(META_AUTHOR_ORGANIZATION "CG Internals GmbH") -set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cppassist/") -set(META_AUTHOR_MAINTAINER "opensource@cginternals.com") -set(META_VERSION_MAJOR "0") -set(META_VERSION_MINOR "0") -set(META_VERSION_PATCH "0") -set(META_VERSION_REVISION "${GIT_REV}") -set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}") -set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})") -set(META_CMAKE_INIT_SHA "6a6f30b38a1cee31ccac3f091816f28e0f6bce4b") - -string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID) -string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID) - - -# -# Project configuration options -# - -# Project options -option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) -option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) -option(OPTION_BUILD_TESTS "Build tests." ON) -option(OPTION_BUILD_DOCS "Build documentation." OFF) -option(OPTION_BUILD_EXAMPLES "Build examples." OFF) -option(OPTION_BUILD_WITH_STD_REGEX "Use std::regex instead of boost" ON) - - -# -# Declare project -# - -# Generate folders for IDE targets (e.g., VisualStudio solutions) -set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set(IDE_FOLDER "") - -# Declare project -project(${META_PROJECT_NAME} C CXX) - -# Set output directories -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) - -# Create version file -file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") - - -# -# Compiler settings and options -# - -include(cmake/CompileOptions.cmake) - - -# -# Project Health Check Setup -# - -# Add cmake-init template check cmake targets -add_check_template_target(${META_CMAKE_INIT_SHA}) - -# Configure health check tools -enable_cppcheck(On) -enable_clang_tidy(On) - - -# -# Deployment/installation setup -# - -# Get project name -set(project ${META_PROJECT_NAME}) - -# Check for system dir install -set(SYSTEM_DIR_INSTALL FALSE) -if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") - set(SYSTEM_DIR_INSTALL TRUE) -endif() - -# Installation paths -if(UNIX AND SYSTEM_DIR_INSTALL) - # Install into the system (/usr/bin or /usr/local/bin) - set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/ - set(INSTALL_CMAKE "share/${project}/cmake") # /usr/[local]/share//cmake - set(INSTALL_EXAMPLES "share/${project}") # /usr/[local]/share/ - set(INSTALL_BIN "bin") # /usr/[local]/bin - set(INSTALL_SHARED "lib") # /usr/[local]/lib - set(INSTALL_LIB "lib") # /usr/[local]/lib - set(INSTALL_INCLUDE "include") # /usr/[local]/include - set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/ - set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications - set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps - set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts) -else() - # Install into local directory - set(INSTALL_ROOT ".") # ./ - set(INSTALL_CMAKE "cmake") # ./cmake - set(INSTALL_EXAMPLES ".") # ./ - set(INSTALL_BIN ".") # ./ - set(INSTALL_SHARED "lib") # ./lib - set(INSTALL_LIB "lib") # ./lib - set(INSTALL_INCLUDE "include") # ./include - set(INSTALL_DOC "doc") # ./doc - set(INSTALL_SHORTCUTS "misc") # ./misc - set(INSTALL_ICONS "misc") # ./misc - set(INSTALL_INIT "misc") # ./misc -endif() - -# Set runtime path -set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for BUILD -set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use CMAKE_INSTALL_RPATH for INSTALL -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # Do NOT add path to dependencies for INSTALL - -if(NOT SYSTEM_DIR_INSTALL) - # Find libraries relative to binary - if(APPLE) - set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}") - else() - set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") - endif() -endif() - - -# -# Project modules -# - -add_subdirectory(source) -add_subdirectory(docs) -add_subdirectory(deploy) - - -# -# Deployment (global project files) -# - -# Install version file -install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime) - -# Install cmake find script for the project -install(FILES ${META_PROJECT_NAME}-config.cmake DESTINATION ${INSTALL_ROOT} COMPONENT dev) - -# Install the project meta files -install(FILES AUTHORS DESTINATION ${INSTALL_ROOT} COMPONENT runtime) -install(FILES LICENSE DESTINATION ${INSTALL_ROOT} COMPONENT runtime) -install(FILES README.md DESTINATION ${INSTALL_ROOT} COMPONENT runtime) + +# +# CMake options +# + +# CMake version +cmake_minimum_required(VERSION 3.0 FATAL_ERROR) + +# +# Configure CMake environment +# + +# Register general cmake commands +include(cmake/Custom.cmake) + +# Set policies +set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. +set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. +set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. +set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. + +# Include cmake modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +include(GenerateExportHeader) + +# Include custom cmake modules +include(cmake/GetGitRevisionDescription.cmake) +include(cmake/HealthCheck.cmake) +include(cmake/GenerateTemplateExportHeader.cmake) + + +# +# Project description and (meta) information +# + +# Get git revision +get_git_head_revision(GIT_REFSPEC GIT_SHA1) +string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) +if(NOT GIT_SHA1) + set(GIT_REV "0") +endif() + +# Meta information about the project +set(META_PROJECT_NAME "cppassist") +set(META_PROJECT_DESCRIPTION "C++ sanctuary for small but powerful and frequently required, stand alone features.") +set(META_AUTHOR_ORGANIZATION "CG Internals GmbH") +set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cppassist/") +set(META_AUTHOR_MAINTAINER "opensource@cginternals.com") +set(META_VERSION_MAJOR "0") +set(META_VERSION_MINOR "0") +set(META_VERSION_PATCH "0") +set(META_VERSION_REVISION "${GIT_REV}") +set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}") +set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})") +set(META_CMAKE_INIT_SHA "6a6f30b38a1cee31ccac3f091816f28e0f6bce4b") + +string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID) +string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID) + + +# +# Project configuration options +# + +# Project options +option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) +option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) +option(OPTION_BUILD_TESTS "Build tests." ON) +option(OPTION_BUILD_DOCS "Build documentation." OFF) +option(OPTION_BUILD_EXAMPLES "Build examples." ON) +option(OPTION_BUILD_WITH_STD_REGEX "Use std::regex instead of boost" ON) + + +# +# Declare project +# + +# Generate folders for IDE targets (e.g., VisualStudio solutions) +set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(IDE_FOLDER "") + +# Declare project +project(${META_PROJECT_NAME} C CXX) + +# Set output directories +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +# Create version file +file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") + + +# +# Compiler settings and options +# + +include(cmake/CompileOptions.cmake) +include(cmake/CheckSimd.cmake) + +# +# Project Health Check Setup +# + +# Add cmake-init template check cmake targets +add_check_template_target(${META_CMAKE_INIT_SHA}) + +# Configure health check tools +enable_cppcheck(On) +enable_clang_tidy(On) + + +# +# Deployment/installation setup +# + +# Get project name +set(project ${META_PROJECT_NAME}) + +# Check for system dir install +set(SYSTEM_DIR_INSTALL FALSE) +if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") + set(SYSTEM_DIR_INSTALL TRUE) +endif() + +# Installation paths +if(UNIX AND SYSTEM_DIR_INSTALL) + # Install into the system (/usr/bin or /usr/local/bin) + set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/ + set(INSTALL_CMAKE "share/${project}/cmake") # /usr/[local]/share//cmake + set(INSTALL_EXAMPLES "share/${project}") # /usr/[local]/share/ + set(INSTALL_BIN "bin") # /usr/[local]/bin + set(INSTALL_SHARED "lib") # /usr/[local]/lib + set(INSTALL_LIB "lib") # /usr/[local]/lib + set(INSTALL_INCLUDE "include") # /usr/[local]/include + set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/ + set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications + set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps + set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts) +else() + # Install into local directory + set(INSTALL_ROOT ".") # ./ + set(INSTALL_CMAKE "cmake") # ./cmake + set(INSTALL_EXAMPLES ".") # ./ + set(INSTALL_BIN ".") # ./ + set(INSTALL_SHARED "lib") # ./lib + set(INSTALL_LIB "lib") # ./lib + set(INSTALL_INCLUDE "include") # ./include + set(INSTALL_DOC "doc") # ./doc + set(INSTALL_SHORTCUTS "misc") # ./misc + set(INSTALL_ICONS "misc") # ./misc + set(INSTALL_INIT "misc") # ./misc +endif() + +# Set runtime path +set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for BUILD +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use CMAKE_INSTALL_RPATH for INSTALL +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # Do NOT add path to dependencies for INSTALL + +if(NOT SYSTEM_DIR_INSTALL) + # Find libraries relative to binary + if(APPLE) + set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}") + else() + set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") + endif() +endif() + + +# +# Project modules +# + +add_subdirectory(source) +add_subdirectory(docs) +add_subdirectory(deploy) + + +# +# Deployment (global project files) +# + +# Install version file +install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime) + +# Install cmake find script for the project +install(FILES ${META_PROJECT_NAME}-config.cmake DESTINATION ${INSTALL_ROOT} COMPONENT dev) + +# Install the project meta files +install(FILES AUTHORS DESTINATION ${INSTALL_ROOT} COMPONENT runtime) +install(FILES LICENSE DESTINATION ${INSTALL_ROOT} COMPONENT runtime) +install(FILES README.md DESTINATION ${INSTALL_ROOT} COMPONENT runtime) diff --git a/cmake/CheckSimd.cmake b/cmake/CheckSimd.cmake new file mode 100644 index 0000000..8e16024 --- /dev/null +++ b/cmake/CheckSimd.cmake @@ -0,0 +1,87 @@ + +include(CheckCXXSourceRuns) + +# save old configuration +set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + +# set flags +set(AVX_FLAGS) +set(AVX2_FLAGS) +set(AVX512_FLAGS) +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") + set(AVX_FLAGS "/arch:AVX") + set(AVX2_FLAGS "/arch:AVX2") + # set(AVX512_FLAGS "/arch:AVX512") found no option for msvc +endif() +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(AVX_FLAGS "-mavx") + set(AVX2_FLAGS "-mavx2") + set(AVX512_FLAGS "-mavx512f" "-mavx512cd") # xeon processors have more flags +endif() + + +# check for AVX +set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS} ${AVX_FLAGS}) +CHECK_CXX_SOURCE_RUNS(" + #include + int main(){ + const float src[8] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float dst[8]; + __m256 a = _mm256_loadu_ps( src ); + __m256 b = _mm256_add_ps( a, a ); + _mm256_storeu_ps( dst, b ); + for( int i = 0; i < 8; i++ ) + if( ( src[i] + src[i] ) != dst[i] ) return -1; + return 0; + }" + AVX_ENABLED) +# remove flags if cpu does not support AVX +if(NOT AVX_ENABLED) + set(AVX_FLAGS "") +endif() + + +# check for AVX2 +set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS} ${AVX2_FLAGS}) +CHECK_CXX_SOURCE_RUNS(" + #include + int main(){ + const int src[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int dst[8]; + __m256i a = _mm256_loadu_si256( (__m256i*)src ); + __m256i b = _mm256_add_epi32( a, a ); + _mm256_storeu_si256( (__m256i*)dst, b ); + for( int i = 0; i < 8; i++ ) + if( ( src[i] + src[i] ) != dst[i] ) return -1; + return 0; + }" + AVX2_ENABLED) +# remove flags if cpu does not support AVX +if(NOT AVX2_ENABLED) + set(AVX2_FLAGS "") +endif() + + +# check for AVX512 +set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS} ${AVX512_FLAGS}) +CHECK_CXX_SOURCE_RUNS(" + #include + int main(){ + const int src[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 }; + int dst[16]; + __m512i a = _mm512_loadu_si512( (__m512i*)src ); + __m512i b = _mm512_add_epi32( a, a ); + _mm512_storeu_si512( (__m512i*)dst, b ); + for( int i = 0; i < 16; i++ ) + if( ( src[i] + src[i] ) != dst[i] ) return -1; + return 0; + }" + AVX512_ENABLED) +# remove flags if cpu does not support AVX +if(NOT AVX512_ENABLED) + set(AVX512_FLAGS "") +endif() + + +# restore previous state of cmake variable +set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) diff --git a/source/examples/simd/CMakeLists.txt b/source/examples/simd/CMakeLists.txt index f4ee332..8492182 100644 --- a/source/examples/simd/CMakeLists.txt +++ b/source/examples/simd/CMakeLists.txt @@ -1,123 +1,129 @@ - -# -# External dependencies -# - - -# -# Executable name and options -# - -# Target name -set(target simd-example) - -# Exit here if required dependencies are not met -message(STATUS "Example ${target}") - - -# -# Sources -# - -set(sources - main.cpp -) - - -# -# Create executable -# - -# Build executable -add_executable(${target} - ${sources} -) - -# Create namespaced alias -add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) - - -# -# Project options -# - -set_target_properties(${target} - PROPERTIES - ${DEFAULT_PROJECT_OPTIONS} - FOLDER "${IDE_FOLDER}" -) - - -# -# Include directories -# - -target_include_directories(${target} - PRIVATE - ${DEFAULT_INCLUDE_DIRECTORIES} - ${CMAKE_CURRENT_SOURCE_DIR} - ${PROJECT_BINARY_DIR}/source/include -) - - -# -# Libraries -# - -target_link_libraries(${target} - PRIVATE - ${DEFAULT_LIBRARIES} - ${META_PROJECT_NAME}::cppassist -) - - -# -# Compile definitions -# - -target_compile_definitions(${target} - PRIVATE - ${DEFAULT_COMPILE_DEFINITIONS} - SSE_ENABLED -) - - -# -# Compile options -# - -target_compile_options(${target} - PRIVATE - ${DEFAULT_COMPILE_OPTIONS} -) - - -# -# Linker options -# - -target_link_libraries(${target} - PRIVATE - ${DEFAULT_LINKER_OPTIONS} -) - - -# -# Target Health -# - -perform_health_checks( - ${target} - ${sources} -) - - -# -# Deployment -# - -# Executable -install(TARGETS ${target} - RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT examples - BUNDLE DESTINATION ${INSTALL_BIN} COMPONENT examples -) + +# +# External dependencies +# + + +# +# Executable name and options +# + +# Target name +set(target simd-example) + +# Exit here if required dependencies are not met +message(STATUS "Example ${target}") + + +# +# Sources +# + +set(sources + main.cpp +) + + +# +# Create executable +# + +# Build executable +add_executable(${target} + ${sources} +) + +# Create namespaced alias +add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + + +# +# Project options +# + +set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" +) + + +# +# Include directories +# + +target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_BINARY_DIR}/source/include +) + + +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + ${META_PROJECT_NAME}::cppassist +) + + +# +# Compile definitions +# + +target_compile_definitions(${target} + PRIVATE + ${DEFAULT_COMPILE_DEFINITIONS} + SSE_ENABLED + $<$:AVX_ENABLED> + $<$:AVX2_ENABLED> + $<$:AVX512_ENABLED> +) + + +# +# Compile options +# + +target_compile_options(${target} + PRIVATE + ${DEFAULT_COMPILE_OPTIONS} + ${AVX_FLAGS} + ${AVX2_FLAGS} + ${AVX512_FLAGS} +) + + +# +# Linker options +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + + +# +# Target Health +# + +perform_health_checks( + ${target} + ${sources} +) + + +# +# Deployment +# + +# Executable +install(TARGETS ${target} + RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT examples + BUNDLE DESTINATION ${INSTALL_BIN} COMPONENT examples +) From 8fd1f42a2861906a09e672ea01fba832d4a9e222 Mon Sep 17 00:00:00 2001 From: christopher Date: Tue, 20 Feb 2018 15:55:39 +0100 Subject: [PATCH 2/3] reset defaults --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d9b89f..13cd725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ option(BUILD_SHARED_LIBS "Build shared instead of static libraries." option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) option(OPTION_BUILD_TESTS "Build tests." ON) option(OPTION_BUILD_DOCS "Build documentation." OFF) -option(OPTION_BUILD_EXAMPLES "Build examples." ON) +option(OPTION_BUILD_EXAMPLES "Build examples." OFF) option(OPTION_BUILD_WITH_STD_REGEX "Use std::regex instead of boost" ON) From 9e38296a1a31271b800606e61dd9a0a56b4f5445 Mon Sep 17 00:00:00 2001 From: christopher Date: Tue, 20 Feb 2018 15:58:44 +0100 Subject: [PATCH 3/3] better line endings --- CMakeLists.txt | 386 ++++++++++++++-------------- source/examples/simd/CMakeLists.txt | 258 +++++++++---------- 2 files changed, 322 insertions(+), 322 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13cd725..3eff15b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,193 +1,193 @@ - -# -# CMake options -# - -# CMake version -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) - -# -# Configure CMake environment -# - -# Register general cmake commands -include(cmake/Custom.cmake) - -# Set policies -set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. -set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. -set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. -set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. - -# Include cmake modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - -include(GenerateExportHeader) - -# Include custom cmake modules -include(cmake/GetGitRevisionDescription.cmake) -include(cmake/HealthCheck.cmake) -include(cmake/GenerateTemplateExportHeader.cmake) - - -# -# Project description and (meta) information -# - -# Get git revision -get_git_head_revision(GIT_REFSPEC GIT_SHA1) -string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) -if(NOT GIT_SHA1) - set(GIT_REV "0") -endif() - -# Meta information about the project -set(META_PROJECT_NAME "cppassist") -set(META_PROJECT_DESCRIPTION "C++ sanctuary for small but powerful and frequently required, stand alone features.") -set(META_AUTHOR_ORGANIZATION "CG Internals GmbH") -set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cppassist/") -set(META_AUTHOR_MAINTAINER "opensource@cginternals.com") -set(META_VERSION_MAJOR "0") -set(META_VERSION_MINOR "0") -set(META_VERSION_PATCH "0") -set(META_VERSION_REVISION "${GIT_REV}") -set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}") -set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})") -set(META_CMAKE_INIT_SHA "6a6f30b38a1cee31ccac3f091816f28e0f6bce4b") - -string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID) -string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID) - - -# -# Project configuration options -# - -# Project options -option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) -option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) -option(OPTION_BUILD_TESTS "Build tests." ON) -option(OPTION_BUILD_DOCS "Build documentation." OFF) -option(OPTION_BUILD_EXAMPLES "Build examples." OFF) -option(OPTION_BUILD_WITH_STD_REGEX "Use std::regex instead of boost" ON) - - -# -# Declare project -# - -# Generate folders for IDE targets (e.g., VisualStudio solutions) -set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set(IDE_FOLDER "") - -# Declare project -project(${META_PROJECT_NAME} C CXX) - -# Set output directories -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) - -# Create version file -file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") - - -# -# Compiler settings and options -# - -include(cmake/CompileOptions.cmake) -include(cmake/CheckSimd.cmake) - -# -# Project Health Check Setup -# - -# Add cmake-init template check cmake targets -add_check_template_target(${META_CMAKE_INIT_SHA}) - -# Configure health check tools -enable_cppcheck(On) -enable_clang_tidy(On) - - -# -# Deployment/installation setup -# - -# Get project name -set(project ${META_PROJECT_NAME}) - -# Check for system dir install -set(SYSTEM_DIR_INSTALL FALSE) -if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") - set(SYSTEM_DIR_INSTALL TRUE) -endif() - -# Installation paths -if(UNIX AND SYSTEM_DIR_INSTALL) - # Install into the system (/usr/bin or /usr/local/bin) - set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/ - set(INSTALL_CMAKE "share/${project}/cmake") # /usr/[local]/share//cmake - set(INSTALL_EXAMPLES "share/${project}") # /usr/[local]/share/ - set(INSTALL_BIN "bin") # /usr/[local]/bin - set(INSTALL_SHARED "lib") # /usr/[local]/lib - set(INSTALL_LIB "lib") # /usr/[local]/lib - set(INSTALL_INCLUDE "include") # /usr/[local]/include - set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/ - set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications - set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps - set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts) -else() - # Install into local directory - set(INSTALL_ROOT ".") # ./ - set(INSTALL_CMAKE "cmake") # ./cmake - set(INSTALL_EXAMPLES ".") # ./ - set(INSTALL_BIN ".") # ./ - set(INSTALL_SHARED "lib") # ./lib - set(INSTALL_LIB "lib") # ./lib - set(INSTALL_INCLUDE "include") # ./include - set(INSTALL_DOC "doc") # ./doc - set(INSTALL_SHORTCUTS "misc") # ./misc - set(INSTALL_ICONS "misc") # ./misc - set(INSTALL_INIT "misc") # ./misc -endif() - -# Set runtime path -set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for BUILD -set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use CMAKE_INSTALL_RPATH for INSTALL -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # Do NOT add path to dependencies for INSTALL - -if(NOT SYSTEM_DIR_INSTALL) - # Find libraries relative to binary - if(APPLE) - set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}") - else() - set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") - endif() -endif() - - -# -# Project modules -# - -add_subdirectory(source) -add_subdirectory(docs) -add_subdirectory(deploy) - - -# -# Deployment (global project files) -# - -# Install version file -install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime) - -# Install cmake find script for the project -install(FILES ${META_PROJECT_NAME}-config.cmake DESTINATION ${INSTALL_ROOT} COMPONENT dev) - -# Install the project meta files -install(FILES AUTHORS DESTINATION ${INSTALL_ROOT} COMPONENT runtime) -install(FILES LICENSE DESTINATION ${INSTALL_ROOT} COMPONENT runtime) -install(FILES README.md DESTINATION ${INSTALL_ROOT} COMPONENT runtime) + +# +# CMake options +# + +# CMake version +cmake_minimum_required(VERSION 3.0 FATAL_ERROR) + +# +# Configure CMake environment +# + +# Register general cmake commands +include(cmake/Custom.cmake) + +# Set policies +set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. +set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. +set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. +set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. + +# Include cmake modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +include(GenerateExportHeader) + +# Include custom cmake modules +include(cmake/GetGitRevisionDescription.cmake) +include(cmake/HealthCheck.cmake) +include(cmake/GenerateTemplateExportHeader.cmake) + + +# +# Project description and (meta) information +# + +# Get git revision +get_git_head_revision(GIT_REFSPEC GIT_SHA1) +string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) +if(NOT GIT_SHA1) + set(GIT_REV "0") +endif() + +# Meta information about the project +set(META_PROJECT_NAME "cppassist") +set(META_PROJECT_DESCRIPTION "C++ sanctuary for small but powerful and frequently required, stand alone features.") +set(META_AUTHOR_ORGANIZATION "CG Internals GmbH") +set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cppassist/") +set(META_AUTHOR_MAINTAINER "opensource@cginternals.com") +set(META_VERSION_MAJOR "0") +set(META_VERSION_MINOR "0") +set(META_VERSION_PATCH "0") +set(META_VERSION_REVISION "${GIT_REV}") +set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}") +set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})") +set(META_CMAKE_INIT_SHA "6a6f30b38a1cee31ccac3f091816f28e0f6bce4b") + +string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID) +string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID) + + +# +# Project configuration options +# + +# Project options +option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) +option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) +option(OPTION_BUILD_TESTS "Build tests." ON) +option(OPTION_BUILD_DOCS "Build documentation." OFF) +option(OPTION_BUILD_EXAMPLES "Build examples." OFF) +option(OPTION_BUILD_WITH_STD_REGEX "Use std::regex instead of boost" ON) + + +# +# Declare project +# + +# Generate folders for IDE targets (e.g., VisualStudio solutions) +set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(IDE_FOLDER "") + +# Declare project +project(${META_PROJECT_NAME} C CXX) + +# Set output directories +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +# Create version file +file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") + + +# +# Compiler settings and options +# + +include(cmake/CompileOptions.cmake) +include(cmake/CheckSimd.cmake) + +# +# Project Health Check Setup +# + +# Add cmake-init template check cmake targets +add_check_template_target(${META_CMAKE_INIT_SHA}) + +# Configure health check tools +enable_cppcheck(On) +enable_clang_tidy(On) + + +# +# Deployment/installation setup +# + +# Get project name +set(project ${META_PROJECT_NAME}) + +# Check for system dir install +set(SYSTEM_DIR_INSTALL FALSE) +if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") + set(SYSTEM_DIR_INSTALL TRUE) +endif() + +# Installation paths +if(UNIX AND SYSTEM_DIR_INSTALL) + # Install into the system (/usr/bin or /usr/local/bin) + set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/ + set(INSTALL_CMAKE "share/${project}/cmake") # /usr/[local]/share//cmake + set(INSTALL_EXAMPLES "share/${project}") # /usr/[local]/share/ + set(INSTALL_BIN "bin") # /usr/[local]/bin + set(INSTALL_SHARED "lib") # /usr/[local]/lib + set(INSTALL_LIB "lib") # /usr/[local]/lib + set(INSTALL_INCLUDE "include") # /usr/[local]/include + set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/ + set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications + set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps + set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts) +else() + # Install into local directory + set(INSTALL_ROOT ".") # ./ + set(INSTALL_CMAKE "cmake") # ./cmake + set(INSTALL_EXAMPLES ".") # ./ + set(INSTALL_BIN ".") # ./ + set(INSTALL_SHARED "lib") # ./lib + set(INSTALL_LIB "lib") # ./lib + set(INSTALL_INCLUDE "include") # ./include + set(INSTALL_DOC "doc") # ./doc + set(INSTALL_SHORTCUTS "misc") # ./misc + set(INSTALL_ICONS "misc") # ./misc + set(INSTALL_INIT "misc") # ./misc +endif() + +# Set runtime path +set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for BUILD +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use CMAKE_INSTALL_RPATH for INSTALL +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # Do NOT add path to dependencies for INSTALL + +if(NOT SYSTEM_DIR_INSTALL) + # Find libraries relative to binary + if(APPLE) + set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}") + else() + set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") + endif() +endif() + + +# +# Project modules +# + +add_subdirectory(source) +add_subdirectory(docs) +add_subdirectory(deploy) + + +# +# Deployment (global project files) +# + +# Install version file +install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime) + +# Install cmake find script for the project +install(FILES ${META_PROJECT_NAME}-config.cmake DESTINATION ${INSTALL_ROOT} COMPONENT dev) + +# Install the project meta files +install(FILES AUTHORS DESTINATION ${INSTALL_ROOT} COMPONENT runtime) +install(FILES LICENSE DESTINATION ${INSTALL_ROOT} COMPONENT runtime) +install(FILES README.md DESTINATION ${INSTALL_ROOT} COMPONENT runtime) diff --git a/source/examples/simd/CMakeLists.txt b/source/examples/simd/CMakeLists.txt index 8492182..8899534 100644 --- a/source/examples/simd/CMakeLists.txt +++ b/source/examples/simd/CMakeLists.txt @@ -1,129 +1,129 @@ - -# -# External dependencies -# - - -# -# Executable name and options -# - -# Target name -set(target simd-example) - -# Exit here if required dependencies are not met -message(STATUS "Example ${target}") - - -# -# Sources -# - -set(sources - main.cpp -) - - -# -# Create executable -# - -# Build executable -add_executable(${target} - ${sources} -) - -# Create namespaced alias -add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) - - -# -# Project options -# - -set_target_properties(${target} - PROPERTIES - ${DEFAULT_PROJECT_OPTIONS} - FOLDER "${IDE_FOLDER}" -) - - -# -# Include directories -# - -target_include_directories(${target} - PRIVATE - ${DEFAULT_INCLUDE_DIRECTORIES} - ${CMAKE_CURRENT_SOURCE_DIR} - ${PROJECT_BINARY_DIR}/source/include -) - - -# -# Libraries -# - -target_link_libraries(${target} - PRIVATE - ${DEFAULT_LIBRARIES} - ${META_PROJECT_NAME}::cppassist -) - - -# -# Compile definitions -# - -target_compile_definitions(${target} - PRIVATE - ${DEFAULT_COMPILE_DEFINITIONS} - SSE_ENABLED - $<$:AVX_ENABLED> - $<$:AVX2_ENABLED> - $<$:AVX512_ENABLED> -) - - -# -# Compile options -# - -target_compile_options(${target} - PRIVATE - ${DEFAULT_COMPILE_OPTIONS} - ${AVX_FLAGS} - ${AVX2_FLAGS} - ${AVX512_FLAGS} -) - - -# -# Linker options -# - -target_link_libraries(${target} - PRIVATE - ${DEFAULT_LINKER_OPTIONS} -) - - -# -# Target Health -# - -perform_health_checks( - ${target} - ${sources} -) - - -# -# Deployment -# - -# Executable -install(TARGETS ${target} - RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT examples - BUNDLE DESTINATION ${INSTALL_BIN} COMPONENT examples -) + +# +# External dependencies +# + + +# +# Executable name and options +# + +# Target name +set(target simd-example) + +# Exit here if required dependencies are not met +message(STATUS "Example ${target}") + + +# +# Sources +# + +set(sources + main.cpp +) + + +# +# Create executable +# + +# Build executable +add_executable(${target} + ${sources} +) + +# Create namespaced alias +add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + + +# +# Project options +# + +set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" +) + + +# +# Include directories +# + +target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_BINARY_DIR}/source/include +) + + +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + ${META_PROJECT_NAME}::cppassist +) + + +# +# Compile definitions +# + +target_compile_definitions(${target} + PRIVATE + ${DEFAULT_COMPILE_DEFINITIONS} + SSE_ENABLED + $<$:AVX_ENABLED> + $<$:AVX2_ENABLED> + $<$:AVX512_ENABLED> +) + + +# +# Compile options +# + +target_compile_options(${target} + PRIVATE + ${DEFAULT_COMPILE_OPTIONS} + ${AVX_FLAGS} + ${AVX2_FLAGS} + ${AVX512_FLAGS} +) + + +# +# Linker options +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + + +# +# Target Health +# + +perform_health_checks( + ${target} + ${sources} +) + + +# +# Deployment +# + +# Executable +install(TARGETS ${target} + RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT examples + BUNDLE DESTINATION ${INSTALL_BIN} COMPONENT examples +)