9b2fd506df43570959bf44a79616f8814051d7a1
[oweals/jsonpath.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2
3 PROJECT(jsonpath C)
4 ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations)
5
6 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
7
8 IF(APPLE)
9   INCLUDE_DIRECTORIES(/opt/local/include)
10   LINK_DIRECTORIES(/opt/local/lib)
11 ENDIF()
12
13 find_library(json NAMES json-c json)
14
15 IF(DEBUG)
16   ADD_DEFINITIONS(-DDEBUG -g3)
17 ENDIF()
18
19 INCLUDE(FindPkgConfig)
20 PKG_CHECK_MODULES(JSONC json-c json)
21 IF(JSONC_FOUND)
22   ADD_DEFINITIONS(-DJSONC)
23   INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
24 ENDIF()
25
26 FIND_PACKAGE(BISON REQUIRED)
27 IF(BISON_FOUND)
28     ADD_CUSTOM_COMMAND(
29       OUTPUT parser.c
30       COMMAND ${BISON_EXECUTABLE} parser.y
31       COMMENT "Generating parser.c"
32     )
33 ENDIF()
34
35 FIND_PACKAGE(FLEX REQUIRED)
36 IF(FLEX_FOUND)
37     ADD_CUSTOM_COMMAND(
38       OUTPUT lexer.c
39       COMMAND ${FLEX_EXECUTABLE} lexer.l
40       COMMENT "Generating lexer.c"
41     )
42 ENDIF()
43
44 ADD_EXECUTABLE(jsonpath main.c lexer.c parser.c matcher.c)
45 TARGET_LINK_LIBRARIES(jsonpath ubox ${json})
46
47 INSTALL(TARGETS jsonpath RUNTIME DESTINATION bin)