CMakeLists.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. set(LIBRARY_NAME libjson)
  2. unset(OPTION_ENABLE_TEST_CODE CACHE)
  3. option(OPTION_ENABLE_TEST_CODE "Whether enable test code." OFF)
  4. message("<=${LIBRARY_NAME}=> OPTION_ENABLE_TEST_CODE: " ${OPTION_ENABLE_TEST_CODE})
  5. set(LIBRARY_SOURCE_LIST
  6. ${CMAKE_CURRENT_LIST_DIR}/allocator.h
  7. ${CMAKE_CURRENT_LIST_DIR}/assertions.h
  8. ${CMAKE_CURRENT_LIST_DIR}/config.h
  9. ${CMAKE_CURRENT_LIST_DIR}/forwards.h
  10. ${CMAKE_CURRENT_LIST_DIR}/json.h
  11. ${CMAKE_CURRENT_LIST_DIR}/json_features.h
  12. ${CMAKE_CURRENT_LIST_DIR}/json_file.hpp
  13. ${CMAKE_CURRENT_LIST_DIR}/json_reader.cpp
  14. ${CMAKE_CURRENT_LIST_DIR}/json_tool.h
  15. ${CMAKE_CURRENT_LIST_DIR}/json_value.cpp
  16. ${CMAKE_CURRENT_LIST_DIR}/json_valueiterator.inl
  17. ${CMAKE_CURRENT_LIST_DIR}/json_writer.cpp
  18. ${CMAKE_CURRENT_LIST_DIR}/reader.h
  19. ${CMAKE_CURRENT_LIST_DIR}/value.h
  20. ${CMAKE_CURRENT_LIST_DIR}/version.h
  21. ${CMAKE_CURRENT_LIST_DIR}/writer.h
  22. )
  23. set(LIBRARY_DEPEND_LIST)
  24. add_library(${LIBRARY_NAME} ${LIBRARY_SOURCE_LIST})
  25. target_link_libraries(${LIBRARY_NAME} PUBLIC ${LIBRARY_DEPEND_LIST})
  26. if (OPTION_ENABLE_TEST_CODE)
  27. set(LIBRARY_TEST_NAME "${LIBRARY_NAME}_test")
  28. set(LIBRARY_TEST_SOURCE_LIST
  29. ${CMAKE_CURRENT_LIST_DIR}/test.h
  30. ${CMAKE_CURRENT_LIST_DIR}/test.cpp
  31. )
  32. add_executable(${LIBRARY_TEST_NAME} ${LIBRARY_TEST_SOURCE_LIST})
  33. target_link_libraries(${LIBRARY_TEST_NAME} ${LIBRARY_NAME} )
  34. endif ()