Fix clang compiler settings, and properly set up warnings so they don't interfere with gtest and gmock

This commit is contained in:
Jesse Beder 2014-03-24 23:34:26 -05:00
parent fe8ca77a1b
commit d59586630e
2 changed files with 31 additions and 14 deletions

View File

@ -68,6 +68,15 @@ else()
add_definitions(-DYAML_CPP_NO_CONTRIB) add_definitions(-DYAML_CPP_NO_CONTRIB)
endif() endif()
set(all_sources
${sources}
${public_headers}
${private_headers}
${contrib_sources}
${contrib_public_headers}
${contrib_private_headers}
)
if(VERBOSE) if(VERBOSE)
message(STATUS "sources: ${sources}") message(STATUS "sources: ${sources}")
message(STATUS "public_headers: ${public_headers}") message(STATUS "public_headers: ${public_headers}")
@ -84,6 +93,9 @@ include_directories(${YAML_CPP_SOURCE_DIR}/src)
### ###
### General compilation settings ### General compilation settings
### ###
set(yaml_c_flags ${CMAKE_C_FLAGS})
set(yaml_cxx_flags ${CMAKE_CXX_FLAGS})
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
set(LABEL_SUFFIX "shared") set(LABEL_SUFFIX "shared")
else() else()
@ -110,8 +122,9 @@ if(WIN32)
endif() endif()
endif() endif()
# GCC specialities # GCC or Clang specialities
if(CMAKE_COMPILER_IS_GNUCXX) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
### General stuff ### General stuff
if(WIN32) if(WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix set(CMAKE_SHARED_LIBRARY_PREFIX "") # DLLs do not have a "lib" prefix
@ -137,7 +150,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}") set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
endif() endif()
# #
set(CMAKE_CXX_FLAGS "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${CMAKE_CXX_FLAGS}") set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${yaml_cxx_flags}")
### Make specific ### Make specific
if(${CMAKE_BUILD_TOOL} STREQUAL make OR ${CMAKE_BUILD_TOOL} STREQUAL gmake) if(${CMAKE_BUILD_TOOL} STREQUAL make OR ${CMAKE_BUILD_TOOL} STREQUAL gmake)
@ -175,7 +188,7 @@ if(MSVC)
endif() endif()
# correct linker options # correct linker options
foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS) foreach(flag_var yaml_c_flags yaml_cxx_flags)
foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO) foreach(config_name "" DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
set(var_name "${flag_var}") set(var_name "${flag_var}")
if(NOT "${config_name}" STREQUAL "") if(NOT "${config_name}" STREQUAL "")
@ -201,7 +214,7 @@ if(MSVC)
# /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx # /W3 = set warning level; see http://msdn.microsoft.com/en-us/library/thxezb7y.aspx
# /wd4127 = disable warning C4127 "conditional expression is constant"; see http://msdn.microsoft.com/en-us/library/6t66728h.aspx # /wd4127 = disable warning C4127 "conditional expression is constant"; see http://msdn.microsoft.com/en-us/library/6t66728h.aspx
# /wd4355 = disable warning C4355 "'this' : used in base member initializer list"; http://msdn.microsoft.com/en-us/library/3c594ae3.aspx # /wd4355 = disable warning C4355 "'this' : used in base member initializer list"; http://msdn.microsoft.com/en-us/library/3c594ae3.aspx
set(CMAKE_CXX_FLAGS "/W3 /wd4127 /wd4355 /D_SCL_SECURE_NO_WARNINGS ${CMAKE_CXX_FLAGS}") set(yaml_cxx_flags "/W3 /wd4127 /wd4355 /D_SCL_SECURE_NO_WARNINGS ${yaml_cxx_flags}")
endif() endif()
@ -229,13 +242,9 @@ set(_INSTALL_DESTINATIONS
### ###
### Library ### Library
### ###
add_library(yaml-cpp add_library(yaml-cpp ${all_sources})
${sources} set_target_properties(yaml-cpp PROPERTIES
${public_headers} COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
${private_headers}
${contrib_sources}
${contrib_public_headers}
${contrib_private_headers}
) )
set_target_properties(yaml-cpp PROPERTIES set_target_properties(yaml-cpp PROPERTIES

View File

@ -1,13 +1,18 @@
set(gtest_force_shared_crt ${MSVC_SHARED_RT} CACHE BOOL set(gtest_force_shared_crt ${MSVC_SHARED_RT} CACHE BOOL
"Use shared (DLL) run-time lib even when Google Test built as a static lib.") "Use shared (DLL) run-time lib even when Google Test built as a static lib.")
add_subdirectory(gmock-1.7.0) add_subdirectory(gmock-1.7.0)
include_directories(gmock-1.7.0/gtest/include) include_directories(SYSTEM gmock-1.7.0/gtest/include)
include_directories(gmock-1.7.0/include) include_directories(SYSTEM gmock-1.7.0/include)
if(WIN32 AND BUILD_SHARED_LIBS) if(WIN32 AND BUILD_SHARED_LIBS)
add_definitions("-DGTEST_LINKED_AS_SHARED_LIBRARY") add_definitions("-DGTEST_LINKED_AS_SHARED_LIBRARY")
endif() endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(yaml_test_flags "-Wno-c99-extensions")
endif()
file(GLOB test_headers [a-z_]*.h) file(GLOB test_headers [a-z_]*.h)
file(GLOB test_sources [a-z_]*.cpp integration/[a-z_]*.cpp) file(GLOB test_sources [a-z_]*.cpp integration/[a-z_]*.cpp)
file(GLOB test_core_sources core/[a-z]*.cpp) file(GLOB test_core_sources core/[a-z]*.cpp)
@ -20,6 +25,9 @@ add_executable(run-tests
${test_sources} ${test_sources}
${test_headers} ${test_headers}
) )
set_target_properties(run-tests PROPERTIES
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
)
target_link_libraries(run-tests yaml-cpp gtest gmock) target_link_libraries(run-tests yaml-cpp gtest gmock)
#add_test(yaml-reader-test run-tests) #add_test(yaml-reader-test run-tests)