rework cmake a bit

This commit is contained in:
Gwendolyn 2022-01-11 19:30:53 +01:00
parent 421cace0c7
commit d163648a4d
3 changed files with 34 additions and 34 deletions

View File

@ -15,21 +15,11 @@ option(XTEST_ENABLE_PRNG "enable prng functions" ON)
add_subdirectory(src)
function(add_xtest_executable TARGET)
add_executable(${TARGET} ${ARGN})
set(XTEST_COMPILE_DEFS XTEST)
if (XTEST_ENABLE_PRNG)
set(XTEST_COMPILE_DEFS ${XTEST_COMPILE_DEFS} XTEST_PRNG)
endif ()
target_compile_definitions(${TARGET} PRIVATE ${XTEST_COMPILE_DEFS})
target_include_directories(${TARGET} AFTER PRIVATE "${XTEST_SOURCE_DIR}/include/xtest")
target_include_directories(${TARGET} SYSTEM BEFORE PRIVATE "${XTEST_SOURCE_DIR}/include/xtest-assert")
target_link_libraries(${TARGET} xtest)
endfunction()
add_library(xtest-assert INTERFACE)
target_include_directories(xtest-assert SYSTEM BEFORE INTERFACE "${XTEST_SOURCE_DIR}/include/xtest-assert")
target_compile_definitions(xtest-assert INTERFACE XTEST)
option(XTEST_BUILD_EXAMPLES "build the xtest examples" OFF)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND XTEST_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
endif ()

View File

@ -1,21 +1,22 @@
add_library(tested-code source.c)
target_link_libraries(tested-code xtest-assert)
function(xtest_define_example NAME)
set(TARGET_NAME "example-${NAME}")
add_xtest_executable(${TARGET_NAME} source.c ${NAME}.c ${ARGN})
add_executable(${TARGET_NAME} ${NAME}.c ${ARGN})
if (NAME STREQUAL "all")
set(EXAMPLE_COMPILE_DEFINITIONS ${EXAMPLE_COMPILE_DEFINITIONS} XTEST_ALL_EXAMPLES)
target_compile_definitions(${TARGET_NAME} PRIVATE XTEST_ALL_EXAMPLES)
endif ()
target_compile_definitions(${TARGET_NAME} PRIVATE ${EXAMPLE_COMPILE_DEFINITIONS})
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
target_link_libraries(${TARGET_NAME} xtest tested-code)
endfunction()
if (XTEST_BUILD_EXAMPLES)
xtest_define_example(all assertions.c expect_assertions.c fail.c float.c groups.c parameterized.c prng.c skip.c)
xtest_define_example(assertions)
xtest_define_example(expect_assertions)
xtest_define_example(fail)
xtest_define_example(float)
xtest_define_example(groups)
xtest_define_example(parameterized)
xtest_define_example(prng)
xtest_define_example(skip)
endif ()
xtest_define_example(all assertions.c expect_assertions.c fail.c float.c groups.c parameterized.c prng.c skip.c)
xtest_define_example(assertions)
xtest_define_example(expect_assertions)
xtest_define_example(fail)
xtest_define_example(float)
xtest_define_example(groups)
xtest_define_example(parameterized)
xtest_define_example(prng)
xtest_define_example(skip)

View File

@ -1,11 +1,20 @@
set(XTEST_LINK_LIBRARIES "")
if(XTEST_ENABLE_PRNG)
set(XTEST_ADDITIONAL_SOURCES ${XTEST_SOURCE_DIR}/extern/pcg/pcg_basic.c)
add_library(pcg ${XTEST_SOURCE_DIR}/extern/pcg/pcg_basic.c)
set(XTEST_LINK_LIBRARIES ${XTEST_LINK_LIBRARIES} pcg)
set(XTEST_ADDITIONAL_DEFINES XTEST_PRNG)
find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
set(XTEST_LINK_LIBRARIES ${XTEST_LINK_LIBRARIES} ${MATH_LIBRARY})
endif()
endif()
add_library(xtest xtest.c ${XTEST_ADDITIONAL_SOURCES})
target_compile_definitions(xtest PRIVATE XTEST ${XTEST_ADDITIONAL_DEFINES})
add_library(xtest xtest.c)
target_compile_options(xtest PRIVATE -Wall -Wextra -pedantic)
target_include_directories(xtest PRIVATE ${XTEST_SOURCE_DIR}/extern/pcg ${XTEST_SOURCE_DIR}/include/xtest)
target_include_directories(xtest PRIVATE ${XTEST_SOURCE_DIR}/extern/pcg)
target_link_libraries(xtest PRIVATE ${XTEST_LINK_LIBRARIES})
target_compile_definitions(xtest PUBLIC XTEST ${XTEST_ADDITIONAL_DEFINES})
target_include_directories(xtest PUBLIC ${XTEST_SOURCE_DIR}/include/xtest)