libdice/CMakeLists.txt

74 lines
1.5 KiB
CMake

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
${CMAKE_CURRENT_BINARY_DIR}
)
# 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)