* Add support for libgraphqlparser in Windows and Linux

* Make the vcpkg_find_acquire_package calls run only for WIN32

* Switch to a SHARED library on Windows (DLL)
This commit is contained in:
Bill Avery 2018-08-03 00:11:55 -07:00 committed by Robert Schumacher
parent c3d34e7d8e
commit 09ccd053db
3 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Source: graphqlparser
Version: v0.7.0
Description: A GraphQL query parser in C++ with C and C++ APIs

View File

@ -0,0 +1,51 @@
# Common Ambient Variables:
# CURRENT_BUILDTREES_DIR = ${VCPKG_ROOT_DIR}\buildtrees\${PORT}
# CURRENT_PACKAGES_DIR = ${VCPKG_ROOT_DIR}\packages\${PORT}_${TARGET_TRIPLET}
# CURRENT_PORT_DIR = ${VCPKG_ROOT_DIR}\ports\${PORT}
# PORT = current port name (zlib, etc)
# TARGET_TRIPLET = current triplet (x86-windows, x64-windows-static, etc)
# VCPKG_CRT_LINKAGE = C runtime linkage type (static, dynamic)
# VCPKG_LIBRARY_LINKAGE = target library linkage type (static, dynamic)
# VCPKG_ROOT_DIR = <C:\path\to\current\vcpkg>
# VCPKG_TARGET_ARCHITECTURE = target architecture (x64, x86, arm)
#
include(vcpkg_common_functions)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO graphql/libgraphqlparser
REF v0.7.0
SHA512 973292b164d0d2cfe453a2f01559dbdb1b9d22b6304f6a3aabf71e2c0a3e24ab69dfd72a086764ad5befecf0005620f8e86f552dacc324f9615a05f31de7cede
HEAD_REF master
PATCHES ${CMAKE_CURRENT_LIST_DIR}/win-cmake.patch
)
if(UNIX)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
)
elseif(WIN32)
vcpkg_find_acquire_program(PYTHON2)
vcpkg_find_acquire_program(FLEX)
vcpkg_find_acquire_program(BISON)
get_filename_component(VCPKG_DOWNLOADS_PYTHON2_DIR "${PYTHON2}" DIRECTORY)
get_filename_component(VCPKG_DOWNLOADS_FLEX_DIR "${FLEX}" DIRECTORY)
get_filename_component(VCPKG_DOWNLOADS_BISON_DIR "${BISON}" DIRECTORY)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
-DVCPKG_DOWNLOADS_PYTHON2_DIR=${VCPKG_DOWNLOADS_PYTHON2_DIR}
-DVCPKG_DOWNLOADS_FLEX_DIR=${VCPKG_DOWNLOADS_FLEX_DIR}
-DVCPKG_DOWNLOADS_BISON_DIR=${VCPKG_DOWNLOADS_BISON_DIR}
)
endif()
vcpkg_install_cmake()
# Handle copyright
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/graphqlparser RENAME copyright)

View File

@ -0,0 +1,104 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c4c8b3e..f19cda3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,16 +3,37 @@ PROJECT(libgraphqlparser C CXX)
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
-INCLUDE(version)
+IF(UNIX)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
+ SET(FLEX_COMPILE_FLAGS "--header-file=lexer.h")
+ELSEIF(WIN32)
+ # If we're building this with vcpkg on Windows, let portfile.cmake tell us where it
+ # stored these tools. Otherwise these variables should be empty and we'll fall back
+ # to the normal CMake FIND_PACKAGE logic for each of these programs.
+ SET(CMAKE_PROGRAM_PATH
+ "${VCPKG_DOWNLOADS_PYTHON2_DIR}"
+ "${VCPKG_DOWNLOADS_FLEX_DIR}"
+ "${VCPKG_DOWNLOADS_BISON_DIR}"
+ "${CMAKE_PROGRAM_PATH}")
+
+ SET(FLEX_COMPILE_FLAGS "--header-file=lexer.h --wincompat")
+
+ # Let CMake figure out the exports for the SHARED library (DLL) on Windows.
+ SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+ENDIF()
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
+INCLUDE(version)
FIND_PACKAGE(PythonInterp 2 REQUIRED)
IF (NOT PYTHON_VERSION_MAJOR EQUAL 2)
MESSAGE(FATAL_ERROR "Python 2 is required.")
ENDIF()
-FIND_PROGRAM(CTYPESGEN_FOUND ctypesgen.py)
+IF(UNIX)
+ SET(FLEX_COMPILE_FLAGS "--header-file=lexer.h")
+ELSEIF(WIN32)
+ SET(FLEX_COMPILE_FLAGS "--header-file=lexer.h --wincompat")
+ENDIF()
FIND_PACKAGE(BISON 3)
FIND_PACKAGE(FLEX)
@@ -21,7 +42,7 @@ IF (BISON_FOUND)
ENDIF()
IF(FLEX_FOUND)
- FLEX_TARGET(GraphQLScanner lexer.lpp ${CMAKE_CURRENT_SOURCE_DIR}/lexer.cpp COMPILE_FLAGS "--header-file=lexer.h")
+ FLEX_TARGET(GraphQLScanner lexer.lpp ${CMAKE_CURRENT_SOURCE_DIR}/lexer.cpp COMPILE_FLAGS ${FLEX_COMPILE_FLAGS})
IF (BISON_FOUND)
ADD_FLEX_BISON_DEPENDENCY(GraphQLScanner graphqlparser)
ENDIF()
@@ -83,11 +104,8 @@ GENERATE_AST_FILE(cxx_json_visitor_header JsonVisitor.h.inc)
GENERATE_AST_FILE(cxx_json_visitor_impl JsonVisitor.cpp.inc)
-ADD_SUBDIRECTORY(python)
-
-OPTION(test "Build tests." OFF)
-
INSTALL(DIRECTORY c ${CMAKE_CURRENT_BINARY_DIR}/c DESTINATION include/graphqlparser
+ CONFIGURATIONS Release
FILES_MATCHING PATTERN "*.h"
PATTERN "build" EXCLUDE)
@@ -103,9 +121,12 @@ INSTALL(FILES
position.hh
stack.hh
syntaxdefs.h
- DESTINATION include/graphqlparser)
+ DESTINATION include/graphqlparser
+ CONFIGURATIONS Release)
+
INSTALL(TARGETS graphqlparser
- LIBRARY DESTINATION lib)
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION bin)
if (UNIX)
# generate pkgconfig file
@@ -116,16 +137,9 @@ if (UNIX)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libgraphqlparser.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()
+elseif(WIN32)
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphqlparser.lib
+ DESTINATION lib)
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphqlparser.pdb
+ DESTINATION bin)
endif()
-
-IF (test)
- ADD_SUBDIRECTORY(test)
-
- if(UNIX)
- # setup valgrind
- ADD_CUSTOM_TARGET(memcheck
- valgrind --leak-check=full --suppressions=./test/valgrind.supp --dsymutil=yes --error-exitcode=1 ./test/runTests >/dev/null
- )
- endif()
-
-ENDIF()