@@ -8,16 +8,17 @@ macro(generate_preprocessed_file preprocessed_file_out cpp_file)
8
8
target_compile_options ( ${cpp_file} _OBJECTS BEFORE PUBLIC -E ${GT_CXX_FLAGS} )
9
9
target_link_libraries ( ${cpp_file} _OBJECTS common )
10
10
11
- # now use the preprocessed file to generate a library (which we will never use) ...
12
- add_library ( dummy_${cpp_file} STATIC EXCLUDE_FROM_ALL $<TARGET_OBJECTS:${cpp_file} _OBJECTS>)
13
- # ... but before linking we copy the preprocessed file to the given file "preprocessed_file_out"
14
- # this trick is necessary because $<TARGET_OBJECTS:XXX> is only defined within add_library
15
- add_custom_command ( TARGET dummy_${cpp_file} PRE_LINK
16
- COMMAND ${CMAKE_COMMAND} -E copy '$<TARGET_OBJECTS:${cpp_file} _OBJECTS>' ${preprocessed_file_out}
17
- )
18
-
19
11
# add a target for the generated file
20
- add_custom_command ( OUTPUT ${preprocessed_file_out} COMMAND "" DEPENDS dummy_${cpp_file} )
12
+ add_custom_command ( OUTPUT ${preprocessed_file_out}
13
+ COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:${cpp_file} _OBJECTS> ${preprocessed_file_out}
14
+ DEPENDS ${cpp_file} _OBJECTS $<TARGET_OBJECTS:${cpp_file} _OBJECTS>
15
+ COMMENT "Extract generated code"
16
+ )
17
+
18
+ get_filename_component (generated_target_name ${preprocessed_file_out} NAME_WE )
19
+ add_custom_target (${generated_target_name}
20
+ DEPENDS ${preprocessed_file_out}
21
+ )
21
22
else ()
22
23
message ( ERROR "In macro generate_preprocessed_file: ${cpp_file} is not a file" )
23
24
endif ()
@@ -29,22 +30,20 @@ if (GT_ENABLE_TARGET_X86)
29
30
generate_preprocessed_file( ${GENERATED_REPOSITORY} plain_repository_generator.cpp )
30
31
31
32
# clean the preprocessed file from comments and from everything before our class starts
32
- add_custom_target ( process_generated_repository
33
+ add_custom_command ( OUTPUT ${GENERATED_REPOSITORY}
33
34
# remove all lines starting with '#'
34
35
# remove everything before "class my_repository"
35
36
COMMAND sed "/^#/d" ${GENERATED_REPOSITORY} | awk "/class my_repository/,0" > ${GENERATED_REPOSITORY} _tmp
36
37
COMMAND cp ${GENERATED_REPOSITORY} _tmp ${GENERATED_REPOSITORY}
37
- DEPENDS ${GENERATED_REPOSITORY}
38
+ APPEND
38
39
)
39
40
40
41
# format the generated file if we can
41
42
if ( CLANG_FORMAT_FOUND )
42
- add_custom_target ( format_generated_repository COMMAND ${CLANG_FORMAT_BIN} -i ${GENERATED_REPOSITORY}
43
- DEPENDS process_generated_repository
43
+ add_custom_command (OUTPUT ${GENERATED_REPOSITORY}
44
+ COMMAND ${CLANG_FORMAT_BIN} -i ${GENERATED_REPOSITORY}
45
+ APPEND
44
46
)
45
- else ()
46
- #dummy target for dependency
47
- add_custom_target ( format_generated_repository COMMAND "" DEPENDS process_generated_repository)
48
47
endif ()
49
48
50
49
# generate the driver
@@ -59,7 +58,7 @@ if (GT_ENABLE_TARGET_X86)
59
58
LABELS unittest_x86 target_x86
60
59
ENVIRONMENT ${TEST_HOST_ENVIRONMENT}
61
60
)
62
- add_dependencies ( custom_test_generated_repository format_generated_repository )
61
+ add_dependencies (custom_test_generated_repository generated_repository )
63
62
endif ()
64
63
65
64
# collect test cases
0 commit comments