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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@ 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=${CMAKE_CURRENT_BINARY_DIR}/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=${CMAKE_CURRENT_BINARY_DIR}/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)
Expand Down Expand Up @@ -39,7 +56,7 @@ ELSE()
ENDIF()

IF(FLEX_FOUND)
FLEX_TARGET(GraphQLScanner lexer.lpp ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp COMPILE_FLAGS "--header-file=${CMAKE_CURRENT_BINARY_DIR}/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_bison)
ENDIF()
Expand Down Expand Up @@ -121,8 +138,10 @@ INSTALL(FILES
JsonVisitor.h
${BISON_LOCATION_HEADER}
DESTINATION include/graphqlparser)

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

if (UNIX)
# generate pkgconfig file
Expand All @@ -133,6 +152,11 @@ 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)
Expand All @@ -144,5 +168,4 @@ IF (test)
valgrind --leak-check=full --suppressions=./test/valgrind.supp --dsymutil=yes --error-exitcode=1 ./test/runTests >/dev/null
)
endif()

ENDIF()
15 changes: 11 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
ADD_SUBDIRECTORY(googletest-release-1.8.0/googletest)
IF(UNIX)
ADD_SUBDIRECTORY(googletest-release-1.8.0/googletest)
INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
ELSEIF(WIN32)
FIND_PACKAGE(GTest REQUIRED)
ENDIF()

ENABLE_TESTING()

INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

FILE(COPY valgrind.supp DESTINATION .)

FILE(COPY kitchen-sink.graphql DESTINATION .)
Expand All @@ -16,7 +19,11 @@ FILE(COPY schema-kitchen-sink.json DESTINATION .)

ADD_EXECUTABLE(runTests ParserTests.cpp JsonVisitorTests.cpp BuildCAPI.c)

TARGET_LINK_LIBRARIES(runTests gtest gtest_main)
IF(UNIX)
TARGET_LINK_LIBRARIES(runTests gtest gtest_main)
ELSEIF(WIN32)
TARGET_LINK_LIBRARIES(runTests GTest::GTest GTest::Main)
ENDIF()

TARGET_LINK_LIBRARIES(runTests graphqlparser)

Expand Down
2 changes: 1 addition & 1 deletion test/ParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ TEST(ParserTests, ProducesCorrectOutputForSchemaKitchenSink) {
}

static void expectSchemaParsing(const char *queryStr) {
char buf[strlen("1.1-XXX: schema support disabled") + 1];
char buf[sizeof("1.1-XXX: schema support disabled")];
ASSERT_LT(strlen(queryStr), 999);
snprintf(
buf,
Expand Down