Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start building as a shared library on Windows (DLL) #67

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
58 changes: 44 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@ 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()

IF(UNIX)
wravery marked this conversation as resolved.
Show resolved Hide resolved
SET(FLEX_COMPILE_FLAGS "--header-file=lexer.h")
ELSEIF(WIN32)
SET(FLEX_COMPILE_FLAGS "--header-file=lexer.h --wincompat")
ENDIF()

FIND_PROGRAM(CTYPESGEN_FOUND ctypesgen.py)

FIND_PACKAGE(BISON 3)
Expand All @@ -21,7 +44,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()
Expand Down Expand Up @@ -104,8 +127,10 @@ INSTALL(FILES
stack.hh
syntaxdefs.h
DESTINATION include/graphqlparser)

INSTALL(TARGETS graphqlparser
LIBRARY DESTINATION lib)
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

if (UNIX)
# generate pkgconfig file
Expand All @@ -116,16 +141,21 @@ if (UNIX)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libgraphqlparser.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()
endif()

IF (test)
ADD_SUBDIRECTORY(test)
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()
if(UNIX)
wravery marked this conversation as resolved.
Show resolved Hide resolved
# 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()
ENDIF()
elseif(WIN32)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphqlparser.lib
DESTINATION lib)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphqlparser.pdb
DESTINATION bin)
endif()