CMakeLists.txt 872 B

123456789101112131415161718192021222324252627
  1. set(LIBRARY_NAME libmessage)
  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. # 获取当前目录下的所有源文件
  6. aux_source_directory(${CMAKE_CURRENT_LIST_DIR} GLOB_RECURSE)
  7. set(LIBRARY_SOURCE_LIST
  8. ${GLOB_RECURSE}
  9. )
  10. set(LIBRARY_DEPEND_LIST)
  11. add_library(${LIBRARY_NAME} ${LIBRARY_SOURCE_LIST})
  12. target_link_libraries(${LIBRARY_NAME} PUBLIC ${LIBRARY_DEPEND_LIST})
  13. if (OPTION_ENABLE_TEST_CODE)
  14. set(LIBRARY_TEST_NAME "${LIBRARY_NAME}_test")
  15. set(LIBRARY_TEST_SOURCE_LIST
  16. ${CMAKE_CURRENT_LIST_DIR}/test.h
  17. ${CMAKE_CURRENT_LIST_DIR}/test.cpp
  18. )
  19. add_executable(${LIBRARY_TEST_NAME} ${LIBRARY_TEST_SOURCE_LIST})
  20. target_link_libraries(${LIBRARY_TEST_NAME} ${LIBRARY_NAME} )
  21. endif ()