CMakeLists.txt 839 B

12345678910111213141516171819202122232425
  1. set(LIBRARY_NAME libfile)
  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}/pathcreator.h
  7. ${CMAKE_CURRENT_LIST_DIR}/pathcreator.cpp
  8. )
  9. set(LIBRARY_DEPEND_LIST)
  10. add_library(${LIBRARY_NAME} ${LIBRARY_SOURCE_LIST})
  11. target_link_libraries(${LIBRARY_NAME} PUBLIC ${LIBRARY_DEPEND_LIST})
  12. if (OPTION_ENABLE_TEST_CODE)
  13. set(LIBRARY_TEST_NAME "${LIBRARY_NAME}_test")
  14. set(LIBRARY_TEST_SOURCE_LIST
  15. ${CMAKE_CURRENT_LIST_DIR}/test.h
  16. ${CMAKE_CURRENT_LIST_DIR}/test.cpp
  17. )
  18. add_executable(${LIBRARY_TEST_NAME} ${LIBRARY_TEST_SOURCE_LIST})
  19. target_link_libraries(${LIBRARY_TEST_NAME} ${LIBRARY_NAME} )
  20. endif ()