set(LIBRARY_NAME libjson) unset(OPTION_ENABLE_TEST_CODE CACHE) option(OPTION_ENABLE_TEST_CODE "Whether enable test code." OFF) message("<=${LIBRARY_NAME}=> OPTION_ENABLE_TEST_CODE: " ${OPTION_ENABLE_TEST_CODE}) set(LIBRARY_SOURCE_LIST ${CMAKE_CURRENT_LIST_DIR}/allocator.h ${CMAKE_CURRENT_LIST_DIR}/assertions.h ${CMAKE_CURRENT_LIST_DIR}/config.h ${CMAKE_CURRENT_LIST_DIR}/forwards.h ${CMAKE_CURRENT_LIST_DIR}/json.h ${CMAKE_CURRENT_LIST_DIR}/json_features.h ${CMAKE_CURRENT_LIST_DIR}/json_file.hpp ${CMAKE_CURRENT_LIST_DIR}/json_reader.cpp ${CMAKE_CURRENT_LIST_DIR}/json_tool.h ${CMAKE_CURRENT_LIST_DIR}/json_value.cpp ${CMAKE_CURRENT_LIST_DIR}/json_valueiterator.inl ${CMAKE_CURRENT_LIST_DIR}/json_writer.cpp ${CMAKE_CURRENT_LIST_DIR}/reader.h ${CMAKE_CURRENT_LIST_DIR}/value.h ${CMAKE_CURRENT_LIST_DIR}/version.h ${CMAKE_CURRENT_LIST_DIR}/writer.h ) set(LIBRARY_DEPEND_LIST) add_library(${LIBRARY_NAME} ${LIBRARY_SOURCE_LIST}) target_link_libraries(${LIBRARY_NAME} PUBLIC ${LIBRARY_DEPEND_LIST}) if (OPTION_ENABLE_TEST_CODE) set(LIBRARY_TEST_NAME "${LIBRARY_NAME}_test") set(LIBRARY_TEST_SOURCE_LIST ${CMAKE_CURRENT_LIST_DIR}/test.h ${CMAKE_CURRENT_LIST_DIR}/test.cpp ) add_executable(${LIBRARY_TEST_NAME} ${LIBRARY_TEST_SOURCE_LIST}) target_link_libraries(${LIBRARY_TEST_NAME} ${LIBRARY_NAME} ) endif ()