commit 744f1e945bc8d1855394e7d5fc2175041335f3f8
parent 0d5a563350ab91d6ce768f8628fb0428245233aa
Author: [email protected] <[email protected]>
Date: Thu, 3 Nov 2016 08:16:03 +0300
Detect clang in CMakeLists.txt
Diffstat:
7 files changed, 126 insertions(+), 105 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -39,6 +39,10 @@ CTestTestfile.cmake
# build directory
build/
+build32/
+build64/
+cmake-build-debug/
+cmake-build-release/
# test directory
svg/
diff --git a/.travis.yml b/.travis.yml
@@ -3,7 +3,8 @@ matrix:
include:
- os: linux
compiler: clang
- sudo: false
+ sudo: required
+ dist: trusty
addons:
apt:
sources:
@@ -14,7 +15,7 @@ matrix:
- clang-3.8
- libmpfr-dev
env:
- - TEST=LINUX-X86-64 CMAKEARGS="-DCMAKE_CXX_COMPILER=clang++-3.8 -DCMAKE_C_COMPILER=clang-3.8 -DCMAKE_BUILD_TYPE=Release .."
+ - TEST=LINUX-X86-64 CMAKEARGS="-DCMAKE_CXX_COMPILER=clang++-3.8 -DCMAKE_BUILD_TYPE=Release .."
- os: linux
compiler: clang
sudo: required
@@ -25,7 +26,6 @@ matrix:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- - g++-5
- clang-3.8
- qemu
- g++-arm-linux-gnueabihf
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -23,46 +23,100 @@ if (CMAKE_VERSION VERSION_LESS "2.8.12")
endfunction(add_compile_options)
endif ()
-set(OPT_BITNESS "") # cmake -DOPT_BITNESS="-m32" or -m64
-set(OPT_STATIC "") # cmake -DOPT_STATIC="-static"
-
+#set(DISABLE_CLANG 1)
+
+if(NOT CMAKE_CXX_COMPILER)
+
+ if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles"
+ OR ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles"
+ OR ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles"
+ OR ${CMAKE_GENERATOR} STREQUAL "Ninja")
+
+ # Find clang and set as c++ compiler for MinGW, MSYS and Unix
+ # If clang is not found, leave default compiler (usually GCC)
+
+ if(NOT DISABLE_CLANG)
+ find_program(CLANG_CXX_PATH clang++-4.0)
+ find_program(CLANG_CXX_PATH clang++-3.9)
+ find_program(CLANG_CXX_PATH clang++-3.8)
+ find_program(CLANG_CXX_PATH clang++-3.7)
+ find_program(CLANG_CXX_PATH clang++-3.6)
+ find_program(CLANG_CXX_PATH clang++)
+
+ # If clang is found
+ if(CLANG_CXX_PATH)
+ set(CMAKE_CXX_COMPILER ${CLANG_CXX_PATH})
+ message(STATUS "Clang found")
+ else()
+ message(STATUS "Clang not found")
+ endif()
+
+ else()
+ message(STATUS "Clang disabled")
+ endif()
+
+ elseif (${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015"
+ OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015 Win64")
+
+ # Find LLVM-vs2014 toolset for MSVC
+ # If clang is not found, leave default Microsoft's cl.exe compiler
+
+ if(NOT DISABLE_CLANG)
+ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test_toolset")
+
+ # Check if toolset can be set
+ execute_process(COMMAND "${CMAKE_COMMAND}" -G "Visual Studio 14 2015" -T LLVM-vs2014 "${CMAKE_SOURCE_DIR}/cmake/test_toolset" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/test_toolset" RESULT_VARIABLE TOOLSET_EXISTS OUTPUT_QUIET ERROR_QUIET)
+
+ if(${TOOLSET_EXISTS} EQUAL 0)
+ set(CMAKE_GENERATOR_TOOLSET LLVM-vs2014)
+ message(STATUS "LLVM-vs2014 found")
+ else()
+ message(STATUS "LLVM-vs2014 not found")
+ endif()
+ else()
+ message(STATUS "LLVM-vs2014 disabled")
+ endif()
+
+ endif()
+endif()
+
+if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles"
+ OR ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles"
+ OR ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles"
+ OR ${CMAKE_GENERATOR} STREQUAL "Ninja")
+
+ if (CMAKE_CXX_COMPILER MATCHES "clang")
+ if (WIN32)
+ # On windows, clang requires --target
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --target=x86_64-w64-windows-gnu" CACHE STRING "cxx compile flags" FORCE)
+ endif()
+ endif()
+endif()
+
+####################################
+
+# Release build by default
if (CMAKE_BUILD_TYPE_INITIALIZED_TO_DEFAULT)
set(CMAKE_BUILD_TYPE Release)
endif ()
-if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles" OR ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles")
- set(OPT_TARGET "--target=x86_64-w64-windows-gnu")
- set(CMAKE_CXX_COMPILER clang++)
- set(CMAKE_C_COMPILER clang)
-else ()
- set(OPT_TARGET "") # default target
-endif ()
+# Only Debug and Release builds
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "config types" FORCE)
-if (${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015")
- set(CMAKE_GENERATOR_TOOLSET LLVM-vs2014)
- set(CMAKE_SUPPRESS_REGENERATION true)
- add_definitions(-D_CRT_SECURE_NO_WARNINGS=1
- -Wno-unused-function
- -Wno-unused-variable
- -Wno-unused-const-variable
- -Wno-unused-command-line-argument)
-endif ()
-set(CMAKE_CXX_FLAGS "${OPT_TARGET} ${OPT_BITNESS} ${OPT_STATIC}" CACHE STRING "compile flags" FORCE)
-set(CMAKE_C_FLAGS "${OPT_TARGET} ${OPT_BITNESS} ${OPT_STATIC}" CACHE STRING "compile flags" FORCE)
-#set(CMAKE_EXE_LINKER_FLAGS "${OPT_TARGET} ${OPT_BITNESS}")
-#set(CMAKE_SHARED_LINKER_FLAGS "${OPT_TARGET} ${OPT_BITNESS}")
-#set(CMAKE_STATIC_LINKER_FLAGS "${OPT_TARGET} ${OPT_BITNESS}")
+# Insert common c++ flags here
+set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS}" CACHE STRING "compile flags" FORCE)
+
+project(kfr CXX)
-project(kfr)
+message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} ${CMAKE_CXX_COMPILER} ")
+# Binary output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin/Debug)
+# Include list of source files
include(sources.cmake)
-set(ALL_WARNINGS -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c99-extensions -Wno-padded)
-
if (IOS)
set(STD_LIB)
else ()
@@ -70,13 +124,30 @@ else ()
endif ()
if (NOT MSVC)
- add_compile_options(-std=c++1y)
+ # Enable C++14, disable exceptions and rtti
+ add_compile_options(-std=c++1y -fno-exceptions -fno-rtti )
+ if (NOT ARCH_FLAGS)
+ add_compile_options(-march=native)
+ if(WIN32)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign -fno-asynchronous-unwind-tables")
+ endif()
+ else ()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
+ endif ()
+ link_libraries(${STD_LIB} pthread m)
else ()
- add_compile_options(/EHsc /D_HAS_EXCEPTIONS=0)
+ # Disable exceptions
+ add_compile_options(/EHsc /D_HAS_EXCEPTIONS=0 /D_CRT_SECURE_NO_WARNINGS=1)
+ add_compile_options(/arch:AVX)
endif ()
-add_subdirectory(examples)
-add_subdirectory(tests)
+if ("${CMAKE_GENERATOR_TOOLSET}" STREQUAL "LLVM-vs2014")
+ add_compile_options( -Wno-unused-command-line-argument )
+endif()
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tests/cmake/")
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/svg)
+add_subdirectory(examples)
+add_subdirectory(tests)
diff --git a/build.py b/build.py
@@ -23,6 +23,7 @@ import os
import multiprocessing
import subprocess
import sys
+from timeit import default_timer as timer
path = os.path.dirname(os.path.realpath(__file__))
build_dir = os.path.join(path, 'build')
@@ -35,50 +36,20 @@ except:
options = [
'-DCMAKE_BUILD_TYPE=Release',
]
-
-CMAKE_C_COMPILER = ''
-CMAKE_CXX_COMPILER = ''
-
-for v in ('clang-3.9', 'clang-3.8', 'clang-3.7', 'clang'):
- print('Checking ', v, '...', end=' ')
- try:
- if subprocess.call([v, '--version'], stdout=subprocess.PIPE) == 0:
- CMAKE_C_COMPILER = v
- break
- except:
- pass
-
-if not CMAKE_C_COMPILER:
- raise Exception('clang is not on your PATH')
-print('ok')
-
-for v in ('clang++-3.9', 'clang++-3.8', 'clang++-3.7', 'clang++'):
- print('Checking ', v, '...', end=' ')
- try:
- if subprocess.call([v, '--version'], stdout=subprocess.PIPE) == 0:
- CMAKE_CXX_COMPILER = v
- break
- except:
- pass
-
-if not CMAKE_CXX_COMPILER:
- raise Exception('clang++ is not on your PATH')
-
-print('ok')
-
-options.append('-DCMAKE_C_COMPILER='+CMAKE_C_COMPILER)
-options.append('-DCMAKE_CXX_COMPILER='+CMAKE_CXX_COMPILER)
if sys.platform.startswith('win32'):
generator = 'MinGW Makefiles'
else:
generator = 'Unix Makefiles'
-threads = int(multiprocessing.cpu_count() * 1.5)
+threads = int(multiprocessing.cpu_count() * 1.2)
print('threads = ', threads)
threads = str(threads)
if subprocess.call(['cmake', '-G', generator, '..'] + options, cwd=build_dir): raise Exception('Can\'t make project')
+start = timer()
if subprocess.call(['cmake', '--build', '.', '--', '-j' + threads], cwd=build_dir): raise Exception('Can\'t build project')
+end = timer()
+print('Project building time: ', end - start)
if subprocess.call(['ctest'], cwd=os.path.join(build_dir, 'tests')): raise Exception('Can\'t test project')
diff --git a/cmake/test_toolset/CMakeLists.txt b/cmake/test_toolset/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+
+project(test_toolset CXX)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
@@ -17,18 +17,6 @@
cmake_minimum_required(VERSION 2.8)
-if (NOT MSVC)
- add_compile_options(-fno-exceptions -fno-rtti)
- if (NOT ARCH_FLAGS)
- add_compile_options(-march=native)
- else ()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
- endif ()
- link_libraries(${STD_LIB} pthread)
-else ()
- add_compile_options(/arch:AVX)
-endif ()
-
include_directories(../include)
add_executable(biquads biquads.cpp ${KFR_SRC})
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
@@ -21,31 +21,20 @@ set(TEST_SRC
testo/testo.hpp
)
-if (NOT MSVC)
- add_compile_options(-fno-exceptions -fno-rtti -ftemplate-backtrace-limit=0)
- link_libraries(${STD_LIB} pthread m)
-endif ()
-
include_directories(../include)
if (NOT ARM)
- add_executable(multiarch multiarch.cpp multiarch_fir_sse2.cpp multiarch_fir_avx.cpp ${KFR_SRC})
- set_source_files_properties(multiarch_fir_sse2.cpp PROPERTIES COMPILE_FLAGS "-mno-avx -mno-sse3 -msse2")
- set_source_files_properties(multiarch_fir_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
-endif ()
-
-if (NOT MSVC)
- if (NOT ARCH_FLAGS)
- add_compile_options(-march=native)
- else ()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
- endif ()
-else ()
- add_compile_options(/arch:AVX)
+ if(MSVC)
+ add_executable(multiarch multiarch.cpp multiarch_fir_sse2.cpp multiarch_fir_avx.cpp ${KFR_SRC})
+ set_source_files_properties(multiarch_fir_sse2.cpp PROPERTIES COMPILE_FLAGS /arch:SSE2)
+ set_source_files_properties(multiarch_fir_avx.cpp PROPERTIES COMPILE_FLAGS /arch:AVX)
+ else()
+ add_executable(multiarch multiarch.cpp multiarch_fir_sse2.cpp multiarch_fir_avx.cpp ${KFR_SRC})
+ set_source_files_properties(multiarch_fir_sse2.cpp PROPERTIES COMPILE_FLAGS "-mno-avx -mno-sse3 -msse2")
+ set_source_files_properties(multiarch_fir_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx -mno-avx2")
+ endif()
endif ()
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tests/cmake/")
-
find_package(MPFR)
add_executable(intrinsic_test intrinsic_test.cpp ${KFR_SRC} ${TEST_SRC})
@@ -67,11 +56,6 @@ else ()
set(EMULATOR "")
endif ()
-#get_cmake_property(_variableNames VARIABLES)
-#foreach (_variableName ${_variableNames})
-# message(STATUS "${_variableName}=${${_variableName}}")
-#endforeach()
-
if (NOT IOS)
enable_testing()