CMakeLists.txt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. set(LIBRARY_NAME error_code)
  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. unset(OPTION_ERROR_CODE_DESCRIPTE CACHE)
  6. option(OPTION_ERROR_CODE_DESCRIPTE "Whether enable error code description." OFF)
  7. message("<=${LIBRARY_NAME}=> OPTION_ERROR_CODE_DESCRIPTE: " ${OPTION_ERROR_CODE_DESCRIPTE})
  8. if (OPTION_ERROR_CODE_DESCRIPTE)
  9. add_definitions(-DOPTION_ERROR_CODE_DESCRIPTE=1)
  10. else ()
  11. add_definitions(-DOPTION_ERROR_CODE_DESCRIPTE=0)
  12. endif ()
  13. set(LIBRARY_SOURCE_LIST
  14. ${CMAKE_CURRENT_LIST_DIR}/error_code.hpp
  15. ${CMAKE_CURRENT_LIST_DIR}/error_code.cpp
  16. )
  17. set(LIBRARY_DEPEND_LIST)
  18. add_library(${LIBRARY_NAME} ${LIBRARY_SOURCE_LIST})
  19. target_link_libraries(${LIBRARY_NAME} PUBLIC ${LIBRARY_DEPEND_LIST})
  20. if (OPTION_ENABLE_TEST_CODE)
  21. set(LIBRARY_TEST_NAME "${LIBRARY_NAME}_test")
  22. set(LIBRARY_TEST_SOURCE_LIST
  23. ${CMAKE_CURRENT_LIST_DIR}/test.h
  24. ${CMAKE_CURRENT_LIST_DIR}/test.cpp
  25. )
  26. add_executable(${LIBRARY_TEST_NAME} ${LIBRARY_TEST_SOURCE_LIST})
  27. target_link_libraries(${LIBRARY_TEST_NAME} ${LIBRARY_NAME} )
  28. endif ()