summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Dickens <michael.dickens@ettus.com>2017-08-14 15:17:49 -0400
committerMichael Dickens <michael.dickens@ettus.com>2017-08-14 15:17:49 -0400
commit296be93db3396bef243c4a6dd54061de07f36079 (patch)
tree75f28a93cb488e9ee2619d287cdb32aa338c138c
parent26475d40e123a139cd7029c5172612d6f59d9fd3 (diff)
cmake: Fix for CppUnit and C++11
If CppUnit version >= 1.14.0, try to switch to C++11. Otherwise, use C++98 as before. Requires that FindCppUnit return the CppUnit version if found.
-rw-r--r--CMakeLists.txt37
-rw-r--r--cmake/Modules/FindCppUnit.cmake7
2 files changed, 34 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 650cfe3ac4..6bfb24e3e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,31 +56,35 @@ IF (NOT MSVC)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O2")
ENDIF()
-# Set C/C++ standard for all targets
-# NOTE: Starting with cmake v3.1 this should be used:
-# set(CMAKE_C_STANDARD 90)
-# set(CMAKE_CXX_STANDARD 98)
+# Configure C++ standard if not externally specified (will actually be
+# set after CppUnit check below). Use the variable CMAKE_CXX_STANDARD
+# since it will actually be used for this purposes starting in CMake 3.1.
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
+ SET(CMAKE_CXX_STANDARD 98)
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
+ SET(CMAKE_CXX_STANDARD 98)
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
+ SET(CMAKE_CXX_STANDARD 98)
ELSE()
message(warning "C++ standard could not be set because compiler is not GNU, Clang or MSVC.")
ENDIF()
IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+ SET(CMAKE_C_STANDARD 99)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+ SET(CMAKE_C_STANDARD 99)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
+ SET(CMAKE_C_STANDARD 11)
ELSE()
message(warning "C standard could not be set because compiler is not GNU, Clang or MSVC.")
ENDIF()
+# if cmake version is < 3.1, explicitly set C standard to use.
+IF(${CMAKE_VERSION} VERSION_LESS "3.1")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c${CMAKE_C_STANDARD}")
+ENDIF()
+
# Set cmake policies.
# This will suppress developer warnings during the cmake process that can occur
# if a newer cmake version than the minimum is used.
@@ -306,6 +310,19 @@ GR_REGISTER_COMPONENT("testing-support" ENABLE_TESTING
CPPUNIT_FOUND
)
+# check if CppUnit version is 1.14.0 or greater; requires c++11 ...
+
+if(CPPUNIT_FOUND AND NOT "${CPPUNIT_VERSION}" VERSION_LESS "1.14.0")
+ message(WARNING "\nWarning: CppUnit version is ${CPPUNIT_VERSION} which requires C++11 for building. Trying to set CMake internally to use C++11 ...")
+ SET(CMAKE_CXX_STANDARD 11)
+endif()
+
+# if cmake version is < 3.1, explicitly set C++ standard to use.
+
+if(${CMAKE_VERSION} VERSION_LESS "3.1")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD}")
+endif()
+
########################################################################
# Add optional dlls specified in DLL_PATHS
########################################################################
diff --git a/cmake/Modules/FindCppUnit.cmake b/cmake/Modules/FindCppUnit.cmake
index f93ade3412..4e9469f9f6 100644
--- a/cmake/Modules/FindCppUnit.cmake
+++ b/cmake/Modules/FindCppUnit.cmake
@@ -37,3 +37,10 @@ LIST(APPEND CPPUNIT_LIBRARIES ${CMAKE_DL_LIBS})
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUNIT DEFAULT_MSG CPPUNIT_LIBRARIES CPPUNIT_INCLUDE_DIRS)
MARK_AS_ADVANCED(CPPUNIT_LIBRARIES CPPUNIT_INCLUDE_DIRS)
+
+
+# set version to be useable by calling script
+
+IF(CPPUNIT_FOUND)
+ set(CPPUNIT_VERSION ${PC_CPPUNIT_VERSION} CACHE INTERNAL "CppUnit Version" FORCE)
+ENDIF()