Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
actor-incubator
Commits
33d43236
Commit
33d43236
authored
Jan 29, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Harmonize incubator CMake scaffold with main repo
parent
4b373edb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
16 deletions
+46
-16
CMakeLists.txt
CMakeLists.txt
+32
-5
cmake/caf-generate-enum-strings.cpp
cmake/caf-generate-enum-strings.cpp
+14
-11
No files found.
CMakeLists.txt
View file @
33d43236
...
...
@@ -192,14 +192,41 @@ function(pretty_yes var)
endif
()
endfunction
(
pretty_yes
)
add_executable
(
caf-generate-enum-strings cmake/caf-generate-enum-strings.cpp
)
function
(
enum_to_string relative_input_file relative_output_file
)
set
(
input
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
relative_input_file
}
"
)
set
(
output
"
${
CMAKE_BINARY_DIR
}
/
${
relative_output_file
}
"
)
add_executable
(
caf-generate-enum-strings
EXCLUDE_FROM_ALL
cmake/caf-generate-enum-strings.cpp
)
add_custom_target
(
consistency-check
)
add_custom_target
(
update-enum-strings
)
# adds a consistency check that verifies that `cpp_file` is still valid by
# re-generating the file and comparing it to the existing file
function
(
add_enum_consistency_check hpp_file cpp_file
)
set
(
input
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
hpp_file
}
"
)
set
(
file_under_test
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
cpp_file
}
"
)
set
(
output
"
${
CMAKE_CURRENT_BINARY_DIR
}
/check/
${
cpp_file
}
"
)
get_filename_component
(
output_dir
"
${
output
}
"
DIRECTORY
)
file
(
MAKE_DIRECTORY
"
${
output_dir
}
"
)
add_custom_command
(
OUTPUT
"
${
output
}
"
COMMAND caf-generate-enum-strings
"
${
input
}
"
"
${
output
}
"
DEPENDS caf-generate-enum-strings
"
${
input
}
"
)
get_filename_component
(
target_name
"
${
input
}
"
NAME_WE
)
add_custom_target
(
"
${
target_name
}
"
COMMAND
"
${
CMAKE_COMMAND
}
"
"-Dfile_under_test=
${
file_under_test
}
"
"-Dgenerated_file=
${
output
}
"
-P
"
${
PROJECT_SOURCE_DIR
}
/cmake/check-consistency.cmake"
DEPENDS
"
${
output
}
"
)
add_dependencies
(
consistency-check
"
${
target_name
}
"
)
add_custom_target
(
"
${
target_name
}
-update"
COMMAND
caf-generate-enum-strings
"
${
input
}
"
"
${
file_under_test
}
"
DEPENDS caf-generate-enum-strings
"
${
input
}
"
)
add_dependencies
(
update-enum-strings
"
${
target_name
}
-update"
)
endfunction
()
# -- binary and library path setup ---------------------------------------------
...
...
cmake/caf-generate-enum-strings.cpp
View file @
33d43236
...
...
@@ -47,7 +47,7 @@ void keep_alnum(string& str) {
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
3
)
{
cerr
<<
"wrong number of arguments.
\n
"
<<
"usage: "
<<
argv
[
0
]
<<
"input-file output-file
\n
"
;
<<
"usage: "
<<
argv
[
0
]
<<
"
input-file output-file
\n
"
;
return
EXIT_FAILURE
;
}
std
::
ifstream
in
{
argv
[
1
]};
...
...
@@ -96,25 +96,27 @@ int main(int argc, char** argv) {
}
std
::
ofstream
out
{
argv
[
2
]};
if
(
!
out
)
{
cerr
<<
"unable to open output file: "
<<
argv
[
1
]
<<
'\n'
;
cerr
<<
"unable to open output file: "
<<
argv
[
2
]
<<
'\n'
;
return
EXIT_FAILURE
;
}
std
::
string
namespace_str
;
for
(
size_t
i
=
0
;
i
<
namespaces
.
size
()
-
1
;
++
i
)
namespace_str
+=
namespaces
[
i
]
+
"::"
;
namespace_str
+=
namespaces
[
namespaces
.
size
()
-
1
];
// Print file header.
out
<<
"#include
\"
"
<<
namespaces
[
0
];
out
<<
"// clang-format off
\n
"
<<
"// DO NOT EDIT: "
"this file is auto-generated by caf-generate-enum-strings.
\n
"
"// Run the target update-enum-strings if this file is out of sync.
\n
"
<<
"#include
\"
"
<<
namespaces
[
0
];
for
(
size_t
i
=
1
;
i
<
namespaces
.
size
();
++
i
)
out
<<
'/'
<<
namespaces
[
i
];
out
<<
'/'
<<
enum_name
<<
".hpp
\"\n\n
"
<<
"#include <string>
\n\n
"
<<
"namespace "
;
out
<<
namespace_str
<<
" {
\n
"
;
<<
"namespace "
<<
namespaces
[
0
]
<<
" {
\n
"
;
for
(
size_t
i
=
1
;
i
<
namespaces
.
size
();
++
i
)
out
<<
"namespace "
<<
namespaces
[
i
]
<<
" {
\n
"
;
out
<<
"
\n
std::string to_string("
<<
enum_name
<<
" x) {
\n
"
<<
" switch
(x) {
\n
"
<<
" switch(x) {
\n
"
<<
" default:
\n
"
<<
" return
\"
???
\"
;
\n
"
;
// Read until hitting the closing '}'.
std
::
string
case_label_prefix
;
if
(
is_enum_class
)
...
...
@@ -138,5 +140,6 @@ int main(int argc, char** argv) {
// Done. Print file footer and exit.
out
<<
" };
\n
"
<<
"}
\n\n
"
;
out
<<
"} // namespace "
<<
namespace_str
<<
'\n'
;
for
(
auto
i
=
namespaces
.
rbegin
();
i
!=
namespaces
.
rend
();
++
i
)
out
<<
"} // namespace "
<<
*
i
<<
'\n'
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment