CMakeLists.txt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. if(NOT DEBUG)
  18. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
  19. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
  20. endif()
  21. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  22. include_directories(${PROJECT_SOURCE_DIR}/src)
  23. add_library(BUTIL_LIB OBJECT ${BUTIL_SOURCES})
  24. add_library(SOURCES_LIB OBJECT ${SOURCES})
  25. add_dependencies(SOURCES_LIB PROTO_LIB)
  26. # shared library needs POSITION_INDEPENDENT_CODE
  27. set_property(TARGET ${SOURCES_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
  28. set_property(TARGET ${BUTIL_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
  29. add_library(brpc-shared SHARED $<TARGET_OBJECTS:BUTIL_LIB>
  30. $<TARGET_OBJECTS:SOURCES_LIB>
  31. $<TARGET_OBJECTS:PROTO_LIB>)
  32. add_library(brpc-static STATIC $<TARGET_OBJECTS:BUTIL_LIB>
  33. $<TARGET_OBJECTS:SOURCES_LIB>
  34. $<TARGET_OBJECTS:PROTO_LIB>)
  35. target_link_libraries(brpc-shared ${DYNAMIC_LIB})
  36. if(BRPC_WITH_GLOG)
  37. target_link_libraries(brpc-shared ${GLOG_LIB})
  38. endif()
  39. if(BRPC_WITH_THRIFT)
  40. target_link_libraries(brpc-shared thrift)
  41. target_link_libraries(brpc-static thrift)
  42. endif()
  43. SET_TARGET_PROPERTIES(brpc-static PROPERTIES OUTPUT_NAME brpc CLEAN_DIRECT_OUTPUT 1)
  44. SET_TARGET_PROPERTIES(brpc-shared PROPERTIES OUTPUT_NAME brpc CLEAN_DIRECT_OUTPUT 1)
  45. # for protoc-gen-mcpack
  46. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output/bin)
  47. set(protoc_gen_mcpack_SOURCES
  48. ${PROJECT_SOURCE_DIR}/src/mcpack2pb/generator.cpp
  49. )
  50. add_executable(protoc-gen-mcpack ${protoc_gen_mcpack_SOURCES})
  51. target_link_libraries(protoc-gen-mcpack brpc-shared)
  52. #install directory
  53. install(TARGETS brpc-shared
  54. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  55. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  56. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  57. )
  58. install(TARGETS brpc-static
  59. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  60. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  61. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  62. )