summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-12-06 07:54:41 +0100
committerMatthias Braun <matze@braunis.de>2015-12-06 09:29:31 +0100
commit8a914506bbaaaff0a918bcd86eb66eb9eb434180 (patch)
tree2c9d8875c3588dda9f5aee33c10beb2e49ab32ca /CMakeLists.txt
parent23040a2322780eee697e6c87be87c9d73d9e4ea3 (diff)
Update CMakeLists.txt
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt65
1 files changed, 57 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index accf182..1f0d1b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,21 @@
-cmake_minimum_required(VERSION 3.0)
-cmake_policy(SET CMP0042 NEW)
-cmake_policy(SET CMP0028 NEW)
+cmake_minimum_required(VERSION 2.8.12)
+if(POLICY CMP0042)
+ cmake_policy(SET CMP0042 NEW)
+endif()
+if(POLICY CMP0028)
+ cmake_policy(SET CMP0028 NEW)
+endif()
project(cparser)
+set(cparser_VERSION "1.22.0")
+
+# Enable C99
+if(CMAKE_VERSION VERSION_LESS "3.1")
+ if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ set(CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
+ endif()
+else()
+ set(CMAKE_C_STANDARD 99)
+endif()
set(SOURCES
src/adt/pset_new.c
@@ -52,17 +66,52 @@ find_package(libfirm REQUIRED)
include_directories(${libfirm_INCLUDE_DIRS})
add_executable(cparser ${SOURCES})
-target_link_libraries(cparser LINK_PRIVATE libfirm::firm)
+target_link_libraries(cparser libfirm::firm)
+if(UNIX)
+ target_link_libraries(cparser m)
+endif()
-# release tarballs have src/revision.h but git checkout need a new one created
-if(NOT EXISTS src/revision.h)
- include_directories(${CMAKE_CURRENT_BINARY_DIR})
+set(DEFAULT_SYSTEM_INCLUDE_DIR /usr/include)
+if(APPLE)
+ execute_process(COMMAND xcrun -show-sdk-path
+ OUTPUT_VARIABLE SDK_PATH
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ set(DEFAULT_SYSTEM_INCLUDE_DIR ${SDK_PATH}/usr/include)
+endif()
+set(SYSTEM_INCLUDE_DIR ${DEFAULT_SYSTEM_INCLUDE_DIR} CACHE PATH "system include directory")
+set(LOCAL_INCLUDE_DIR /usr/local CACHE PATH "system local include directory")
+set(COMPILER_INCLUDE_DIR lib/cparser/${cparser_VERSION} CACHE STRING "compiler include dir (under CMAKE_INSTALL_PREFIX)")
+
+add_definitions(-DSYSTEM_INCLUDE_DIR=\"${SYSTEM_INCLUDE_DIR}\")
+add_definitions(-DLOCAL_INCLUDE_DIR=\"${LOCAL_INCLUDE_DIR}\")
+add_definitions(-DCOMPILER_INCLUDE_DIR=\"${CMAKE_INSTALL_PREFIX}/${COMPILER_INCLUDE_DIR}\")
+
+# Produce revision.h
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD)
set(REVISIONH "${CMAKE_CURRENT_BINARY_DIR}/revision.h")
set(REVGEN echo '\#define cparser_REVISION \"'`git describe --abbrev=40 --always --dirty --match ''`'\"')
add_custom_command(
OUTPUT ${REVISIONH}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD
COMMAND ${REVGEN} | cmp -s - "${REVISIONH}" 2> /dev/null || ${REVGEN} > "${REVISIONH}"
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
SET_SOURCE_FILES_PROPERTIES(src/driver/actions.c PROPERTIES OBJECT_DEPENDS ${REVISIONH})
+else()
+ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/revision.h
+ CONTENT "#define cparser_REVISION \"\"")
endif()
+
+# Installation
+set(INSTALL_HEADERS
+ include/float.h
+ include/iso646.h
+ include/limits.h
+ include/stdarg.h
+ include/stdbool.h
+ include/stddef.h
+)
+install(FILES ${INSTALL_HEADERS} DESTINATION ${COMPILER_INCLUDE_DIR})
+install(TARGETS cparser DESTINATION bin)