Skip to content

Commit 1fcd2e4

Browse files
committed
Merge remote-tracking branch 'github/pr/1425'
2 parents 34933ac + e286742 commit 1fcd2e4

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

CMakeLists.txt

+38-22
Original file line numberDiff line numberDiff line change
@@ -131,30 +131,33 @@ ELSE()
131131
MESSAGE(status "Skipping compiler version check.")
132132
ENDIF()
133133

134-
# Configure C++ and C standards
135-
IF(CMAKE_VERSION VERSION_LESS "3.1")
136-
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
137-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
138-
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
139-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
140-
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
141-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
142-
ELSE()
143-
MESSAGE(warning "C++ standard could not be set because compiler is not GNU, Clang or MSVC.")
144-
ENDIF()
134+
# Configure C++ standard if not externally specified (will actually be
135+
# set after CppUnit check below). Use the variable CMAKE_CXX_STANDARD
136+
# since it will actually be used for this purposes starting in CMake 3.1.
145137

146-
IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
147-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
148-
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
149-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
150-
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
151-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
152-
ELSE()
153-
MESSAGE(warning "C standard could not be set because compiler is not GNU, Clang or MSVC.")
154-
ENDIF()
155-
ELSE()
156-
SET(CMAKE_C_STANDARD 90)
138+
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
157139
SET(CMAKE_CXX_STANDARD 98)
140+
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
141+
SET(CMAKE_CXX_STANDARD 98)
142+
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
143+
SET(CMAKE_CXX_STANDARD 98)
144+
ELSE()
145+
message(warning "C++ standard could not be set because compiler is not GNU, Clang or MSVC.")
146+
ENDIF()
147+
148+
IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
149+
SET(CMAKE_C_STANDARD 99)
150+
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
151+
SET(CMAKE_C_STANDARD 99)
152+
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
153+
SET(CMAKE_C_STANDARD 11)
154+
ELSE()
155+
message(warning "C standard could not be set because compiler is not GNU, Clang or MSVC.")
156+
ENDIF()
157+
158+
# if cmake version is < 3.1, explicitly set C standard to use.
159+
IF(${CMAKE_VERSION} VERSION_LESS "3.1")
160+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c${CMAKE_C_STANDARD}")
158161
ENDIF()
159162

160163
########################################################################
@@ -369,6 +372,19 @@ GR_REGISTER_COMPONENT("testing-support" ENABLE_TESTING
369372
CPPUNIT_FOUND
370373
)
371374

375+
# check if CppUnit version is 1.14.0 or greater; requires c++11 ...
376+
377+
if(CPPUNIT_FOUND AND NOT "${CPPUNIT_VERSION}" VERSION_LESS "1.14.0")
378+
message(WARNING "\nWarning: CppUnit version is ${CPPUNIT_VERSION} which requires C++11 for building. Trying to set CMake internally to use C++11 ...")
379+
SET(CMAKE_CXX_STANDARD 11)
380+
endif()
381+
382+
# if cmake version is < 3.1, explicitly set C++ standard to use.
383+
384+
if(${CMAKE_VERSION} VERSION_LESS "3.1")
385+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD}")
386+
endif()
387+
372388
########################################################################
373389
# Add optional dlls specified in DLL_PATHS
374390
########################################################################

cmake/Modules/FindCppUnit.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ LIST(APPEND CPPUNIT_LIBRARIES ${CMAKE_DL_LIBS})
3737
INCLUDE(FindPackageHandleStandardArgs)
3838
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUNIT DEFAULT_MSG CPPUNIT_LIBRARIES CPPUNIT_INCLUDE_DIRS)
3939
MARK_AS_ADVANCED(CPPUNIT_LIBRARIES CPPUNIT_INCLUDE_DIRS)
40+
41+
42+
# set version to be useable by calling script
43+
44+
IF(CPPUNIT_FOUND)
45+
set(CPPUNIT_VERSION ${PC_CPPUNIT_VERSION} CACHE INTERNAL "CppUnit Version" FORCE)
46+
ENDIF()

0 commit comments

Comments
 (0)