From a75eee13257bfc0598b1e124c5e451734e886312 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 17 Mar 2016 09:11:13 +0100 Subject: [PATCH] Add DINDEXER_NATIVE_RELEASE cmake option. Allows to pass -march=native to dindxer projects and to libpqtypes. CMake min version raised to 3.3 since externalproject_add didn't support generator expressions prior to that version. --- CMakeLists.txt | 14 +++++++++++--- cmake/Modules/Buildlibpqtypes.cmake | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69755dc..366ec5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.3 FATAL_ERROR) set(bare_name "dindexer") project("${bare_name}-if" VERSION 0.1.4 LANGUAGES CXX C) list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) @@ -22,15 +22,21 @@ include(CPack) option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF) option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON) +option(DINDEXER_NATIVE_RELEASE "Pass the -march=native flag to the compiler for release builds" OFF) if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION_MAJOR EQUAL "5") option(DINDEXER_CXX11_ABI "Controls if _GLIBCXX_USE_CXX11_ABI gets set to 0 or not" ON) endif() +if(DINDEXER_NATIVE_RELEASE) + set(march_flag "-march=native") +else() + set(march_flag "") +endif() set(DINDEXER_ACTIONS_PATH "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Actions search path") string(REGEX MATCH "[^/].*" ACTIONS_PATH_INSTALL "${DINDEXER_ACTIONS_PATH}") set(DB_OWNER_NAME "$ENV{USER}" CACHE STRING "Name that will be used as the DB owner name") set(PROJECT_VERSION_BETA "1") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra -Wno-missing-field-initializers") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra -O3 -fomit-frame-pointer -Wno-missing-field-initializers") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra -O3 -fomit-frame-pointer -Wno-missing-field-initializers ${march_flag}") set(DINDEXER_PUB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") get_git_head_revision(GIT_REFSPEC PROJECT_VERSION_GIT) @@ -46,7 +52,7 @@ message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"") find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options) find_package(PostgreSQL 8.3 REQUIRED) find_package(YamlCpp 0.5.1 REQUIRED) -import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}") +import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}" "-O3 ${march_flag}") add_library(${PROJECT_NAME} INTERFACE) add_library(${bare_name}-inc INTERFACE) @@ -102,6 +108,8 @@ add_subdirectory(src/delete) add_subdirectory(src/query) add_subdirectory(src/locate) add_subdirectory(src/navigate) + +#Tests add_subdirectory(test/gtest) add_subdirectory(test/unit) diff --git a/cmake/Modules/Buildlibpqtypes.cmake b/cmake/Modules/Buildlibpqtypes.cmake index 7a07078..fc37ce0 100644 --- a/cmake/Modules/Buildlibpqtypes.cmake +++ b/cmake/Modules/Buildlibpqtypes.cmake @@ -1,6 +1,6 @@ include(ExternalProject) -function (import_libpqtypes_project PostgreSQL_INCLUDE_DIRS) +function (import_libpqtypes_project PostgreSQL_INCLUDE_DIRS RELEASE_C_FLAGS) #find_path(libpqtypes_base_path NAMES src/libpqtypes.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib NO_DEFAULT_PATH) file(GLOB_RECURSE libpqtypes_base_path "lib/**libpqtypes.h") @@ -13,7 +13,8 @@ function (import_libpqtypes_project PostgreSQL_INCLUDE_DIRS) DOWNLOAD_COMMAND "" SOURCE_DIR ${libpqtypes_base_path} PREFIX ${libpqtypes_prefix} - CONFIGURE_COMMAND ${libpqtypes_base_path}/configure --prefix ${libpqtypes_prefix} "CPPFLAGS=${libpqtypes_inc_dirs}" --quiet + CONFIGURE_COMMAND ${libpqtypes_base_path}/configure --prefix ${libpqtypes_prefix} "CPPFLAGS=${libpqtypes_inc_dirs}" + "CFLAGS=$<$:${RELEASE_C_FLAGS}>" --quiet BUILD_COMMAND ${MAKE} BUILD_IN_SOURCE 0 )