diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0cc1ea7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,71 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) + +INCLUDE(CheckFunctionExists) + +FIND_PACKAGE(PkgConfig) +FIND_PACKAGE(BISON) +FIND_PACKAGE(FLEX) + +PKG_CHECK_MODULES(CMOCKA REQUIRED cmocka) + +ENABLE_TESTING() + +SET(VERSION "0.4") +SET(TARGET "dice") + +SET(SOURCES + "lib/diceexpr.c" + "lib/dice.c" + ) + +SET(HEADERS + "lib/dice.h" + ) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib) + +# Yacc/BISON/Flex stuff +BISON_TARGET(DICE_PARSER + "${CMAKE_CURRENT_SOURCE_DIR}/lib/dice_parse.y" + "${CMAKE_CURRENT_BINARY_DIR}/dice_parse.c" + COMPILE_FLAGS "-d" + ) +FLEX_TARGET(DICE_LEXER + "${CMAKE_CURRENT_SOURCE_DIR}/lib/dice_lexer.l" + "${CMAKE_CURRENT_BINARY_DIR}/dice_lexer.c" + COMPILE_FLAGS "-P dp" + ) + +ADD_DEFINITIONS("-Wall") + +CHECK_FUNCTION_EXISTS("arc4random_uniform" HAVE_ARC4RANDOM_UNIFORM) +IF (HAVE_ARC4RANDOM_UNIFORM) + ADD_DEFINITIONS("-DHAVE_ARC4RANDOM_UNIFORM") +ELSE() + PKG_CHECK_MODULES(BSD REQUIRED libbsd) + INCLUDE_DIRECTORIES(${BSD_INCLUDE_DIRS}) + # used in pkg-config IN file + SET(REQUIRES "libbsd") +ENDIF() + +# pkg-config file +CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/libdice.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/libdice.pc" + ) + +ADD_LIBRARY(${TARGET} SHARED + ${SOURCES} ${HEADERS} + ${BISON_DICE_PARSER_OUTPUTS} + ${FLEX_DICE_LEXER_OUTPUTS} + ) + +IF (NOT HAVE_ARC4RANDOM_UNIFORM) + TARGET_LINK_LIBRARIES(${TARGET} ${BSD_LIBRARIES} m) +ENDIF() + +INSTALL(TARGETS ${TARGET} DESTINATION lib) +INSTALL(FILES ${HEADERS} DESTINATION include) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdice.pc + DESTINATION share/pkgconfig) + +ADD_SUBDIRECTORY(tests) diff --git a/lib/dice.c b/lib/dice.c index ee99dc4..24f14d0 100644 --- a/lib/dice.c +++ b/lib/dice.c @@ -24,8 +24,6 @@ #include #include -#include "config.h" - #ifndef HAVE_ARC4RANDOM_UNIFORM #include #endif diff --git a/lib/dice_lexer.l b/lib/dice_lexer.l index f88efd7..317e36b 100644 --- a/lib/dice_lexer.l +++ b/lib/dice_lexer.l @@ -1,6 +1,5 @@ %option bison-bridge %option reentrant -%option outfile="../lib/dice_lexer.c" %{ #define YYSTYPE DPSTYPE diff --git a/libdice.pc.in b/libdice.pc.in index 82f0cf6..613735a 100644 --- a/libdice.pc.in +++ b/libdice.pc.in @@ -1,12 +1,11 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=lib +includedir=include Name: libdice Description: dice rolling and math expression library Version: @VERSION@ -Requires: +Requires: @REQUIRES@ Conflicts: Cflags: -I${includedir} Libs: -L${libdir} -ldice diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..2120b1c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,20 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) + +SET(TESTS + "test_dice_evaluate" + "test_dice_fudge" + "test_dice_parse" + "test_dice_simple_roll" + "test_expr_parse" + ) + +INCLUDE_DIRECTORIES( + "${CMAKE_CURRENT_SOURCE_DIR}/../lib/" + ${CMOCKA_INCLUDE_DIRS} + ) + +FOREACH(TEST ${TESTS}) + ADD_EXECUTABLE(${TEST} ${TEST}.c) + TARGET_LINK_LIBRARIES(${TEST} dice ${CMOCKA_LIBRARIES}) + ADD_TEST(NAME "${TEST}" COMMAND ${TEST}) +ENDFOREACH()