CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # This file was generated from BUILD using tools/make_cmakelists.py.
  2. cmake_minimum_required(VERSION 3.1)
  3. if(${CMAKE_VERSION} VERSION_LESS 3.12)
  4. cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
  5. else()
  6. cmake_policy(VERSION 3.12)
  7. endif()
  8. cmake_minimum_required (VERSION 3.0)
  9. cmake_policy(SET CMP0048 NEW)
  10. project(upb)
  11. set(CMAKE_C_STANDARD 99)
  12. # Prevent CMake from setting -rdynamic on Linux (!!).
  13. SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  14. SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  15. # Set default build type.
  16. if(NOT CMAKE_BUILD_TYPE)
  17. message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
  18. set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
  19. "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
  20. FORCE)
  21. endif()
  22. # When using Ninja, compiler output won't be colorized without this.
  23. include(CheckCXXCompilerFlag)
  24. CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always SUPPORTS_COLOR_ALWAYS)
  25. if(SUPPORTS_COLOR_ALWAYS)
  26. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
  27. endif()
  28. # Implement ASAN/UBSAN options
  29. if(UPB_ENABLE_ASAN)
  30. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  31. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  32. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
  33. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
  34. endif()
  35. if(UPB_ENABLE_UBSAN)
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
  37. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  38. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
  39. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
  40. endif()
  41. include_directories(..)
  42. include_directories(../cmake)
  43. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  44. if(APPLE)
  45. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
  46. elseif(UNIX)
  47. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
  48. endif()
  49. enable_testing()
  50. add_library(port INTERFACE)
  51. add_library(upb
  52. ../upb/decode.c
  53. ../upb/decode_internal.h
  54. ../upb/encode.c
  55. ../upb/msg.c
  56. ../upb/msg_internal.h
  57. ../upb/table.c
  58. ../upb/table_internal.h
  59. ../upb/upb.c
  60. ../upb/upb_internal.h
  61. ../upb/decode.h
  62. ../upb/encode.h
  63. ../upb/msg.h
  64. ../upb/upb.h
  65. ../upb/upb.hpp)
  66. target_link_libraries(upb
  67. fastdecode
  68. port
  69. /third_party/utf8_range)
  70. add_library(fastdecode
  71. ../upb/decode.h
  72. ../upb/decode_internal.h
  73. ../upb/decode_fast.c
  74. ../upb/decode_fast.h
  75. ../upb/msg.h
  76. ../upb/msg_internal.h
  77. ../upb/upb_internal.h)
  78. target_link_libraries(fastdecode
  79. port
  80. table
  81. /third_party/utf8_range)
  82. add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
  83. target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
  84. table
  85. upb)
  86. add_library(reflection
  87. ../upb/def.c
  88. ../upb/msg.h
  89. ../upb/reflection.c
  90. ../upb/def.h
  91. ../upb/def.hpp
  92. ../upb/reflection.h
  93. ../upb/reflection.hpp)
  94. target_link_libraries(reflection
  95. descriptor_upb_proto
  96. port
  97. table
  98. upb)
  99. add_library(textformat
  100. ../upb/text_encode.c
  101. ../upb/text_encode.h)
  102. target_link_libraries(textformat
  103. port
  104. reflection)
  105. add_library(json
  106. ../upb/json_decode.c
  107. ../upb/json_encode.c
  108. ../upb/json_decode.h
  109. ../upb/json_encode.h)
  110. target_link_libraries(json
  111. port
  112. reflection
  113. upb)
  114. add_library(table INTERFACE)
  115. target_link_libraries(table INTERFACE
  116. port)