CMakeLists.txt 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ################################################################################
  2. # This file is part of the argtable3 library.
  3. #
  4. # Copyright (C) 2016-2019 Tom G. Huang
  5. # <tomghuang@gmail.com>
  6. # All rights reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions are met:
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. # * Neither the name of STEWART HEITMANN nor the names of its contributors
  16. # may be used to endorse or promote products derived from this software
  17. # without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. # ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
  23. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. ################################################################################
  30. set(TEST_PUBLIC_SRC_FILES
  31. testall.c
  32. testarglit.c
  33. testargstr.c
  34. testargint.c
  35. testargdate.c
  36. testargdbl.c
  37. testargfile.c
  38. testargrex.c
  39. testargdstr.c
  40. testargcmd.c
  41. CuTest.c
  42. )
  43. set(TEST_SRC_FILES
  44. ${TEST_PUBLIC_SRC_FILES}
  45. testarghashtable.c
  46. )
  47. if(UNIX)
  48. set(ARGTABLE3_EXTRA_LIBS m)
  49. endif()
  50. add_executable(test_shared ${TEST_PUBLIC_SRC_FILES})
  51. target_compile_definitions(test_shared PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY)
  52. target_include_directories(test_shared PRIVATE ${PROJECT_SOURCE_DIR}/src)
  53. target_link_libraries(test_shared argtable3 ${ARGTABLE3_EXTRA_LIBS})
  54. add_custom_command(TARGET test_shared POST_BUILD
  55. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  56. "$<TARGET_FILE:argtable3>"
  57. "$<TARGET_FILE_DIR:test_shared>"
  58. )
  59. add_executable(test_static ${TEST_SRC_FILES})
  60. target_compile_definitions(test_static PRIVATE -DARGTABLE3_TEST_PUBLIC_ONLY)
  61. target_include_directories(test_static PRIVATE ${PROJECT_SOURCE_DIR}/src)
  62. target_link_libraries(test_static argtable3_static ${ARGTABLE3_EXTRA_LIBS})
  63. add_executable(test_src ${TEST_SRC_FILES} ${ARGTABLE3_SRC_FILES})
  64. target_include_directories(test_src PRIVATE ${PROJECT_SOURCE_DIR}/src)
  65. target_link_libraries(test_src ${ARGTABLE3_EXTRA_LIBS})
  66. add_custom_command(OUTPUT ${ARGTABLE3_AMALGAMATION_SRC_FILE}
  67. COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist
  68. WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools"
  69. )
  70. add_executable(test_amalgamation ${TEST_SRC_FILES} ${ARGTABLE3_AMALGAMATION_SRC_FILE})
  71. target_include_directories(test_amalgamation PRIVATE ${PROJECT_SOURCE_DIR}/src)
  72. target_link_libraries(test_amalgamation ${ARGTABLE3_EXTRA_LIBS})
  73. add_custom_command(TARGET test_amalgamation PRE_BUILD
  74. COMMAND "${PROJECT_SOURCE_DIR}/tools/build" dist
  75. WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/tools"
  76. )
  77. add_test(NAME test_shared COMMAND "$<TARGET_FILE:test_shared>")
  78. add_test(NAME test_static COMMAND "$<TARGET_FILE:test_static>")
  79. add_test(NAME test_src COMMAND "$<TARGET_FILE:test_src>")
  80. add_test(NAME test_amalgamation COMMAND "$<TARGET_FILE:test_amalgamation>")