Skip to content

Commit 06dc945

Browse files
Update README.md Fixes #1
1 parent 9808095 commit 06dc945

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,35 @@ The respository has two parts - [Parser](https://github.com/AustinBrunkhorst/CPP
6262

6363
This is basic example of adding the prebuild step to an existing target in CMake.
6464

65-
**Note:** this assumes you have created empty files for `${META_GENERATED_HEADER}` and `${META_GENERATED_SOURCE}` and added it to the list of sources when calling `add_executable( )`. Otherwise, CMake will complain about the files not existing initially.
66-
6765
```CMake
68-
# assume a target has been created, with add_executable( ... )
6966
set(PROJECT_NAME "Example")
7067
68+
# assume this contains header files for this project
69+
set(PROJECT_HEADER_FILES ...)
70+
71+
# assume this contains source files for this project
72+
set(PROJECT_SOURCE_FILES ...)
73+
74+
# generated file names, in the build directory
75+
set(META_GENERATED_HEADER "${CMAKE_CURRENT_BINARY_DIR}/Meta.Generated.h")
76+
set(META_GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/Meta.Generated.cpp")
77+
78+
# create the project target
79+
add_executable(${PROJECT_NAME}
80+
${PROJECT_HEADER_FILES}
81+
${PROJECT_SOURCE_FILES}
82+
# make sure the generated header and source are included
83+
${META_GENERATED_HEADER}
84+
${META_GENERATED_SOURCE}
85+
)
86+
7187
# path to the reflection parser executable
7288
set(PARSE_TOOL_EXE "ReflectionParser.exe")
7389
7490
# input source file to pass to the reflection parser compiler
7591
# in this file, include any files that you want exposed to the parser
7692
set(PROJECT_META_HEADER "Reflection.h")
7793
78-
# generated file names
79-
set(META_GENERATED_HEADER "Meta.Generated.h")
80-
set(META_GENERATED_SOURCE "Meta.Generated.cpp")
81-
8294
# fetch all include directories for the project target
8395
get_property(DIRECTORIES TARGET ${PROJECT_NAME} PROPERTY INCLUDE_DIRECTORIES)
8496
@@ -101,10 +113,11 @@ else ()
101113
message(FATAL_ERROR "System include directories not implemented for this compiler.")
102114
endif ()
103115
104-
# add the prebuild command that invokes the reflection parser executable
116+
# add the command that invokes the reflection parser executable
117+
# whenever a header file in your project has changed
105118
add_custom_command(
106-
TARGET ${PROJECT_NAME}
107-
PRE_BUILD
119+
OUTPUT ${META_GENERATED_HEADER} ${META_GENERATED_SOURCE}
120+
DEPENDS ${PROJECT_HEADER_FILES}
108121
COMMAND call "${PARSE_TOOL_EXE}"
109122
--target-name "${PROJECT_NAME}"
110123
--in-source "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SOURCE_DIR}/${PROJECT_META_HEADER}"
@@ -214,7 +227,10 @@ struct SoundEffect
214227
int main(void)
215228
{
216229
// you can also use type meta::Type::Get( "SoundEffect" ) based on a string name
217-
Field volumeField = typeof( SoundEffect ).GetField( "volume" );
230+
Type soundEffectType = typeof( SoundEffect );
231+
232+
// the volume field in the SoundEffect struct
233+
Field volumeField = soundEffectType.GetField( "volume" );
218234

219235
// meta data for the volume field
220236
MetaManager &volumeMeta = soundEffectType.GetMeta( );
@@ -322,4 +338,4 @@ int main(void)
322338

323339
return 0;
324340
}
325-
```
341+
```

0 commit comments

Comments
 (0)