Skip to content

Commit d557b9d

Browse files
authored
Merge pull request #146 from wravery/master
Fix #145
2 parents 54baee1 + e9baddc commit d557b9d

File tree

14 files changed

+208
-9
lines changed

14 files changed

+208
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ with `schemagen`, you can look at [samples/CMakeLists.txt](samples/CMakeLists.tx
9393
```
9494
Usage: schemagen [options] <schema file> <output filename prefix> <output namespace>
9595
Command line options:
96+
--version Print the version number
9697
-? [ --help ] Print the command line options
9798
-v [ --verbose ] Verbose output including generated header names as
9899
well as sources

cmake/SchemaGen.rc.in

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#include <winver.h>
5+
6+
#define SCHEMAGEN_RC_VERSION @SCHEMAGEN_RC_VERSION@
7+
#define SCHEMAGEN_RC_VERSION_STR "@SCHEMAGEN_RC_VERSION_STR@"
8+
9+
#ifndef DEBUG
10+
#define VER_DEBUG 0
11+
#else
12+
#define VER_DEBUG VS_FF_DEBUG
13+
#endif
14+
15+
VS_VERSION_INFO VERSIONINFO
16+
FILEVERSION SCHEMAGEN_RC_VERSION
17+
PRODUCTVERSION SCHEMAGEN_RC_VERSION
18+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
19+
FILEFLAGS VER_DEBUG
20+
FILEOS VOS__WINDOWS32
21+
FILETYPE VFT_APP
22+
FILESUBTYPE VFT2_UNKNOWN
23+
BEGIN
24+
BLOCK "StringFileInfo"
25+
BEGIN
26+
BLOCK "040904B0"
27+
BEGIN
28+
VALUE "CompanyName", "Microsoft Corporation"
29+
VALUE "FileDescription", "Code generator for https://github.com/microsoft/cppgraphqlgen"
30+
VALUE "FileVersion", SCHEMAGEN_RC_VERSION_STR
31+
VALUE "InternalName", "schemagen"
32+
VALUE "LegalCopyright", "Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License."
33+
VALUE "OriginalFilename", "schemagen.exe"
34+
VALUE "ProductName", "CppGraphQLGen"
35+
VALUE "ProductVersion", SCHEMAGEN_RC_VERSION_STR
36+
END
37+
END
38+
39+
BLOCK "VarFileInfo"
40+
BEGIN
41+
VALUE "Translation", 0x409, 1200
42+
END
43+
END

cmake/Version.h.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#pragma once
5+
6+
#ifndef VERSION_H
7+
#define VERSION_H
8+
9+
#include <string_view>
10+
11+
namespace graphql::internal {
12+
13+
constexpr std::string_view FullVersion { "@PROJECT_VERSION@" };
14+
15+
constexpr size_t MajorVersion = @PROJECT_VERSION_MAJOR@;
16+
constexpr size_t MinorVersion = @PROJECT_VERSION_MINOR@;
17+
constexpr size_t PatchVersion = @PROJECT_VERSION_PATCH@;
18+
19+
} // namespace graphql::internal
20+
21+
#endif // VERSION_H

cmake/Version.rc.in

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#include <winver.h>
5+
6+
#define GRAPHQL_RC_VERSION @GRAPHQL_RC_VERSION@
7+
#define GRAPHQL_RC_VERSION_STR "@GRAPHQL_RC_VERSION_STR@"
8+
9+
#ifndef DEBUG
10+
#define VER_DEBUG 0
11+
#else
12+
#define VER_DEBUG VS_FF_DEBUG
13+
#endif
14+
15+
VS_VERSION_INFO VERSIONINFO
16+
FILEVERSION GRAPHQL_RC_VERSION
17+
PRODUCTVERSION GRAPHQL_RC_VERSION
18+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
19+
FILEFLAGS VER_DEBUG
20+
FILEOS VOS__WINDOWS32
21+
FILETYPE VFT_DLL
22+
FILESUBTYPE VFT2_UNKNOWN
23+
BEGIN
24+
BLOCK "StringFileInfo"
25+
BEGIN
26+
BLOCK "040904B0"
27+
BEGIN
28+
VALUE "CompanyName", "Microsoft Corporation"
29+
VALUE "FileDescription", "Shared library for https://github.com/microsoft/cppgraphqlgen"
30+
VALUE "FileVersion", GRAPHQL_RC_VERSION_STR
31+
VALUE "InternalName", "@GRAPHQL_RC_FILENAME@"
32+
VALUE "LegalCopyright", "Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License."
33+
VALUE "OriginalFilename", "@GRAPHQL_RC_FILENAME@.dll"
34+
VALUE "ProductName", "CppGraphQLGen"
35+
VALUE "ProductVersion", GRAPHQL_RC_VERSION_STR
36+
END
37+
END
38+
39+
BLOCK "VarFileInfo"
40+
BEGIN
41+
VALUE "Translation", 0x409, 1200
42+
END
43+
END

cmake/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.0
1+
3.4.1

include/graphqlservice/GraphQLService.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
#include "graphqlservice/GraphQLParse.h"
2222
#include "graphqlservice/GraphQLResponse.h"
23+
2324
#include "graphqlservice/internal/SortedMap.h"
25+
#include "graphqlservice/internal/Version.h"
2426

2527
#include <functional>
2628
#include <future>

samples/introspection/IntrospectionSchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "graphqlservice/GraphQLSchema.h"
1010
#include "graphqlservice/GraphQLService.h"
1111

12+
// Check if the library version is compatible with schemagen 3.4.1
13+
static_assert(graphql::internal::MajorVersion == 3, "regenerate with schemagen: major version mismatch");
14+
static_assert(graphql::internal::MinorVersion == 4, "regenerate with schemagen: minor version mismatch");
15+
1216
// clang-format off
1317
#ifdef GRAPHQL_DLLEXPORTS
1418
#ifdef IMPL_GRAPHQLINTROSPECTION_DLL

samples/separate/TodaySchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "graphqlservice/GraphQLSchema.h"
1010
#include "graphqlservice/GraphQLService.h"
1111

12+
// Check if the library version is compatible with schemagen 3.4.1
13+
static_assert(graphql::internal::MajorVersion == 3, "regenerate with schemagen: major version mismatch");
14+
static_assert(graphql::internal::MinorVersion == 4, "regenerate with schemagen: minor version mismatch");
15+
1216
#include <memory>
1317
#include <string>
1418
#include <vector>

samples/separate_nointrospection/TodaySchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "graphqlservice/GraphQLSchema.h"
1010
#include "graphqlservice/GraphQLService.h"
1111

12+
// Check if the library version is compatible with schemagen 3.4.1
13+
static_assert(graphql::internal::MajorVersion == 3, "regenerate with schemagen: major version mismatch");
14+
static_assert(graphql::internal::MinorVersion == 4, "regenerate with schemagen: minor version mismatch");
15+
1216
#include <memory>
1317
#include <string>
1418
#include <vector>

samples/unified/TodaySchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "graphqlservice/GraphQLSchema.h"
1010
#include "graphqlservice/GraphQLService.h"
1111

12+
// Check if the library version is compatible with schemagen 3.4.1
13+
static_assert(graphql::internal::MajorVersion == 3, "regenerate with schemagen: major version mismatch");
14+
static_assert(graphql::internal::MinorVersion == 4, "regenerate with schemagen: minor version mismatch");
15+
1216
#include <memory>
1317
#include <string>
1418
#include <vector>

samples/unified_nointrospection/TodaySchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "graphqlservice/GraphQLSchema.h"
1010
#include "graphqlservice/GraphQLService.h"
1111

12+
// Check if the library version is compatible with schemagen 3.4.1
13+
static_assert(graphql::internal::MajorVersion == 3, "regenerate with schemagen: major version mismatch");
14+
static_assert(graphql::internal::MinorVersion == 4, "regenerate with schemagen: minor version mismatch");
15+
1216
#include <memory>
1317
#include <string>
1418
#include <vector>

samples/validation/ValidationSchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "graphqlservice/GraphQLSchema.h"
1010
#include "graphqlservice/GraphQLService.h"
1111

12+
// Check if the library version is compatible with schemagen 3.4.1
13+
static_assert(graphql::internal::MajorVersion == 3, "regenerate with schemagen: major version mismatch");
14+
static_assert(graphql::internal::MinorVersion == 4, "regenerate with schemagen: minor version mismatch");
15+
1216
#include <memory>
1317
#include <string>
1418
#include <vector>

src/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33

44
cmake_minimum_required(VERSION 3.8.2)
55

6+
# internal/Version.h
7+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Version.h.in
8+
${CMAKE_CURRENT_BINARY_DIR}/../include/graphqlservice/internal/Version.h
9+
@ONLY)
10+
11+
if(WIN32 AND BUILD_SHARED_LIBS)
12+
# Version.rc
13+
set(GRAPHQL_RC_VERSION "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
14+
set(GRAPHQL_RC_VERSION_STR "${PROJECT_VERSION}")
15+
16+
function(add_version_rc target)
17+
set(GRAPHQL_RC_FILENAME "${target}")
18+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Version.rc.in
19+
${CMAKE_CURRENT_BINARY_DIR}/${target}_version.rc
20+
@ONLY)
21+
add_library(${target}_version OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${target}_version.rc)
22+
target_link_libraries(${target} PRIVATE ${target}_version)
23+
endfunction()
24+
endif()
25+
626
function(add_bigobj_flag target)
727
if(MSVC)
828
# MSVC requires the /bigobj flag if the number of sections gets too big.
@@ -24,6 +44,8 @@ if(WIN32 AND BUILD_SHARED_LIBS)
2444
target_compile_definitions(graphqlpeg
2545
PUBLIC GRAPHQL_DLLEXPORTS
2646
PRIVATE IMPL_GRAPHQLPEG_DLL)
47+
48+
add_version_rc(graphqlpeg)
2749
endif()
2850

2951
# graphqlresponse
@@ -37,12 +59,16 @@ if(WIN32 AND BUILD_SHARED_LIBS)
3759
target_compile_definitions(graphqlresponse
3860
PUBLIC GRAPHQL_DLLEXPORTS
3961
PRIVATE IMPL_GRAPHQLRESPONSE_DLL)
62+
63+
add_version_rc(graphqlresponse)
4064
endif()
4165

4266
# schemagen
4367
if(GRAPHQL_BUILD_SCHEMAGEN)
4468
add_executable(schemagen SchemaGenerator.cpp)
4569
add_executable(cppgraphqlgen::schemagen ALIAS schemagen)
70+
target_include_directories(schemagen PRIVATE
71+
${CMAKE_CURRENT_BINARY_DIR}/../include)
4672
target_link_libraries(schemagen PRIVATE
4773
graphqlpeg
4874
graphqlresponse)
@@ -101,6 +127,18 @@ if(GRAPHQL_BUILD_SCHEMAGEN)
101127

102128
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
103129
target_link_libraries(schemagen PRIVATE ${BOOST_LIBRARIES})
130+
131+
if(WIN32)
132+
# SchemaGen.rc
133+
set(SCHEMAGEN_RC_VERSION "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
134+
set(SCHEMAGEN_RC_VERSION_STR "${PROJECT_VERSION}")
135+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/SchemaGen.rc.in
136+
${CMAKE_CURRENT_BINARY_DIR}/SchemaGen.rc
137+
@ONLY)
138+
139+
add_library(schemagen_version OBJECT ${CMAKE_CURRENT_BINARY_DIR}/SchemaGen.rc)
140+
target_link_libraries(schemagen PRIVATE schemagen_version)
141+
endif()
104142

105143
install(TARGETS schemagen
106144
EXPORT cppgraphqlgen-targets
@@ -170,6 +208,8 @@ if(WIN32 AND BUILD_SHARED_LIBS)
170208
target_compile_definitions(graphqlservice_nointrospection
171209
PUBLIC GRAPHQL_DLLEXPORTS
172210
PRIVATE IMPL_GRAPHQLSERVICE_DLL)
211+
212+
add_version_rc(graphqlservice_nointrospection)
173213
endif()
174214

175215
# graphqlservice
@@ -183,6 +223,8 @@ if(WIN32 AND BUILD_SHARED_LIBS)
183223
target_compile_definitions(graphqlservice
184224
PUBLIC GRAPHQL_DLLEXPORTS
185225
PRIVATE IMPL_GRAPHQLINTROSPECTION_DLL)
226+
227+
add_version_rc(graphqlservice)
186228
endif()
187229

188230
# RapidJSON is the only option for JSON serialization used in this project, but if you want
@@ -206,6 +248,8 @@ if(GRAPHQL_USE_RAPIDJSON)
206248
target_compile_definitions(graphqljson
207249
PUBLIC GRAPHQL_DLLEXPORTS
208250
PRIVATE IMPL_JSONRESPONSE_DLL)
251+
252+
add_version_rc(graphqljson)
209253
endif()
210254
endif()
211255

@@ -249,6 +293,7 @@ install(FILES
249293

250294
install(FILES
251295
${CMAKE_CURRENT_SOURCE_DIR}/../include/graphqlservice/internal/SortedMap.h
296+
${CMAKE_CURRENT_BINARY_DIR}/../include/graphqlservice/internal/Version.h
252297
CONFIGURATIONS ${GRAPHQL_INSTALL_CONFIGURATIONS}
253298
DESTINATION ${GRAPHQL_INSTALL_INCLUDE_DIR}/graphqlservice/internal)
254299

src/SchemaGenerator.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,13 @@ bool Generator::outputHeader() const noexcept
16911691
headerFile << R"cpp(#include "graphqlservice/GraphQLSchema.h"
16921692
#include "graphqlservice/GraphQLService.h"
16931693
1694+
// Check if the library version is compatible with schemagen )cpp"
1695+
<< graphql::internal::FullVersion << R"cpp(
1696+
static_assert(graphql::internal::MajorVersion == )cpp"
1697+
<< graphql::internal::MajorVersion << R"cpp(, "regenerate with schemagen: major version mismatch");
1698+
static_assert(graphql::internal::MinorVersion == )cpp"
1699+
<< graphql::internal::MinorVersion << R"cpp(, "regenerate with schemagen: minor version mismatch");
1700+
16941701
)cpp";
16951702
if (_isIntrospection)
16961703
{
@@ -2602,7 +2609,8 @@ Operations::Operations()cpp";
26022609
{
26032610
bool firstValue = true;
26042611

2605-
sourceFile << R"cpp( type)cpp" << unionType.cppType << R"cpp(->AddPossibleTypes({
2612+
sourceFile << R"cpp( type)cpp" << unionType.cppType
2613+
<< R"cpp(->AddPossibleTypes({
26062614
)cpp";
26072615

26082616
for (const auto& unionOption : unionType.options)
@@ -3673,12 +3681,16 @@ using namespace std::literals;
36733681

36743682
namespace po = boost::program_options;
36753683

3684+
void outputVersion(std::ostream& ostm)
3685+
{
3686+
ostm << graphql::internal::FullVersion << std::endl;
3687+
}
3688+
36763689
void outputUsage(std::ostream& ostm, const po::options_description& options)
36773690
{
3678-
std::cerr
3679-
<< "Usage:\tschemagen [options] <schema file> <output filename prefix> <output namespace>"
3680-
<< std::endl;
3681-
std::cerr << options;
3691+
ostm << "Usage:\tschemagen [options] <schema file> <output filename prefix> <output namespace>"
3692+
<< std::endl;
3693+
ostm << options;
36823694
}
36833695

36843696
int main(int argc, char** argv)
@@ -3688,6 +3700,7 @@ int main(int argc, char** argv)
36883700
po::options_description internalOptions("Internal options");
36893701
po::variables_map variables;
36903702
bool showUsage = false;
3703+
bool showVersion = false;
36913704
bool buildIntrospection = false;
36923705
bool buildCustom = false;
36933706
bool noStubs = false;
@@ -3700,8 +3713,10 @@ int main(int argc, char** argv)
37003713
std::string sourceDir;
37013714
std::string headerDir;
37023715

3703-
options.add_options()("help,?", po::bool_switch(&showUsage), "Print the command line options")(
3704-
"verbose,v",
3716+
options.add_options()("version", po::bool_switch(&showVersion), "Print the version number")(
3717+
"help,?",
3718+
po::bool_switch(&showUsage),
3719+
"Print the command line options")("verbose,v",
37053720
po::bool_switch(&verbose),
37063721
"Verbose output including generated header names as well as sources")("schema,s",
37073722
po::value(&schemaFileName),
@@ -3762,7 +3777,12 @@ int main(int argc, char** argv)
37623777
return 1;
37633778
}
37643779

3765-
if (showUsage || (!buildIntrospection && !buildCustom))
3780+
if (showVersion)
3781+
{
3782+
outputVersion(std::cout);
3783+
return 0;
3784+
}
3785+
else if (showUsage || (!buildIntrospection && !buildCustom))
37663786
{
37673787
outputUsage(std::cout, options);
37683788
return 0;

0 commit comments

Comments
 (0)