|
| 1 | +cmake_minimum_required(VERSION 2.8.12) |
| 2 | +project("libvqm") |
| 3 | + |
| 4 | +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) |
| 5 | + #Only set compiler settings if we are not a sub-project |
| 6 | + set(WARN_FLAGS "-Wall -Wextra -Wpedantic -Wcast-qual -Wcast-align -Wshadow -Wformat=2 -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wredundant-decls -Wswitch-default -Wundef -Wunused-variable -Wdisabled-optimization -Wnoexcept -Woverloaded-virtual -Wctor-dtor-privacy -Wnon-virtual-dtor") |
| 7 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 ${WARN_FLAGS}") |
| 8 | + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined") |
| 9 | + set(FLEX_BISON_WARN_SUPPRESS_FLAGS "-Wno-switch-default -Wno-unused-parameter -Wno-missing-declarations") |
| 10 | +endif() |
| 11 | + |
| 12 | +#Flex and Bison are used to generate the parser |
| 13 | +find_package(BISON REQUIRED 3.0) |
| 14 | +find_package(FLEX REQUIRED) |
| 15 | + |
| 16 | +file(GLOB_RECURSE LIB_SOURCES *.c *.cpp) |
| 17 | +file(GLOB_RECURSE LIB_HEADERS *.h) |
| 18 | +files_to_dirs(LIB_HEADERS LIB_INCLUDE_DIRS) |
| 19 | + |
| 20 | +#Find the flex and bison input files |
| 21 | +file(GLOB_RECURSE LEXER_SOURCES *.l) |
| 22 | +file(GLOB_RECURSE PARSER_SOURCES *.y) |
| 23 | + |
| 24 | +#Make the flex and bison targets |
| 25 | +flex_target(VqmLexer ${LEXER_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/vqm_lexer.gen.c |
| 26 | + COMPILE_FLAGS --header-file=${CMAKE_CURRENT_BINARY_DIR}/vqm_lexer.gen.h) |
| 27 | +bison_target(VqmParser ${PARSER_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/vqm_parser.gen.c) |
| 28 | +add_flex_bison_dependency(VqmLexer VqmParser) |
| 29 | + |
| 30 | + |
| 31 | +#Treat .c as CXX |
| 32 | +set_source_files_properties(${LIB_SOURCES} ${FLEX_VqmLexer_OUTPUTS} ${BISON_VqmParser_OUTPUT_SOURCE} PROPERTIES LANGUAGE CXX) |
| 33 | + |
| 34 | +#Suppress warnings in Flex/Bison generated files |
| 35 | +if(FLEX_BISON_WARN_SUPPRESS_FLAGS) |
| 36 | + set_source_files_properties(${FLEX_VqmLexer_OUTPUTS} ${BISON_VqmParser_OUTPUT_SOURCE} |
| 37 | + PROPERTIES COMPILE_FLAGS ${FLEX_BISON_WARN_SUPPRESS_FLAGS}) |
| 38 | +endif() |
| 39 | + |
| 40 | +#Create the library |
| 41 | +add_library(libvqm STATIC |
| 42 | + ${LIB_HEADERS} |
| 43 | + ${LIB_SOURCES} |
| 44 | + ${FLEX_VqmLexer_OUTPUTS} |
| 45 | + ${BISON_VqmParser_OUTPUT_SOURCE}) |
| 46 | +target_include_directories(libvqm PUBLIC ${LIB_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) |
| 47 | +set_target_properties(libvqm PROPERTIES PREFIX "") #Avoid extra 'lib' prefix |
| 48 | + |
| 49 | +target_link_libraries(libvqm |
| 50 | + libvtrutil) |
0 commit comments