@@ -131,40 +131,35 @@ endif()
131
131
#################
132
132
## .Net Test ##
133
133
#################
134
- # add_dotnet_test()
135
- # CMake function to generate and build dotnet test.
134
+ # add_dotnet_tfm_test()
135
+ # CMake function to generate and build dotnet test for a specific TFM.
136
+ # warning: only net6.0, net7.0 and net8.0 are supported
136
137
# Parameters:
137
138
# the dotnet filename
138
139
# e.g.:
139
- # add_dotnet_test(FooTests.cs)
140
- function (add_dotnet_test FILE_NAME)
141
- message (STATUS "Configuring test ${FILE_NAME} ..." )
140
+ # add_dotnet_test(FooTests.cs net8.0 )
141
+ function (add_dotnet_tfm_test FILE_NAME TEST_TFM )
142
+ message (STATUS " Configuring test ${FILE_NAME} ( ${TEST_TFM} ) ..." )
142
143
get_filename_component (TEST_NAME ${FILE_NAME} NAME_WE )
143
144
get_filename_component (COMPONENT_DIR ${FILE_NAME} DIRECTORY )
144
145
get_filename_component (COMPONENT_NAME ${COMPONENT_DIR} NAME )
145
146
146
147
set (DOTNET_TEST_DIR ${PROJECT_BINARY_DIR} /dotnet/${COMPONENT_NAME} /${TEST_NAME} )
147
- message (STATUS "build path: ${DOTNET_TEST_DIR} " )
148
-
149
- configure_file (
150
- ${PROJECT_SOURCE_DIR} /dotnet/Test .csproj.in
151
- ${DOTNET_TEST_DIR} /${TEST_NAME} .csproj
152
- @ONLY)
153
148
154
- add_custom_command (
155
- OUTPUT ${DOTNET_TEST_DIR} / ${TEST_NAME} .cs
156
- COMMAND ${CMAKE_COMMAND} -E make_directory ${DOTNET_TEST_DIR}
157
- COMMAND ${CMAKE_COMMAND} -E copy
158
- ${FILE_NAME}
159
- ${DOTNET_TEST_DIR} /
160
- MAIN_DEPENDENCY ${FILE_NAME}
161
- VERBATIM
162
- WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
149
+ if (TEST_TFM STREQUAL "net6.0" )
150
+ set (TEST_SUFFIX net60)
151
+ elseif (TEST_TFM STREQUAL "net7.0" )
152
+ set (TEST_SUFFIX net70)
153
+ elseif (TEST_TFM STREQUAL "net8.0" )
154
+ set (TEST_SUFFIX net80)
155
+ else ()
156
+ message (FATAL_ERROR "TFM: ${TEST_TFM} is not supported." )
157
+ endif ( )
163
158
164
159
add_custom_command (
165
- OUTPUT ${DOTNET_TEST_DIR} /timestamp
160
+ OUTPUT ${DOTNET_TEST_DIR} /timestamp_ ${TEST_SUFFIX}
166
161
COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
167
- ${DOTNET_EXECUTABLE} build --nologo -c Release ${TEST_NAME} .csproj
162
+ ${DOTNET_EXECUTABLE} build --nologo -- framework ${TEST_TFM} -c Release ${TEST_NAME} .csproj
168
163
COMMAND ${CMAKE_COMMAND} -E touch ${DOTNET_TEST_DIR} /timestamp
169
164
DEPENDS
170
165
${DOTNET_TEST_DIR} /${TEST_NAME} .csproj
@@ -174,40 +169,66 @@ function(add_dotnet_test FILE_NAME)
174
169
${DOTNET_TEST_DIR} /bin
175
170
${DOTNET_TEST_DIR} /obj
176
171
VERBATIM
177
- COMMENT "Compiling .Net ${COMPONENT_NAME} /${TEST_NAME} .cs (${DOTNET_TEST_DIR} /timestamp )"
172
+ COMMENT "Compiling .Net ${COMPONENT_NAME} /${TEST_NAME} .cs (${TEST_TFM} )"
178
173
WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
179
174
180
- add_custom_target (dotnet_${COMPONENT_NAME} _${TEST_NAME} ALL
175
+ add_custom_target (dotnet_${COMPONENT_NAME} _${TEST_NAME} _ ${TEST_SUFFIX} ALL
181
176
DEPENDS
182
- ${DOTNET_TEST_DIR} /timestamp
177
+ ${DOTNET_TEST_DIR} /timestamp_ ${TEST_SUFFIX}
183
178
WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
184
179
185
180
if (BUILD_TESTING)
186
- if (USE_DOTNET_6)
187
- add_test (
188
- NAME dotnet_${COMPONENT_NAME} _${TEST_NAME} _net60
189
- COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
190
- ${DOTNET_EXECUTABLE} test --nologo --framework net6.0 -c Release
191
- WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
192
- endif ()
193
- if (USE_DOTNET_7)
194
181
add_test (
195
- NAME dotnet_${COMPONENT_NAME} _${TEST_NAME} _net70
182
+ NAME dotnet_${COMPONENT_NAME} _${TEST_NAME} _ ${TEST_SUFFIX}
196
183
COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
197
- ${DOTNET_EXECUTABLE} test --nologo --framework net7.0 -c Release
184
+ ${DOTNET_EXECUTABLE} test --nologo --framework ${TEST_TFM} -c Release
198
185
WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
199
- endif ()
200
- if (USE_DOTNET_8)
201
- add_test (
202
- NAME dotnet_${COMPONENT_NAME} _${TEST_NAME} _net80
203
- COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
204
- ${DOTNET_EXECUTABLE} test --nologo --framework net8.0 -c Release
205
- WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
206
- endif ()
207
186
endif ()
208
- message (STATUS "Configuring test ${FILE_NAME} ...DONE" )
187
+ message (STATUS " Configuring test ${FILE_NAME} ( ${TEST_TFM} ) ...DONE" )
209
188
endfunction ()
210
189
190
+ # add_dotnet_test()
191
+ # CMake function to generate and build dotnet test.
192
+ # Currently only net6.0, net7.0 and net8.0 are supported
193
+ # Parameters:
194
+ # the dotnet filename
195
+ # e.g.:
196
+ # add_dotnet_test(FooTests.cs)
197
+ function (add_dotnet_test FILE_NAME)
198
+ message (STATUS "Configuring test ${FILE_NAME} ..." )
199
+ get_filename_component (TEST_NAME ${FILE_NAME} NAME_WE )
200
+ get_filename_component (COMPONENT_DIR ${FILE_NAME} DIRECTORY )
201
+ get_filename_component (COMPONENT_NAME ${COMPONENT_DIR} NAME )
202
+
203
+ set (DOTNET_TEST_DIR ${PROJECT_BINARY_DIR} /dotnet/${COMPONENT_NAME} /${TEST_NAME} )
204
+ message (STATUS "build path: ${DOTNET_TEST_DIR} " )
205
+
206
+ configure_file (
207
+ ${PROJECT_SOURCE_DIR} /dotnet/Test .csproj.in
208
+ ${DOTNET_TEST_DIR} /${TEST_NAME} .csproj
209
+ @ONLY)
210
+
211
+ add_custom_command (
212
+ OUTPUT ${DOTNET_TEST_DIR} /${TEST_NAME} .cs
213
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${DOTNET_TEST_DIR}
214
+ COMMAND ${CMAKE_COMMAND} -E copy
215
+ ${FILE_NAME}
216
+ ${DOTNET_TEST_DIR} /
217
+ MAIN_DEPENDENCY ${FILE_NAME}
218
+ VERBATIM
219
+ WORKING_DIRECTORY ${DOTNET_TEST_DIR} )
220
+
221
+ if (USE_DOTNET_6)
222
+ add_dotnet_tfm_test(${FILE_NAME} net6.0)
223
+ endif ()
224
+ if (USE_DOTNET_7)
225
+ add_dotnet_tfm_test(${FILE_NAME} net7.0)
226
+ endif ()
227
+ if (USE_DOTNET_8)
228
+ add_dotnet_tfm_test(${FILE_NAME} net8.0)
229
+ endif ()
230
+ message (STATUS "Configuring test ${FILE_NAME} ...DONE" )
231
+ endfunction ()
211
232
212
233
#######################
213
234
## DOTNET WRAPPERS ##
@@ -328,7 +349,7 @@ add_custom_target(dotnet_package ALL
328
349
# e.g.:
329
350
# add_dotnet_example(Foo.cs net48)
330
351
function (add_dotnet_example FILE_NAME EXAMPLE_TFM)
331
- message (STATUS "Configuring example ${FILE_NAME} ..." )
352
+ message (STATUS "Configuring example ${FILE_NAME} ( ${EXAMPLE_TFM} ) ..." )
332
353
get_filename_component (EXAMPLE_NAME ${FILE_NAME} NAME_WE )
333
354
get_filename_component (COMPONENT_DIR ${FILE_NAME} DIRECTORY )
334
355
get_filename_component (COMPONENT_NAME ${COMPONENT_DIR} NAME )
@@ -355,7 +376,7 @@ function(add_dotnet_example FILE_NAME EXAMPLE_TFM)
355
376
add_custom_command (
356
377
OUTPUT ${DOTNET_EXAMPLE_DIR} /timestamp
357
378
COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
358
- ${DOTNET_EXECUTABLE} build --nologo -r ${DOTNET_RID } -c Release ${EXAMPLE_NAME} .csproj
379
+ ${DOTNET_EXECUTABLE} build --nologo -- framework ${EXAMPLE_TFM } -c Release ${EXAMPLE_NAME} .csproj
359
380
COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
360
381
${DOTNET_EXECUTABLE} pack --nologo -c Release ${EXAMPLE_NAME} .csproj
361
382
COMMAND ${CMAKE_COMMAND} -E touch ${DOTNET_EXAMPLE_DIR} /timestamp
@@ -370,7 +391,7 @@ function(add_dotnet_example FILE_NAME EXAMPLE_TFM)
370
391
COMMENT "Compiling .Net ${COMPONENT_NAME} /${EXAMPLE_NAME} .cs for ${EXAMPLE_TFM} (${DOTNET_EXAMPLE_DIR} /timestamp)"
371
392
WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR} )
372
393
373
- add_custom_target (dotnet_${COMPONENT_NAME} _${EXAMPLE_NAME} ALL
394
+ add_custom_target (dotnet_${COMPONENT_NAME} _${EXAMPLE_NAME} _ ${EXAMPLE_TFM} ALL
374
395
DEPENDS
375
396
${DOTNET_EXAMPLE_DIR} /timestamp
376
397
WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR} )
@@ -379,8 +400,8 @@ function(add_dotnet_example FILE_NAME EXAMPLE_TFM)
379
400
add_test (
380
401
NAME dotnet_${COMPONENT_NAME} _${EXAMPLE_NAME} _${EXAMPLE_TFM}
381
402
COMMAND ${CMAKE_COMMAND} -E env --unset=TARGETNAME
382
- ${DOTNET_EXECUTABLE} run --no -build -r ${DOTNET_RID } -c Release ${EXAMPLE_NAME} .csproj
403
+ ${DOTNET_EXECUTABLE} run --no -build -- framework ${EXAMPLE_TFM } -c Release ${EXAMPLE_NAME} .csproj
383
404
WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR} )
384
405
endif ()
385
- message (STATUS "Configuring example ${FILE_NAME} done" )
406
+ message (STATUS "Configuring example ${FILE_NAME} ( ${EXAMPLE_TFM} ) done" )
386
407
endfunction ()
0 commit comments