Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
6b1a6958
Commit
6b1a6958
authored
Aug 01, 2014
by
Matt Clarkson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CMake function for adding compiler flags
parent
6945096b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
25 deletions
+48
-25
CMakeLists.txt
CMakeLists.txt
+9
-25
AddCXXCompilerFlag.cmake
cmake/AddCXXCompilerFlag.cmake
+39
-0
No files found.
CMakeLists.txt
View file @
6b1a6958
...
...
@@ -20,10 +20,8 @@ include_directories(${source_dir}/include)
ExternalProject_Get_Property
(
googletest binary_dir
)
link_directories
(
${
binary_dir
}
)
# Set up the compiler flags
include
(
CheckCXXCompilerFlag
)
# Enable the latest C++ standard possible
include
(
CheckCXXCompilerFlag
)
check_cxx_compiler_flag
(
--std=c++14 HAVE_FLAG_CXX_14
)
check_cxx_compiler_flag
(
--std=c++11 HAVE_FLAG_CXX_11
)
check_cxx_compiler_flag
(
--std=c++0x HAVE_FLAG_CXX_0X
)
...
...
@@ -36,32 +34,18 @@ elseif (HAVE_FLAG_CXX_0X)
endif
()
# Turn compiler warnings up to 11
check_cxx_compiler_flag
(
-Wall HAVE_FLAG_WALL
)
if
(
HAVE_FLAG_WALL
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wall"
)
endif
()
check_cxx_compiler_flag
(
-Wshadow HAVE_FLAG_WSHADOW
)
if
(
HAVE_FLAG_WSHADOW
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wshadow"
)
endif
()
check_cxx_compiler_flag
(
-Werror HAVE_FLAG_WERROR
)
if
(
HAVE_FLAG_WERROR
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Werror"
)
endif
()
check_cxx_compiler_flag
(
-pedantic-errors HAVE_FLAG_PEDANTIC_ERRORS
)
if
(
HAVE_FLAG_PEDANTIC_ERRORS
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-pedantic-errors"
)
endif
()
include
(
AddCXXCompilerFlag
)
add_cxx_compiler_flag
(
-Wall
)
add_cxx_compiler_flag
(
-Wshadow
)
add_cxx_compiler_flag
(
-Werror
)
add_cxx_compiler_flag
(
-pedantic-errors
)
# Release flags
add_cxx_compiler_flag
(
-fno-strict-aliasing RELEASE
)
# Add a debug definition so we can make decisions in the compilation
set
(
CMAKE_CXX_FLAGS_DEBUG
"
${
CMAKE_CXX_FLAGS_DEBUG
}
-DDEBUG"
)
# We relax the aliasing in release
check_cxx_compiler_flag
(
-fno-strict-aliasing HAVE_FLAG_NO_STRICT_ALIASING
)
if
(
HAVE_FLAG_NO_STRICT_ALIASING
)
set
(
CMAKE_CXX_FLAGS_RELEASE
"
${
CMAKE_CXX_FLAGS_RELEASE
}
-fno-strict-aliasing"
)
endif
()
# Set OS
if
(
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Darwin"
)
add_definitions
(
-DOS_MACOSX
)
...
...
cmake/AddCXXCompilerFlag.cmake
0 → 100644
View file @
6b1a6958
# - Adds a compiler FLAG if it is supported by the compiler
#
# This function checks that the supplied compiler FLAG is supported and then
# adds it to the corresponding compiler FLAGs
#
# add_cxx_compiler_FLAG(<FLAG> [<VARIANT>])
#
# - Example
#
# include(AddCXXCompilerFlag)
# add_cxx_compiler_FLAG(-Wall)
# add_cxx_compiler_FLAG(-no-strict-aliasing RELEASE)
# Requires CMake 2.6+
if
(
__add_cxx_compiler_FLAG
)
return
()
endif
()
set
(
__add_cxx_compiler_FLAG INCLUDED
)
include
(
CheckCXXCompilerFlag
)
function
(
add_cxx_compiler_flag FLAG
)
if
(
ARGV1
)
set
(
VARIANT
${
ARGV1
}
)
string
(
TOLOWER
${
VARIANT
}
VARIANT
)
set
(
VARIANT
"
${
VARIANT
}
"
)
endif
()
message
(
"-- Check compiler
${
VARIANT
}
flag
${
FLAG
}
"
)
string
(
TOUPPER
${
FLAG
}
SANITIZED_FLAG
)
string
(
REGEX REPLACE
"[^A-Za-z_0-9]"
"_"
${
SANITIZED_FLAG
}
SANITIZED_FLAG
)
check_cxx_compiler_flag
(
${
FLAG
}
${
SANITIZED_FLAG
}
)
if
(
${
SANITIZED_FLAG
}
)
message
(
"-- Check compiler
${
VARIANT
}
flag
${
FLAG
}
-- works"
)
string
(
REGEX REPLACE
"[^A-Za-z_0-9]"
"_"
"
${
VARIANT
}
"
VARIANT
)
string
(
TOUPPER
"
${
VARIANT
}
"
VARIANT
)
set
(
CMAKE_CXX_FLAGS
${
VARIANT
}
"
${
CMAKE_CXX_FLAGS
}${
VARIANT
}
${
FLAG
}
"
PARENT_SCOPE
)
endif
()
endfunction
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment