123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- macro(fix_default_compiler_settings_)
- if (MSVC)
-
-
-
- foreach (flag_var
- CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
- CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
- if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt)
-
-
-
-
-
-
-
- string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
- endif()
-
-
- string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}")
-
-
-
- string(REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}")
- endforeach()
- endif()
- endmacro()
- macro(config_compiler_and_linker)
-
-
- unset(GTEST_HAS_PTHREAD)
- if (NOT gtest_disable_pthreads AND NOT MINGW)
-
- set(THREADS_PREFER_PTHREAD_FLAG ON)
- find_package(Threads)
- if (CMAKE_USE_PTHREADS_INIT)
- set(GTEST_HAS_PTHREAD ON)
- endif()
- endif()
- fix_default_compiler_settings_()
- if (MSVC)
-
-
- set(cxx_base_flags "-GS -W4 -WX -wd4251 -wd4275 -nologo -J -Zi")
- if (MSVC_VERSION LESS 1400)
-
-
- set(cxx_base_flags "${cxx_base_flags} -wd4800")
-
- set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512")
-
-
- set(cxx_base_flags "${cxx_base_flags} -wd4675")
- endif()
- if (MSVC_VERSION LESS 1500)
-
-
-
-
-
-
- set(cxx_base_flags "${cxx_base_flags} -wd4127")
- endif()
- if (NOT (MSVC_VERSION LESS 1700))
-
-
- set(cxx_base_flags "${cxx_base_flags} -wd4702")
- endif()
- set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
- set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
- set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
- set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0")
- set(cxx_no_rtti_flags "-GR-")
- elseif (CMAKE_COMPILER_IS_GNUCXX)
- set(cxx_base_flags "-Wall -Wshadow -Werror")
- if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
- set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else")
- endif()
- set(cxx_exception_flags "-fexceptions")
- set(cxx_no_exception_flags "-fno-exceptions")
-
-
-
- set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0")
- set(cxx_strict_flags
- "-Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
- set(cxx_exception_flags "-features=except")
-
-
- set(cxx_no_exception_flags "-features=no%except -DGTEST_HAS_EXCEPTIONS=0")
- set(cxx_no_rtti_flags "-features=no%rtti -DGTEST_HAS_RTTI=0")
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "VisualAge" OR
- CMAKE_CXX_COMPILER_ID STREQUAL "XL")
-
- set(cxx_exception_flags "-qeh")
- set(cxx_no_exception_flags "-qnoeh")
-
-
-
- set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0")
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP")
- set(cxx_base_flags "-AA -mt")
- set(cxx_exception_flags "-DGTEST_HAS_EXCEPTIONS=1")
- set(cxx_no_exception_flags "+noeh -DGTEST_HAS_EXCEPTIONS=0")
-
- set(cxx_no_rtti_flags "")
- endif()
-
- if (DEFINED GTEST_HAS_PTHREAD)
- set(GTEST_HAS_PTHREAD_MACRO "-DGTEST_HAS_PTHREAD=1")
- else()
- set(GTEST_HAS_PTHREAD_MACRO "-DGTEST_HAS_PTHREAD=0")
- endif()
- set(cxx_base_flags "${cxx_base_flags} ${GTEST_HAS_PTHREAD_MACRO}")
-
- set(cxx_exception "${cxx_base_flags} ${cxx_exception_flags}")
- set(cxx_no_exception
- "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}")
- set(cxx_default "${cxx_exception}")
- set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}")
- set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1")
-
- set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
- endmacro()
- function(cxx_library_with_type name type cxx_flags)
-
-
- add_library(${name} ${type} ${ARGN})
- set_target_properties(${name}
- PROPERTIES
- COMPILE_FLAGS "${cxx_flags}")
-
- set_target_properties(${name}
- PROPERTIES
- DEBUG_POSTFIX "d")
- if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED")
- set_target_properties(${name}
- PROPERTIES
- COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1")
- if (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
- target_compile_definitions(${name} INTERFACE
- $<INSTALL_INTERFACE:GTEST_LINKED_AS_SHARED_LIBRARY=1>)
- endif()
- endif()
- if (DEFINED GTEST_HAS_PTHREAD)
- if ("${CMAKE_VERSION}" VERSION_LESS "3.1.0")
- set(threads_spec ${CMAKE_THREAD_LIBS_INIT})
- else()
- set(threads_spec Threads::Threads)
- endif()
- target_link_libraries(${name} PUBLIC ${threads_spec})
- endif()
- endfunction()
- function(cxx_shared_library name cxx_flags)
- cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN})
- endfunction()
- function(cxx_library name cxx_flags)
- cxx_library_with_type(${name} "" "${cxx_flags}" ${ARGN})
- endfunction()
- function(cxx_executable_with_flags name cxx_flags libs)
- add_executable(${name} ${ARGN})
- if (MSVC AND (NOT (MSVC_VERSION LESS 1700)))
-
- set(cxx_flags "${cxx_flags} -bigobj")
- endif()
- if (cxx_flags)
- set_target_properties(${name}
- PROPERTIES
- COMPILE_FLAGS "${cxx_flags}")
- endif()
- if (BUILD_SHARED_LIBS)
- set_target_properties(${name}
- PROPERTIES
- COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
- endif()
-
-
- foreach (lib "${libs}")
- target_link_libraries(${name} ${lib})
- endforeach()
- endfunction()
- function(cxx_executable name dir libs)
- cxx_executable_with_flags(
- ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN})
- endfunction()
- find_package(PythonInterp)
- function(cxx_test_with_flags name cxx_flags libs)
- cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN})
- add_test(NAME ${name} COMMAND ${name})
- endfunction()
- function(cxx_test name libs)
- cxx_test_with_flags("${name}" "${cxx_default}" "${libs}"
- "test/${name}.cc" ${ARGN})
- endfunction()
- function(py_test name)
- if (PYTHONINTERP_FOUND)
- if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
- if (CMAKE_CONFIGURATION_TYPES)
-
-
-
- add_test(
- NAME ${name}
- COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
- --build_dir=${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> ${ARGN})
- else (CMAKE_CONFIGURATION_TYPES)
-
-
- add_test(
- NAME ${name}
- COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
- --build_dir=${CMAKE_CURRENT_BINARY_DIR} ${ARGN})
- endif (CMAKE_CONFIGURATION_TYPES)
- else (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
-
-
-
-
- add_test(
- ${name}
- ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
- --build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE} ${ARGN})
- endif (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
- endif(PYTHONINTERP_FOUND)
- endfunction()
- function(install_project)
- if(INSTALL_GTEST)
- install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
-
- install(TARGETS ${ARGN}
- EXPORT ${targets_export_name}
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
-
- foreach(t ${ARGN})
- set(configured_pc "${generated_dir}/${t}.pc")
- configure_file("${PROJECT_SOURCE_DIR}/cmake/${t}.pc.in"
- "${configured_pc}" @ONLY)
- install(FILES "${configured_pc}"
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
- endforeach()
- endif()
- endfunction()
|