switch to cmake

This commit is contained in:
Florian Stinglmayr 2019-08-19 21:28:04 +02:00
parent e7ca9d9036
commit 823fcecc03
5 changed files with 95 additions and 8 deletions

71
CMakeLists.txt Normal file
View File

@ -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)

View File

@ -24,8 +24,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "config.h"
#ifndef HAVE_ARC4RANDOM_UNIFORM #ifndef HAVE_ARC4RANDOM_UNIFORM
#include <bsd/stdlib.h> #include <bsd/stdlib.h>
#endif #endif

View File

@ -1,6 +1,5 @@
%option bison-bridge %option bison-bridge
%option reentrant %option reentrant
%option outfile="../lib/dice_lexer.c"
%{ %{
#define YYSTYPE DPSTYPE #define YYSTYPE DPSTYPE

View File

@ -1,12 +1,11 @@
prefix=@prefix@ prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@exec_prefix@ libdir=lib
libdir=@libdir@ includedir=include
includedir=@includedir@
Name: libdice Name: libdice
Description: dice rolling and math expression library Description: dice rolling and math expression library
Version: @VERSION@ Version: @VERSION@
Requires: Requires: @REQUIRES@
Conflicts: Conflicts:
Cflags: -I${includedir} Cflags: -I${includedir}
Libs: -L${libdir} -ldice Libs: -L${libdir} -ldice

20
tests/CMakeLists.txt Normal file
View File

@ -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()