CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. cmake_minimum_required(VERSION 2.8.7)
  2. project(libogg)
  3. # Required modules
  4. include(GNUInstallDirs)
  5. include(CheckIncludeFiles)
  6. # Build options
  7. option(BUILD_SHARED_LIBS "Build shared library" OFF)
  8. if(APPLE)
  9. option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
  10. endif()
  11. # Extract project version from configure.ac
  12. file(READ configure.ac CONFIGURE_AC_CONTENTS)
  13. string(REGEX MATCH "AC_INIT\\(\\[libogg\\],\\[([0-9]*).([0-9]*).([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  14. set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
  15. set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
  16. set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
  17. set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
  18. # Helper function to get version-info
  19. function(get_version_info result current_var_name age_var_name revision_var_name)
  20. string(REGEX MATCH "${current_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  21. set(VERSION_INFO_CURRENT ${CMAKE_MATCH_1})
  22. string(REGEX MATCH "${age_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  23. set(VERSION_INFO_AGE ${CMAKE_MATCH_1})
  24. string(REGEX MATCH "${revision_var_name}=([0-9]*)" DUMMY ${CONFIGURE_AC_CONTENTS})
  25. set(VERSION_INFO_REVISION ${CMAKE_MATCH_1})
  26. math(EXPR VERSION_INFO_CURRENT_MINUS_AGE "${VERSION_INFO_CURRENT} - ${VERSION_INFO_AGE}")
  27. set(${result} "${VERSION_INFO_CURRENT_MINUS_AGE}.${VERSION_INFO_AGE}.${VERSION_INFO_REVISION}" PARENT_SCOPE)
  28. endfunction()
  29. # Helper function to configure pkg-config files
  30. function(configure_pkg_config_file pkg_config_file_in)
  31. set(prefix ${CMAKE_INSTALL_PREFIX})
  32. set(exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
  33. set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
  34. set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
  35. set(VERSION ${PROJECT_VERSION})
  36. string(REPLACE ".in" "" pkg_config_file ${pkg_config_file_in})
  37. configure_file(${pkg_config_file_in} ${CMAKE_CURRENT_BINARY_DIR}/${pkg_config_file} @ONLY)
  38. endfunction()
  39. message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}")
  40. # Configure config_type.h
  41. check_include_files(inttypes.h INCLUDE_INTTYPES_H)
  42. check_include_files(stdint.h INCLUDE_STDINT_H)
  43. check_include_files(sys/types.h INCLUDE_SYS_TYPES_H)
  44. set(SIZE16 int16_t)
  45. set(USIZE16 uint16_t)
  46. set(SIZE32 int32_t)
  47. set(USIZE32 uint32_t)
  48. set(SIZE64 int64_t)
  49. configure_file(include/ogg/config_types.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/ogg/config_types.h @ONLY)
  50. set(OGG_HEADERS
  51. ${CMAKE_CURRENT_BINARY_DIR}/include/ogg/config_types.h
  52. include/ogg/ogg.h
  53. include/ogg/os_types.h
  54. )
  55. set(OGG_SOURCES
  56. src/bitwise.c
  57. src/framing.c
  58. )
  59. if(MSVC)
  60. list(APPEND OGG_SOURCES win32/ogg.def)
  61. endif()
  62. if(BUILD_FRAMEWORK)
  63. set(BUILD_SHARED_LIBS TRUE)
  64. endif()
  65. add_library(ogg ${OGG_HEADERS} ${OGG_SOURCES})
  66. target_include_directories(ogg PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
  67. get_version_info(OGG_VERSION_INFO "LIB_CURRENT" "LIB_AGE" "LIB_REVISION")
  68. set_target_properties(
  69. ogg PROPERTIES
  70. SOVERSION ${OGG_VERSION_INFO}
  71. PUBLIC_HEADER "${OGG_HEADERS}"
  72. )
  73. if(BUILD_FRAMEWORK)
  74. set_target_properties(ogg PROPERTIES
  75. FRAMEWORK TRUE
  76. FRAMEWORK_VERSION ${PROJECT_VERSION}
  77. MACOSX_FRAMEWORK_IDENTIFIER org.xiph.ogg
  78. MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
  79. MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
  80. XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
  81. OUTPUT_NAME Ogg
  82. )
  83. endif()
  84. configure_pkg_config_file(ogg.pc.in)
  85. install(TARGETS ogg
  86. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  87. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  88. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  89. FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
  90. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ogg
  91. )
  92. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ogg.pc
  93. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
  94. )