switch to cmake
This commit is contained in:
parent
e7ca9d9036
commit
823fcecc03
71
CMakeLists.txt
Normal file
71
CMakeLists.txt
Normal 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)
|
@ -24,8 +24,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM_UNIFORM
|
||||
#include <bsd/stdlib.h>
|
||||
#endif
|
||||
|
@ -1,6 +1,5 @@
|
||||
%option bison-bridge
|
||||
%option reentrant
|
||||
%option outfile="../lib/dice_lexer.c"
|
||||
|
||||
%{
|
||||
#define YYSTYPE DPSTYPE
|
||||
|
@ -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
|
||||
|
20
tests/CMakeLists.txt
Normal file
20
tests/CMakeLists.txt
Normal 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()
|
Loading…
Reference in New Issue
Block a user