Skip to content

Commit 02991d5

Browse files
authored
mostly making the code readable. change forced flush to only be activ… (#5)
* mostly making the code readable. change forced flush to only be activated if compiled for windows, where it actually matter. * Fixed DNDEBUG define typo. More Readability. Fixed more linter issues: mostly casting-related, but also unused vars * Accidentally an entire file * more cleaning, and notes about bugs that can be fixed
1 parent 6321645 commit 02991d5

29 files changed

+2601
-2595
lines changed

CMakeLists.txt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
cmake_minimum_required(VERSION 2.8.12)
22
project(dsd)
3-
3+
set(CMAKE_C_STANDARD 11)
4+
set(CMAKE_CXX_STANDARD 14)
45
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
5-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fomit-frame-pointer -ftree-vectorize")
6-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fomit-frame-pointer -ftree-vectorize")
76

8-
include(TargetArch)
9-
target_architecture(TARGET_ARCH)
107
option(NATIVE OFF)
11-
if (NATIVE)
12-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native")
13-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native")
14-
if (TARGET_ARCH STREQUAL "aarch64")
15-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=native")
16-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
8+
9+
if (NOT "Debug" STREQUAL "${CMAKE_BUILD_TYPE}")
10+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG -Ofast -Wall -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fomit-frame-pointer -ftree-vectorize")
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -Ofast -Wall -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fomit-frame-pointer -ftree-vectorize")
12+
include(TargetArch)
13+
target_architecture(TARGET_ARCH)
14+
if (NATIVE)
15+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native")
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native")
17+
if (TARGET_ARCH STREQUAL "aarch64")
18+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=native")
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
20+
endif()
1721
endif()
1822
endif()
1923

cmake/FindLibSndFile.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile)
1212
FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES})
1313

1414
include(FindPackageHandleStandardArgs)
15-
if (APPLE)
16-
find_package_handle_standard_args(LibSndFile DEFAULT_MSG LIBSNDFILE_LIBRARY
17-
LIBSNDFILE_INCLUDE_DIR)
18-
elseif (UNIX)
15+
16+
find_package_handle_standard_args(LibSndFile DEFAULT_MSG LIBSNDFILE_LIBRARY
17+
LIBSNDFILE_INCLUDE_DIR)
18+
19+
if (NOT LIBSNDFILE_FOUND)
1920
find_package_handle_standard_args(LIBSNDFILE DEFAULT_MSG LIBSNDFILE_LIBRARY
2021
LIBSNDFILE_INCLUDE_DIR)
21-
endif() #TODO elseif windows lol
22+
endif()

cmake/TargetArch.cmake

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Based on the Qt 5 processor detection code, so should be very accurate
2+
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
3+
# Currently handles arm (v5, v6, v7, and now, v8), x86 (32/64), ia64, and ppc (32/64)
4+
5+
# Regarding POWER/PowerPC, just as is noted in the Qt source,
6+
# "There are many more known variants/revisions that we do not handle/detect."
7+
8+
set(archdetect_c_code "
9+
#if defined(__aarch64__) || defined(_M_ARM64)
10+
#error cmake_ARCH aarch64
11+
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
12+
#error cmake_ARCH i386
13+
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
14+
#error cmake_ARCH x86_64
15+
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
16+
#error cmake_ARCH ia64
17+
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
18+
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
19+
|| defined(_M_MPPC) || defined(_M_PPC)
20+
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
21+
#error cmake_ARCH ppc64
22+
#else
23+
#error cmake_ARCH ppc
24+
#endif
25+
#else if defined(__arm__) || defined(__TARGET_ARCH_ARM)
26+
#if defined(__ARM_ARCH_7__) \\
27+
|| defined(__ARM_ARCH_7A__) \\
28+
|| defined(__ARM_ARCH_7R__) \\
29+
|| defined(__ARM_ARCH_7M__) \\
30+
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
31+
#error cmake_ARCH armv7
32+
#elif defined(__ARM_ARCH_6__) \\
33+
|| defined(__ARM_ARCH_6J__) \\
34+
|| defined(__ARM_ARCH_6T2__) \\
35+
|| defined(__ARM_ARCH_6Z__) \\
36+
|| defined(__ARM_ARCH_6K__) \\
37+
|| defined(__ARM_ARCH_6ZK__) \\
38+
|| defined(__ARM_ARCH_6M__) \\
39+
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
40+
#error cmake_ARCH armv6
41+
#elif defined(__ARM_ARCH_5TEJ__) \\
42+
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
43+
#error cmake_ARCH armv5
44+
#else
45+
#error cmake_ARCH arm
46+
#endif
47+
#endif
48+
49+
#error cmake_ARCH unknown
50+
")
51+
52+
# Set ppc_support to TRUE before including this file or ppc and ppc64
53+
# will be treated as invalid architectures since they are no longer supported by Apple
54+
55+
function(target_architecture output_var)
56+
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
57+
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
58+
# First let's normalize the order of the values
59+
60+
# Note that it's not possible to compile PowerPC applications if you are using
61+
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
62+
# disable it by default
63+
# See this page for more information:
64+
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
65+
66+
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
67+
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
68+
69+
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
70+
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
71+
set(osx_arch_ppc TRUE)
72+
elseif("${osx_arch}" STREQUAL "i386")
73+
set(osx_arch_i386 TRUE)
74+
elseif("${osx_arch}" STREQUAL "x86_64")
75+
set(osx_arch_x86_64 TRUE)
76+
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
77+
set(osx_arch_ppc64 TRUE)
78+
else()
79+
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
80+
endif()
81+
endforeach()
82+
83+
# Now add all the architectures in our normalized order
84+
if(osx_arch_ppc)
85+
list(APPEND ARCH ppc)
86+
endif()
87+
88+
if(osx_arch_i386)
89+
list(APPEND ARCH i386)
90+
endif()
91+
92+
if(osx_arch_x86_64)
93+
list(APPEND ARCH x86_64)
94+
endif()
95+
96+
if(osx_arch_ppc64)
97+
list(APPEND ARCH ppc64)
98+
endif()
99+
else()
100+
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
101+
102+
enable_language(C)
103+
104+
# Detect the architecture in a rather creative way...
105+
# This compiles a small C program which is a series of ifdefs that selects a
106+
# particular #error preprocessor directive whose message string contains the
107+
# target architecture. The program will always fail to compile (both because
108+
# file is not a valid C program, and obviously because of the presence of the
109+
# #error preprocessor directives... but by exploiting the preprocessor in this
110+
# way, we can detect the correct target architecture even when cross-compiling,
111+
# since the program itself never needs to be run (only the compiler/preprocessor)
112+
try_run(
113+
run_result_unused
114+
compile_result_unused
115+
"${CMAKE_BINARY_DIR}"
116+
"${CMAKE_BINARY_DIR}/arch.c"
117+
COMPILE_OUTPUT_VARIABLE ARCH
118+
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
119+
)
120+
121+
# Parse the architecture name from the compiler output
122+
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
123+
124+
# Get rid of the value marker leaving just the architecture name
125+
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
126+
127+
# If we are compiling with an unknown architecture this variable should
128+
# already be set to "unknown" but in the case that it's empty (i.e. due
129+
# to a typo in the code), then set it to unknown
130+
if (NOT ARCH)
131+
set(ARCH unknown)
132+
endif()
133+
endif()
134+
135+
set(${output_var} "${ARCH}" PARENT_SCOPE)
136+
endfunction()

0 commit comments

Comments
 (0)