18a914506SMatthias Brauncmake_minimum_required(VERSION 2.8.12)
28a914506SMatthias Braunif(POLICY CMP0042)
38a914506SMatthias Braun	cmake_policy(SET CMP0042 NEW)
48a914506SMatthias Braunendif()
58a914506SMatthias Braunif(POLICY CMP0028)
68a914506SMatthias Braun	cmake_policy(SET CMP0028 NEW)
78a914506SMatthias Braunendif()
8209a7455SMatthias Braunproject(cparser C)
9f6800f19SMatthias Braunset(cparser_VERSION "1.22.1")
108a914506SMatthias Braun
118a914506SMatthias Braun# Enable C99
128a914506SMatthias Braunif(CMAKE_VERSION VERSION_LESS "3.1")
138a914506SMatthias Braun	if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
14209a7455SMatthias Braun		set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
158a914506SMatthias Braun	endif()
168a914506SMatthias Braunelse()
178a914506SMatthias Braun	set(CMAKE_C_STANDARD 99)
188a914506SMatthias Braunendif()
19aabeb2edSMatthias Braun
20aabeb2edSMatthias Braunset(SOURCES
219fc50584SSebastian Graf	src/adt/panic.c
22aabeb2edSMatthias Braun	src/adt/pset_new.c
23aabeb2edSMatthias Braun	src/adt/strutil.c
24aabeb2edSMatthias Braun	src/ast/ast.c
25aabeb2edSMatthias Braun	src/ast/attribute.c
26aabeb2edSMatthias Braun	src/ast/constfold.c
27aabeb2edSMatthias Braun	src/ast/entity.c
28aabeb2edSMatthias Braun	src/ast/printer.c
29aabeb2edSMatthias Braun	src/ast/string_hash.c
30aabeb2edSMatthias Braun	src/ast/string_rep.c
31aabeb2edSMatthias Braun	src/ast/symbol_table.c
32aabeb2edSMatthias Braun	src/ast/type.c
33aabeb2edSMatthias Braun	src/ast/type_hash.c
34aabeb2edSMatthias Braun	src/ast/types.c
35aabeb2edSMatthias Braun	src/ast/walk.c
36aabeb2edSMatthias Braun	src/driver/actions.c
37aabeb2edSMatthias Braun	src/driver/c_driver.c
38aabeb2edSMatthias Braun	src/driver/diagnostic.c
39aabeb2edSMatthias Braun	src/driver/driver.c
40aabeb2edSMatthias Braun	src/driver/help.c
41aabeb2edSMatthias Braun	src/driver/options.c
42aabeb2edSMatthias Braun	src/driver/predefs.c
43aabeb2edSMatthias Braun	src/driver/target.c
44aabeb2edSMatthias Braun	src/driver/tempfile.c
45aabeb2edSMatthias Braun	src/driver/timing.c
46aabeb2edSMatthias Braun	src/driver/warning.c
47aabeb2edSMatthias Braun	src/firm/ast2firm.c
48aabeb2edSMatthias Braun	src/firm/firm_opt.c
499fc50584SSebastian Graf	src/firm/jittest.c
50aabeb2edSMatthias Braun	src/firm/jump_target.c
51aabeb2edSMatthias Braun	src/firm/mangle.c
52aabeb2edSMatthias Braun	src/main.c
53aabeb2edSMatthias Braun	src/parser/builtins.c
54aabeb2edSMatthias Braun	src/parser/format_check.c
55aabeb2edSMatthias Braun	src/parser/input.c
56aabeb2edSMatthias Braun	src/parser/parser.c
57aabeb2edSMatthias Braun	src/parser/preprocessor.c
58aabeb2edSMatthias Braun	src/parser/token.c
59aabeb2edSMatthias Braun	src/wrappergen/write_compoundsizes.c
60aabeb2edSMatthias Braun	src/wrappergen/write_fluffy.c
61aabeb2edSMatthias Braun	src/wrappergen/write_jna.c
62aabeb2edSMatthias Braun)
63aabeb2edSMatthias Brauninclude_directories(src)
64aabeb2edSMatthias Braun
65bedf49a1SSebastian Grafadd_subdirectory(libfirm)
66bedf49a1SSebastian Graf# Also include generated header files which are dropped into firm's BINARY_DIR.
67be2d414bSSebastian Grafinclude_directories(libfirm/include ${libfirm_BINARY_DIR}/gen/include/libfirm)
68aabeb2edSMatthias Braun
69aabeb2edSMatthias Braunadd_executable(cparser ${SOURCES})
70bedf49a1SSebastian Graftarget_link_libraries(cparser firm)
718a914506SMatthias Braunif(UNIX)
728a914506SMatthias Braun	target_link_libraries(cparser m)
738a914506SMatthias Braunendif()
74aabeb2edSMatthias Braun
758a914506SMatthias Braunset(DEFAULT_SYSTEM_INCLUDE_DIR /usr/include)
768a914506SMatthias Braunif(APPLE)
778a914506SMatthias Braun	execute_process(COMMAND xcrun -show-sdk-path
788a914506SMatthias Braun		OUTPUT_VARIABLE SDK_PATH
798a914506SMatthias Braun		OUTPUT_STRIP_TRAILING_WHITESPACE
808a914506SMatthias Braun	)
818a914506SMatthias Braun	set(DEFAULT_SYSTEM_INCLUDE_DIR ${SDK_PATH}/usr/include)
828a914506SMatthias Braunendif()
838a914506SMatthias Braunset(SYSTEM_INCLUDE_DIR ${DEFAULT_SYSTEM_INCLUDE_DIR} CACHE PATH "system include directory")
848a914506SMatthias Braunset(LOCAL_INCLUDE_DIR /usr/local CACHE PATH "system local include directory")
857f084be8SMatthias Braunset(COMPILER_INCLUDE_DIR lib/cparser/${cparser_VERSION}/include CACHE STRING "compiler include dir (under CMAKE_INSTALL_PREFIX)")
86868a321bSMatthias Braunset(HOST_TRIPLE CACHE STRING "host machine triple (may be empty)")
878a914506SMatthias Braun
888a914506SMatthias Braunadd_definitions(-DSYSTEM_INCLUDE_DIR=\"${SYSTEM_INCLUDE_DIR}\")
898a914506SMatthias Braunadd_definitions(-DLOCAL_INCLUDE_DIR=\"${LOCAL_INCLUDE_DIR}\")
908a914506SMatthias Braunadd_definitions(-DCOMPILER_INCLUDE_DIR=\"${CMAKE_INSTALL_PREFIX}/${COMPILER_INCLUDE_DIR}\")
91868a321bSMatthias Braunif(HOST_TRIPLE)
92868a321bSMatthias Braun  add_definitions(-DHOST_TRIPLE=\"${HOST_TRIPLE}\")
93868a321bSMatthias Braunendif()
948a914506SMatthias Braun
958a914506SMatthias Braun# Produce revision.h
968a914506SMatthias Brauninclude_directories(${CMAKE_CURRENT_BINARY_DIR})
978a914506SMatthias Braunif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD)
98aabeb2edSMatthias Braun	set(REVISIONH "${CMAKE_CURRENT_BINARY_DIR}/revision.h")
99aabeb2edSMatthias Braun	set(REVGEN echo '\#define cparser_REVISION \"'`git describe --abbrev=40 --always --dirty --match ''`'\"')
100aabeb2edSMatthias Braun	add_custom_command(
101aabeb2edSMatthias Braun		OUTPUT ${REVISIONH}
1028a914506SMatthias Braun		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD
103aabeb2edSMatthias Braun		COMMAND ${REVGEN} | cmp -s - "${REVISIONH}" 2> /dev/null || ${REVGEN} > "${REVISIONH}"
1048a914506SMatthias Braun		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
105aabeb2edSMatthias Braun	)
106aabeb2edSMatthias Braun	SET_SOURCE_FILES_PROPERTIES(src/driver/actions.c PROPERTIES OBJECT_DEPENDS ${REVISIONH})
1078a914506SMatthias Braunelse()
1088a914506SMatthias Braun	file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/revision.h
1098a914506SMatthias Braun		 CONTENT "#define cparser_REVISION \"\"")
110aabeb2edSMatthias Braunendif()
1118a914506SMatthias Braun
1128a914506SMatthias Braun# Installation
1138a914506SMatthias Braunset(INSTALL_HEADERS
1148a914506SMatthias Braun	include/float.h
1158a914506SMatthias Braun	include/iso646.h
1168a914506SMatthias Braun	include/limits.h
1178a914506SMatthias Braun	include/stdarg.h
1188a914506SMatthias Braun	include/stdbool.h
1198a914506SMatthias Braun	include/stddef.h
1208a914506SMatthias Braun)
1218a914506SMatthias Brauninstall(FILES ${INSTALL_HEADERS} DESTINATION ${COMPILER_INCLUDE_DIR})
122c493a350SMatthias Brauninstall(FILES cparser.1 DESTINATION share/man/man1)
1238a914506SMatthias Brauninstall(TARGETS cparser DESTINATION bin)
124