Home | History | Annotate | Download | only in libtest
      1 set(TARGET_LABEL_PREFIX "Test ")
      2 
      3 if(MSVC)
      4   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
      5 endif()
      6 
      7 function(setup_test TEST_NAME)          # ARGN are the files in the test
      8   add_executable( ${TEST_NAME} ${ARGN} )
      9   string(TOUPPER ${TEST_NAME} UPPER_TEST_NAME)
     10 
     11   include_directories(
     12     ${CURL_SOURCE_DIR}/lib          # To be able to reach "curl_setup_once.h"
     13     ${CURL_BINARY_DIR}/lib          # To be able to reach "curl_config.h"
     14     ${CURL_BINARY_DIR}/include      # To be able to reach "curl/curl.h"
     15     ${CURL_SOURCE_DIR}/tests/libtest # To be able to build generated tests
     16     )
     17   if(USE_ARES)
     18     include_directories(${CARES_INCLUDE_DIR})
     19   endif()
     20 
     21   target_link_libraries(${TEST_NAME} libcurl ${CURL_LIBS})
     22 
     23   set_target_properties(${TEST_NAME}
     24     PROPERTIES COMPILE_DEFINITIONS ${UPPER_TEST_NAME})
     25   set_target_properties(${TEST_NAME}
     26     PROPERTIES PROJECT_LABEL "${TARGET_LABEL_PREFIX}${TEST_NAME}")
     27 endfunction()
     28 
     29 
     30 transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
     31 include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
     32 
     33 foreach(TEST_NAME ${noinst_PROGRAMS})
     34   if(DEFINED ${TEST_NAME}_SOURCES)
     35     setup_test(${TEST_NAME} ${${TEST_NAME}_SOURCES})
     36   else()
     37     setup_test(${TEST_NAME} ${nodist_${TEST_NAME}_SOURCES})
     38   endif()
     39 endforeach()
     40 
     41 # Allows for hostname override to make tests machine independent.
     42 # TODO this cmake build assumes a shared build, detect static linking here!
     43 if(NOT WIN32)
     44   add_library(hostname MODULE sethostname.c sethostname.h)
     45   # Output to .libs for compatibility with autotools, the test data expects a
     46   # library at (tests)/libtest/.libs/libhostname.so
     47   set_target_properties(hostname PROPERTIES
     48       LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.libs)
     49   if(HIDES_CURL_PRIVATE_SYMBOLS)
     50     set_property(TARGET hostname APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
     51     set_property(TARGET hostname APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
     52   endif()
     53 endif()
     54 
     55 add_custom_command(
     56   OUTPUT lib1521.c
     57   COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl < ${CURL_SOURCE_DIR}/include/curl/curl.h > lib1521.c
     58   DEPENDS
     59     "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl"
     60     "${CURL_SOURCE_DIR}/include/curl/curl.h"
     61   VERBATIM)
     62 
     63 set_property(TARGET chkdecimalpoint
     64   APPEND PROPERTY COMPILE_DEFINITIONS "CURLX_NO_MEMORY_CALLBACKS;CURL_STATICLIB")
     65 
     66   # # files used only in some libcurl test programs
     67 # SET(TESTUTIL testutil.c testutil.h)
     68 
     69 # # these files are used in every single test program below
     70 # SET(SUPPORTFILES first.c test.h)
     71 
     72 # # These are all libcurl test programs
     73 # SET(noinst_PROGRAMS
     74 # lib500 lib501 lib502 lib503 lib504 lib505 lib506
     75 # lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516
     76 # lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526
     77 # #lib527
     78 # #lib529
     79 # lib530
     80 # #lib532
     81 # lib533 lib536 lib537 lib540 lib541 lib542 lib543
     82 # lib544
     83 # #lib545
     84 # lib547
     85 # #lib548
     86 # lib549 lib552 lib553 lib554 lib555 lib556
     87 # lib539 lib557
     88 # lib560
     89 # )
     90 
     91 # SET(noinst_PROGRAMS_USE_TESTUTIL
     92 # lib502 lib503 lib504
     93 # lib507
     94 # lib525 lib526 lib527
     95 # lib529
     96 # lib530
     97 # lib532
     98 # lib533 lib536
     99 # lib555
    100 # )
    101 
    102 # MACRO(ADD_TESTUTIL_IF_NECESSARY TEST_NAME)
    103 # LIST(FIND noinst_PROGRAMS_USE_TESTUTIL ${TEST_NAME} USES_TESTUTIL)
    104 # IF(NOT ${USES_TESTUTIL} EQUAL -1)
    105 # LIST(APPEND SOURCE ${TESTUTIL})               # Need TestUtil
    106 # ENDIF()
    107 # ENDMACRO()
    108 
    109 # # General case
    110 # FOREACH(TEST_NAME ${noinst_PROGRAMS})
    111 # SET(SOURCE "${TEST_NAME}.c" ${SUPPORTFILES})
    112 # ADD_TESTUTIL_IF_NECESSARY(${TEST_NAME})
    113 # SETUP_TEST(${TEST_NAME} ${SOURCE})
    114 # ENDFOREACH()
    115 
    116 # # Special cases
    117 # SET(TEST_NAME lib527)
    118 # SET(SOURCE "lib526.c" ${SUPPORTFILES})
    119 # ADD_TESTUTIL_IF_NECESSARY(${TEST_NAME})
    120 # SETUP_TEST(${TEST_NAME} ${SOURCE})
    121 
    122 # SET(TEST_NAME lib529)
    123 # SET(SOURCE "lib525.c" ${SUPPORTFILES})
    124 # ADD_TESTUTIL_IF_NECESSARY(${TEST_NAME})
    125 # SETUP_TEST(${TEST_NAME} ${SOURCE})
    126 
    127 # SET(TEST_NAME lib532)
    128 # SET(SOURCE "lib526.c" ${SUPPORTFILES})
    129 # ADD_TESTUTIL_IF_NECESSARY(${TEST_NAME})
    130 # SETUP_TEST(${TEST_NAME} ${SOURCE})
    131 
    132 # SET(TEST_NAME lib545)
    133 # SET(SOURCE "lib544.c" ${SUPPORTFILES})
    134 # ADD_TESTUTIL_IF_NECESSARY(${TEST_NAME})
    135 # SETUP_TEST(${TEST_NAME} ${SOURCE})
    136 
    137 # SET(TEST_NAME lib548)
    138 # SET(SOURCE "lib547.c" ${SUPPORTFILES})
    139 # ADD_TESTUTIL_IF_NECESSARY(${TEST_NAME})
    140 # SETUP_TEST(${TEST_NAME} ${SOURCE})
    141