0001-CMake-make-shared-static-target-a-configurable-optio.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 9462847f23a25524fdc2112cbc8de3f2c02a1669 Mon Sep 17 00:00:00 2001
  2. From: Jan Heylen <jan.heylen@nokia.com>
  3. Date: Fri, 22 Dec 2017 22:04:29 +0100
  4. Subject: [PATCH] CMake: make shared/static target a configurable option
  5. Signed-off-by: Jan Heylen <jan.heylen@nokia.com>
  6. ---
  7. CMakeLists.txt | 40 ++++++++++++++++++++++++++++------------
  8. 1 file changed, 28 insertions(+), 12 deletions(-)
  9. diff --git a/CMakeLists.txt b/CMakeLists.txt
  10. index aadf2f9..d03bd00 100644
  11. --- a/CMakeLists.txt
  12. +++ b/CMakeLists.txt
  13. @@ -70,18 +70,36 @@ endif()
  14. include_directories(include)
  15. include_directories(SYSTEM 3rd_party/include)
  16. +option(BUILD_SHARED_LIBS "Build as a shared library" ON)
  17. +option(BUILD_STATIC_LIBS "Build as a static library" ON)
  18. +
  19. +if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
  20. + message(FATAL_ERROR "One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build")
  21. +endif()
  22. +
  23. set(SRCS src/propagation.cpp src/noop.cpp src/tracer.cpp)
  24. -add_library(opentracing SHARED ${SRCS})
  25. -target_include_directories(opentracing INTERFACE "$<INSTALL_INTERFACE:include/>")
  26. -set_target_properties(opentracing PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
  27. +
  28. +if (BUILD_SHARED_LIBS)
  29. + add_library(opentracing SHARED ${SRCS})
  30. + target_include_directories(opentracing INTERFACE "$<INSTALL_INTERFACE:include/>")
  31. + set_target_properties(opentracing PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
  32. SOVERSION ${OPENTRACING_VERSION_MAJOR})
  33. -add_library(opentracing-static STATIC ${SRCS})
  34. -set_target_properties(opentracing-static PROPERTIES OUTPUT_NAME opentracing)
  35. -target_include_directories(opentracing-static INTERFACE "$<INSTALL_INTERFACE:include/>")
  36. -if (CLANG_TIDY_EXE)
  37. - set_target_properties(opentracing PROPERTIES
  38. + install(TARGETS opentracing EXPORT OpenTracingTargets
  39. + LIBRARY DESTINATION lib
  40. + ARCHIVE DESTINATION lib)
  41. + if (CLANG_TIDY_EXE)
  42. + set_target_properties(opentracing PROPERTIES
  43. CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
  44. -endif()
  45. + endif()
  46. +endif(BUILD_SHARED_LIBS)
  47. +
  48. +if (BUILD_STATIC_LIBS)
  49. + add_library(opentracing-static STATIC ${SRCS})
  50. + set_target_properties(opentracing-static PROPERTIES OUTPUT_NAME opentracing)
  51. + target_include_directories(opentracing-static INTERFACE "$<INSTALL_INTERFACE:include/>")
  52. + install(TARGETS opentracing-static EXPORT OpenTracingTargets
  53. + ARCHIVE DESTINATION lib)
  54. +endif(BUILD_STATIC_LIBS)
  55. install(DIRECTORY 3rd_party/include/opentracing DESTINATION include
  56. @@ -89,9 +107,7 @@ install(DIRECTORY 3rd_party/include/opentracing DESTINATION include
  57. PATTERN "*.h")
  58. install(DIRECTORY include/opentracing DESTINATION include
  59. FILES_MATCHING PATTERN "*.h")
  60. -install(TARGETS opentracing opentracing-static EXPORT OpenTracingTargets
  61. - LIBRARY DESTINATION lib
  62. - ARCHIVE DESTINATION lib)
  63. +
  64. # ==============================================================================
  65. # Package configuration setup
  66. --
  67. 2.7.4