mirror of
https://github.com/curl/curl.git
synced 2025-01-18 14:04:30 +08:00
cmake: add libcurlu
/libcurltool
for unit tests
Add a `libcurlu`/`libcurltool` static library that is compiled only for unit tests. We use `EXCLUDE_FROM_ALL` to make sure that they're not built by default, they're only built if unit tests are built. These libraries allow us to compile every unit test with CMake. Closes #11446
This commit is contained in:
parent
c42c6eb245
commit
39e7c22bb4
@ -64,6 +64,14 @@ add_library(
|
||||
${HHEADERS} ${CSOURCES}
|
||||
)
|
||||
|
||||
add_library(
|
||||
curlu # special libcurlu library just for unittests
|
||||
STATIC
|
||||
EXCLUDE_FROM_ALL
|
||||
${HHEADERS} ${CSOURCES}
|
||||
)
|
||||
target_compile_definitions(curlu PUBLIC UNITTESTS CURL_STATICLIB)
|
||||
|
||||
add_library(
|
||||
${PROJECT_NAME}::${LIB_NAME}
|
||||
ALIAS ${LIB_NAME}
|
||||
@ -80,6 +88,7 @@ if(NOT BUILD_SHARED_LIBS)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
|
||||
target_link_libraries(curlu PRIVATE ${CURL_LIBS})
|
||||
|
||||
transform_makefile_inc("Makefile.soname" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake")
|
||||
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.soname.cmake)
|
||||
|
@ -76,6 +76,14 @@ add_executable(
|
||||
ALIAS ${EXE_NAME}
|
||||
)
|
||||
|
||||
add_library(
|
||||
curltool # special libcurltool library just for unittests
|
||||
STATIC
|
||||
EXCLUDE_FROM_ALL
|
||||
${CURL_CFILES} ${CURLX_CFILES} ${CURL_HFILES}
|
||||
)
|
||||
target_compile_definitions(curltool PUBLIC UNITTESTS CURL_STATICLIB)
|
||||
|
||||
if(CURL_HAS_LTO)
|
||||
set_target_properties(${EXE_NAME} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
||||
|
@ -33,18 +33,10 @@ include_directories(
|
||||
${CURL_BINARY_DIR}/include # To be able to reach "curl/curl.h"
|
||||
)
|
||||
|
||||
# TODO build a special libcurlu library for unittests.
|
||||
# Until that happens, only build the unit tests when creating a static libcurl
|
||||
# or else they will fail to link. Some of the tests require the special libcurlu
|
||||
# build, so filter those out until we get libcurlu.
|
||||
list(FILTER UNITPROGS EXCLUDE REGEX
|
||||
"unit1394|unit1395|unit1604|unit1608|unit1621|unit1650|unit1653|unit1655|unit1660|unit2600|unit2601|unit2602|unit2603")
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
if (ENABLE_CURLDEBUG) # running unittests require curl to compiled with CURLDEBUG
|
||||
foreach(_testfile ${UNITPROGS})
|
||||
add_executable(${_testfile} EXCLUDE_FROM_ALL ${_testfile}.c ${UNITFILES})
|
||||
add_dependencies(testdeps ${_testfile})
|
||||
target_link_libraries(${_testfile} libcurl ${CURL_LIBS})
|
||||
set_target_properties(${_testfile}
|
||||
PROPERTIES COMPILE_DEFINITIONS "UNITTESTS")
|
||||
target_link_libraries(${_testfile} curltool curlu)
|
||||
endforeach()
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user