utils.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright 2017 The Effcee Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Utility functions
  15. function(effcee_default_c_compile_options TARGET)
  16. if (NOT "${MSVC}")
  17. target_compile_options(${TARGET} PRIVATE -Wall -Werror)
  18. if (ENABLE_CODE_COVERAGE)
  19. # The --coverage option is a synonym for -fprofile-arcs -ftest-coverage
  20. # when compiling.
  21. target_compile_options(${TARGET} PRIVATE -g -O0 --coverage)
  22. # The --coverage option is a synonym for -lgcov when linking for gcc.
  23. # For clang, it links in a different library, libclang_rt.profile, which
  24. # requires clang to be built with compiler-rt.
  25. target_link_libraries(${TARGET} PRIVATE --coverage)
  26. endif()
  27. if (NOT EFFCEE_ENABLE_SHARED_CRT)
  28. if (WIN32)
  29. # For MinGW cross compile, statically link to the libgcc runtime.
  30. # But it still depends on MSVCRT.dll.
  31. set_target_properties(${TARGET} PROPERTIES
  32. LINK_FLAGS "-static -static-libgcc")
  33. endif(WIN32)
  34. endif(NOT EFFCEE_ENABLE_SHARED_CRT)
  35. if (UNIX AND NOT MINGW)
  36. target_link_libraries(${TARGET} PUBLIC -pthread)
  37. endif()
  38. if (${CMAKE_C_COMPILER_ID} MATCHES "Clang")
  39. target_compile_options(${TARGET} PRIVATE -Wextra-semi)
  40. endif()
  41. else()
  42. # disable warning C4800: 'int' : forcing value to bool 'true' or 'false'
  43. # (performance warning)
  44. target_compile_options(${TARGET} PRIVATE /wd4800)
  45. endif()
  46. endfunction(effcee_default_c_compile_options)
  47. function(effcee_default_compile_options TARGET)
  48. effcee_default_c_compile_options(${TARGET})
  49. # RE2's public header requires C++11. So publicly require C++11
  50. target_compile_features(${TARGET} PUBLIC cxx_std_11)
  51. if (NOT "${MSVC}")
  52. if (NOT EFFCEE_ENABLE_SHARED_CRT)
  53. if (WIN32)
  54. # For MinGW cross compile, statically link to the C++ runtime.
  55. # But it still depends on MSVCRT.dll.
  56. set_target_properties(${TARGET} PROPERTIES
  57. LINK_FLAGS "-static -static-libgcc -static-libstdc++")
  58. endif(WIN32)
  59. endif(NOT EFFCEE_ENABLE_SHARED_CRT)
  60. endif()
  61. endfunction(effcee_default_compile_options)