Skip to content

Commit

Permalink
enable c++11 compilation and check for c++11 support
Browse files Browse the repository at this point in the history
added GCC  option to enable c++11 support
added try compile statement to check for c++11 support
with small test program for checking null pointer and new initializers
removed the obtaining of GCC version (no longer being used)
  • Loading branch information
thunder422 committed Aug 14, 2014
1 parent 7cbabf6 commit 18ed38e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
29 changes: 23 additions & 6 deletions CMakeLists.txt
Expand Up @@ -25,7 +25,29 @@ project(ibcp)

cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic-errors")
# enable all compiler warnings as errors, enable c++11 compilation
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic-errors -std=c++11"
)

# check for c++11 support
message(STATUS "Checking for working C++11 compiler: ${CMAKE_CXX_COMPILER}")
try_compile(CPP11_GOOD
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/test/cpp11.cpp
OUTPUT_VARIABLE OUTPUT
)
if (${CPP11_GOOD})
message(STATUS
"Checking for working C++11 compiler: ${CMAKE_CXX_COMPILER} -- works"
)
else ()
message(FATAL_ERROR
"The C++ compiler is not able to compile a simple C++11 test program.\n"
"It fails with the following output:\n"
"${OUTPUT}"
)
endif ()

# prevent in source directory builds
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
Expand All @@ -39,11 +61,6 @@ endif (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
find_package(Qt4 REQUIRED QtCore QtGui)
include(${QT_USE_FILE})

# check GCC versionn
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION
)

# ckeck is a specific build type is set in the environment
if (NOT $ENV{CMAKE_BUILD_TYPE} STREQUAL "")
if (NOT CMAKE_BUILD_TYPE)
Expand Down
18 changes: 18 additions & 0 deletions test/cpp11.cpp
@@ -0,0 +1,18 @@
#include <iostream>

int main()
{
// test initializers
int i {1};
double d {2.0};

// test initializer list
int a[] {1, 2, 3, 4};

// test nullptr
int *pi {nullptr};

pi = &i;

std::cout << d << a[1] << *pi << std::endl;
}

0 comments on commit 18ed38e

Please sign in to comment.