You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

108 lines
5.7 KiB

  1. # Initialize ######################################################################################
  2. Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE )
  3. Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC )
  4. Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS )
  5. If ( HAS_PEDANTIC )
  6. Pedantic_Apply_Flags ( ALL )
  7. EndIf ( )
  8. Option ( LIBHELLOWORLD_INSTALL_HEADER
  9. "Install headers of libhelloworld."
  10. ON )
  11. Option ( LIBHELLOWORLD_INSTALL_STATIC
  12. "Install static library of libhelloworld."
  13. ON )
  14. Option ( LIBHELLOWORLD_INSTALL_SHARED
  15. "Install shared library of libhelloworld."
  16. ON )
  17. Option ( LIBHELLOWORLD_INSTALL_DEBUG
  18. "Install the stripped debug informations of libhelloworld."
  19. OFF )
  20. Option ( LIBHELLOWORLD_NO_STRIP
  21. "Do not strip debug symbols from binary."
  22. OFF )
  23. # Object Library ##################################################################################
  24. Set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
  25. Set ( LIBHELLOWORLD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include )
  26. File ( GLOB_RECURSE LIBHELLOWORLD_HEADER_FILES ${LIBHELLOWORLD_INCLUDE_DIR}/*.h )
  27. File ( GLOB_RECURSE LIBHELLOWORLD_INLINE_FILES ${LIBHELLOWORLD_INCLUDE_DIR}/*.inl )
  28. File ( GLOB_RECURSE LIBHELLOWORLD_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )
  29. Add_Library ( libhelloworld-objects
  30. OBJECT
  31. ${LIBHELLOWORLD_HEADER_FILES}
  32. ${LIBHELLOWORLD_INLINE_FILES}
  33. ${LIBHELLOWORLD_SOURCE_FILES} )
  34. Target_Include_Directories ( libhelloworld-objects
  35. PUBLIC
  36. $<BUILD_INTERFACE:${LIBHELLOWORLD_INCLUDE_DIR}>
  37. $<INSTALL_INTERFACE:${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}> )
  38. # Static Library ##################################################################################
  39. Message ( WARNING "Please configure the output name of the static library target!" )
  40. Add_Library ( libhelloworld-static STATIC $<TARGET_OBJECTS:libhelloworld-objects> )
  41. Set_Target_Properties ( libhelloworld-static
  42. PROPERTIES
  43. OUTPUT_NAME "helloworld" )
  44. Target_Include_Directories ( libhelloworld-static
  45. PUBLIC
  46. $<BUILD_INTERFACE:${LIBHELLOWORLD_INCLUDE_DIR}>
  47. $<INSTALL_INTERFACE:${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}> )
  48. # Shared Library ##################################################################################
  49. Message ( WARNING "Please configure the output name of the shared library target!" )
  50. Add_Library ( libhelloworld-shared SHARED $<TARGET_OBJECTS:libhelloworld-objects> )
  51. Set_Target_Properties ( libhelloworld-shared
  52. PROPERTIES
  53. OUTPUT_NAME "helloworld" )
  54. Target_Include_Directories ( libhelloworld-shared
  55. PUBLIC
  56. $<BUILD_INTERFACE:${LIBHELLOWORLD_INCLUDE_DIR}>
  57. $<INSTALL_INTERFACE:${LIBHELLOWORLD_INSTALL_DIR_INCLUDE}> )
  58. # Optimization ####################################################################################
  59. If ( HAS_COTIRE )
  60. Cotire ( libhelloworld-objects )
  61. Cotire ( libhelloworld-static )
  62. Cotire ( libhelloworld-shared )
  63. EndIf ( )
  64. # Install #########################################################################################
  65. # Header
  66. If ( LIBHELLOWORLD_INSTALL_HEADER )
  67. Install ( FILES ${LIBHELLOWORLD_INCLUDE_DIR}/libhelloworld.h
  68. DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_INCLUDE} )
  69. Install ( DIRECTORY ${LIBHELLOWORLD_INCLUDE_DIR}/libhelloworld
  70. DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_INCLUDE} )
  71. EndIf ( )
  72. # Static
  73. If ( LIBHELLOWORLD_INSTALL_STATIC )
  74. Install ( TARGETS libhelloworld-static
  75. EXPORT libhelloworld
  76. DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_LIB} )
  77. EndIf ( )
  78. # Shared
  79. If ( LIBHELLOWORLD_INSTALL_SHARED )
  80. Install ( TARGETS libhelloworld-shared
  81. EXPORT libhelloworld
  82. DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_LIB} )
  83. EndIf ( )
  84. # Debug
  85. If ( HAS_STRIP_SYMBOLS AND NOT LIBHELLOWORLD_NO_STRIP )
  86. Strip_Symbols ( libhelloworld-shared LIBHELLOWORLD_DBG_FILE )
  87. If ( LIBHELLOWORLD_INSTALL_DEBUG )
  88. Install ( FILES ${LIBHELLOWORLD_DBG_FILE}
  89. DESTINATION ${LIBHELLOWORLD_INSTALL_DIR_LIB} )
  90. EndIf ( )
  91. EndIf ( )