SgFlags.cmake 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #.rst:
  2. # SgFlags
  3. # -------
  4. #
  5. # Compiler/linker warnings.
  6. #
  7. # Configures the compiler/linker flags.
  8. #
  9. # ::
  10. #
  11. # SG_PICKY_COMPILER - Enable/disable the compiler warnings.
  12. # _
  13. # ___ __ _ __ _ _ _(_)
  14. # / __|/ _` |/ _` | | | | |
  15. # \__ \ (_| | (_| | |_| | |
  16. # |___/\__,_|\__, |\__,_|_|
  17. # |___/
  18. #
  19. # Cross-platform library which helps to develop web servers or frameworks.
  20. #
  21. # Copyright (C) 2016-2024 Silvio Clecio <[email protected]>
  22. #
  23. # Sagui library is free software; you can redistribute it and/or
  24. # modify it under the terms of the GNU Lesser General Public
  25. # License as published by the Free Software Foundation; either
  26. # version 2.1 of the License, or (at your option) any later version.
  27. #
  28. # Sagui library is distributed in the hope that it will be useful,
  29. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. # Lesser General Public License for more details.
  32. #
  33. # You should have received a copy of the GNU Lesser General Public
  34. # License along with Sagui library; if not, write to the Free Software
  35. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  36. #
  37. #TODO: -fsanitize=address/leak
  38. if(__SG_FLAGS_INCLUDED)
  39. return()
  40. endif()
  41. set(__SG_FLAGS_INCLUDED ON)
  42. option(SG_PICKY_COMPILER "Enable picky compiler options" ON)
  43. if(MINGW)
  44. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
  45. endif()
  46. if(BUILD_TESTING AND NOT APPLE)
  47. set(CMAKE_EXE_LINKER_FLAGS
  48. "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition")
  49. endif()
  50. if(SG_PICKY_COMPILER)
  51. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
  52. #-Wsign-conversion - needs to fix (un)signed bugs in utstring.h
  53. set(CMAKE_C_FLAGS
  54. "${CMAKE_C_FLAGS} -Wall -Werror -Wextra -Wpedantic -Wdeclaration-after-statement -Wstrict-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline"
  55. )
  56. if(ANDROID)
  57. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-command-line-argument")
  58. endif()
  59. else()
  60. message(FATAL_ERROR "Unknown C compiler: ${CMAKE_C_COMPILER}")
  61. endif()
  62. endif()