CMakeLists.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. cmake_minimum_required(VERSION 3.9.4)
  2. project(libnbt++
  3. VERSION 2.3)
  4. # supported configure options
  5. option(NBT_BUILD_SHARED "Build shared libraries" OFF)
  6. option(NBT_USE_ZLIB "Build additional zlib stream functionality" ON)
  7. option(NBT_BUILD_TESTS "Build the unit tests. Requires CxxTest." ON)
  8. if(NBT_NAME)
  9. message("Using override nbt++ name: ${NBT_NAME}")
  10. else()
  11. set(NBT_NAME nbt++)
  12. endif()
  13. # hide this from includers.
  14. set(BUILD_SHARED_LIBS ${NBT_BUILD_SHARED})
  15. include(GenerateExportHeader)
  16. set(NBT_SOURCES
  17. src/endian_str.cpp
  18. src/tag.cpp
  19. src/tag_compound.cpp
  20. src/tag_list.cpp
  21. src/tag_string.cpp
  22. src/value.cpp
  23. src/value_initializer.cpp
  24. src/io/stream_reader.cpp
  25. src/io/stream_writer.cpp
  26. src/text/json_formatter.cpp)
  27. set(NBT_SOURCES_Z
  28. src/io/izlibstream.cpp
  29. src/io/ozlibstream.cpp)
  30. if(NBT_USE_ZLIB)
  31. find_package(ZLIB REQUIRED)
  32. list(APPEND NBT_SOURCES ${NBT_SOURCES_Z})
  33. add_definitions("-DNBT_HAVE_ZLIB")
  34. endif()
  35. add_library(${NBT_NAME} ${NBT_SOURCES})
  36. target_include_directories(${NBT_NAME} PUBLIC include ${CMAKE_CURRENT_BINARY_DIR})
  37. # Install it
  38. if(DEFINED NBT_DEST_DIR)
  39. install(
  40. TARGETS ${NBT_NAME}
  41. ARCHIVE DESTINATION ${LIBRARY_DEST_DIR}
  42. RUNTIME DESTINATION ${LIBRARY_DEST_DIR}
  43. LIBRARY DESTINATION ${LIBRARY_DEST_DIR}
  44. )
  45. endif()
  46. if(NBT_USE_ZLIB)
  47. target_link_libraries(${NBT_NAME} ZLIB::ZLIB)
  48. endif()
  49. set_property(TARGET ${NBT_NAME} PROPERTY CXX_STANDARD 11)
  50. generate_export_header(${NBT_NAME} BASE_NAME nbt)
  51. if(${BUILD_SHARED_LIBS})
  52. set_target_properties(${NBT_NAME} PROPERTIES
  53. CXX_VISIBILITY_PRESET hidden
  54. VISIBILITY_INLINES_HIDDEN 1)
  55. endif()
  56. if(NBT_BUILD_TESTS)
  57. enable_testing()
  58. add_subdirectory(test)
  59. endif()