rework cmake a bit
This commit is contained in:
parent
421cace0c7
commit
d163648a4d
|
@ -15,21 +15,11 @@ option(XTEST_ENABLE_PRNG "enable prng functions" ON)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
add_library(xtest-assert INTERFACE)
|
||||||
function(add_xtest_executable TARGET)
|
target_include_directories(xtest-assert SYSTEM BEFORE INTERFACE "${XTEST_SOURCE_DIR}/include/xtest-assert")
|
||||||
add_executable(${TARGET} ${ARGN})
|
target_compile_definitions(xtest-assert INTERFACE XTEST)
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
option(XTEST_BUILD_EXAMPLES "build the xtest examples" OFF)
|
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)
|
add_subdirectory(examples)
|
||||||
endif ()
|
endif ()
|
|
@ -1,14 +1,16 @@
|
||||||
|
add_library(tested-code source.c)
|
||||||
|
target_link_libraries(tested-code xtest-assert)
|
||||||
|
|
||||||
function(xtest_define_example NAME)
|
function(xtest_define_example NAME)
|
||||||
set(TARGET_NAME "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")
|
if (NAME STREQUAL "all")
|
||||||
set(EXAMPLE_COMPILE_DEFINITIONS ${EXAMPLE_COMPILE_DEFINITIONS} XTEST_ALL_EXAMPLES)
|
target_compile_definitions(${TARGET_NAME} PRIVATE XTEST_ALL_EXAMPLES)
|
||||||
endif ()
|
endif ()
|
||||||
target_compile_definitions(${TARGET_NAME} PRIVATE ${EXAMPLE_COMPILE_DEFINITIONS})
|
target_link_libraries(${TARGET_NAME} xtest tested-code)
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
|
|
||||||
endfunction()
|
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(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(assertions)
|
||||||
xtest_define_example(expect_assertions)
|
xtest_define_example(expect_assertions)
|
||||||
|
@ -18,4 +20,3 @@ if (XTEST_BUILD_EXAMPLES)
|
||||||
xtest_define_example(parameterized)
|
xtest_define_example(parameterized)
|
||||||
xtest_define_example(prng)
|
xtest_define_example(prng)
|
||||||
xtest_define_example(skip)
|
xtest_define_example(skip)
|
||||||
endif ()
|
|
|
@ -1,11 +1,20 @@
|
||||||
|
|
||||||
|
set(XTEST_LINK_LIBRARIES "")
|
||||||
|
|
||||||
if(XTEST_ENABLE_PRNG)
|
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)
|
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()
|
endif()
|
||||||
|
|
||||||
add_library(xtest xtest.c ${XTEST_ADDITIONAL_SOURCES})
|
add_library(xtest xtest.c)
|
||||||
target_compile_definitions(xtest PRIVATE XTEST ${XTEST_ADDITIONAL_DEFINES})
|
|
||||||
target_compile_options(xtest PRIVATE -Wall -Wextra -pedantic)
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue