File tree Expand file tree Collapse file tree 10 files changed +31
-104
lines changed
samples/BlackJack/BlackJack_Server Expand file tree Collapse file tree 10 files changed +31
-104
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,28 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
202202set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /Binaries)
203203set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /Binaries)
204204
205+ function (configure_pch target precompile_header precomile_source) # optional additional compile arguments
206+ if (MSVC )
207+ get_target_property (_srcs ${target} SOURCES )
208+
209+ set (pch_output_filepath_arg)
210+ if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
211+ set_property (SOURCE ${precomile_source} APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /${target} .pch" )
212+ set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /${target} .pch" )
213+ set (pch_output_filepath_arg "/Fp${CMAKE_CURRENT_BINARY_DIR} /${target} .pch" )
214+ else ()
215+ # Don't specify output file so that VS may choose a config spefic location.
216+ # Otherwise Debug/Release builds will interfere with one another.
217+ endif ()
218+
219+ set_source_files_properties (${precomile_source} PROPERTIES COMPILE_FLAGS "/Yc${precompile_header} " )
220+ target_sources (${target} PRIVATE ${precomile_source} )
221+ # Note: as ${precomile_source} is also a SOURCE for ${target}, the below options will also be applied.
222+ # ${precomile_source} has /Yc option that will cause the shared /Yu to be ignored.
223+ target_compile_options (${target} PRIVATE /Yu${precompile_header} ${pch_output_filepath_arg} ${ARGN} )
224+ endif ()
225+ endfunction ()
226+
205227# These settings can be used by the test targets
206228set (Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} /include )
207229set (Casablanca_LIBRARY cpprest)
Original file line number Diff line number Diff line change @@ -10,13 +10,4 @@ add_executable(blackjackserver
1010
1111target_link_libraries (blackjackserver cpprest)
1212
13- if (MSVC )
14- get_target_property (_srcs blackjackserver SOURCES )
15- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
16- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /blackjack-server-stdafx.pch" )
17- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /blackjack-server-stdafx.pch" )
18- endif ()
19- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpblackjack-server-stdafx.pch /Zm120" )
20- target_sources (blackjackserver PRIVATE stdafx.cpp)
21- target_compile_options (blackjackserver PRIVATE /Yustdafx.h /Fpblackjack-server-stdafx.pch /Zm120)
22- endif ()
13+ configure_pch(blackjackserver stdafx.h stdafx.cpp /Zm120)
Original file line number Diff line number Diff line change @@ -174,18 +174,7 @@ else()
174174 message (FATAL_ERROR "Invalid implementation" )
175175endif ()
176176
177- if (MSVC )
178- get_target_property (_srcs cpprest SOURCES )
179-
180- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
181- set_property (SOURCE pch/stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /stdafx.pch" )
182- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /stdafx.pch" )
183- endif ()
184-
185- set_source_files_properties (pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Zm120" )
186- target_sources (cpprest PRIVATE pch/stdafx.cpp)
187- target_compile_options (cpprest PRIVATE /Yustdafx.h /Zm120)
188- endif ()
177+ configure_pch(cpprest stdafx.h pch/stdafx.cpp /Zm120)
189178
190179if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
191180 if (WERROR)
Original file line number Diff line number Diff line change @@ -32,18 +32,7 @@ else()
3232 target_link_libraries (httpclient_test PRIVATE httptest_utilities)
3333endif ()
3434
35- if (MSVC )
36- get_target_property (_srcs httpclient_test SOURCES )
37-
38- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
39- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /client-tests-stdafx.pch" )
40- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /client-tests-stdafx.pch" )
41- endif ()
42-
43- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpclient-tests-stdafx.pch" )
44- target_sources (httpclient_test PRIVATE stdafx.cpp)
45- target_compile_options (httpclient_test PRIVATE /Yustdafx.h /Fpclient-tests-stdafx.pch)
46- endif ()
35+ configure_pch(httpclient_test stdafx.h stdafx.cpp)
4736
4837if (NOT WIN32 )
4938 cpprest_find_boost()
Original file line number Diff line number Diff line change @@ -22,14 +22,5 @@ if(NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
2222 target_link_libraries (httplistener_test PRIVATE httptest_utilities)
2323 endif ()
2424
25- if (MSVC )
26- get_target_property (_srcs httplistener_test SOURCES )
27- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
28- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /listener-tests-stdafx.pch" )
29- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /listener-tests-stdafx.pch" )
30- endif ()
31- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fplistener-tests-stdafx.pch" )
32- target_sources (httplistener_test PRIVATE stdafx.cpp)
33- target_compile_options (httplistener_test PRIVATE /Yustdafx.h /Fplistener-tests-stdafx.pch)
34- endif ()
25+ configure_pch(httplistener_test stdafx.h stdafx.cpp)
3526endif ()
Original file line number Diff line number Diff line change @@ -16,15 +16,4 @@ if(UNIX AND NOT APPLE)
1616 target_link_libraries (json_test PRIVATE cpprestsdk_boost_internal)
1717endif ()
1818
19- if (MSVC )
20- get_target_property (_srcs json_test SOURCES )
21-
22- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
23- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /json-tests-stdafx.pch" )
24- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /json-tests-stdafx.pch" )
25- endif ()
26-
27- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpjson-tests-stdafx.pch" )
28- target_sources (json_test PRIVATE stdafx.cpp)
29- target_compile_options (json_test PRIVATE /Yustdafx.h /Fpjson-tests-stdafx.pch)
30- endif ()
19+ configure_pch(json_test stdafx.h stdafx.cpp)
Original file line number Diff line number Diff line change @@ -6,15 +6,4 @@ set(SOURCES
66
77add_casablanca_test(pplx_test SOURCES )
88
9- if (MSVC )
10- get_target_property (_srcs pplx_test SOURCES )
11-
12- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
13- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /pplx-tests-stdafx.pch" )
14- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /pplx-tests-stdafx.pch" )
15- endif ()
16-
17- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fppplx-tests-stdafx.pch" )
18- target_sources (pplx_test PRIVATE stdafx.cpp)
19- target_compile_options (pplx_test PRIVATE /Yustdafx.h /Fppplx-tests-stdafx.pch)
20- endif ()
9+ configure_pch(pplx_test stdafx.h stdafx.cpp)
Original file line number Diff line number Diff line change @@ -24,15 +24,4 @@ if(NOT WIN32 OR CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp")
2424 endif ()
2525endif ()
2626
27- if (MSVC )
28- get_target_property (_srcs streams_test SOURCES )
29-
30- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
31- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /streams-tests-stdafx.pch" )
32- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /streams-tests-stdafx.pch" )
33- endif ()
34-
35- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpstreams-tests-stdafx.pch" )
36- target_sources (streams_test PRIVATE stdafx.cpp)
37- target_compile_options (streams_test PRIVATE /Yustdafx.h /Fpstreams-tests-stdafx.pch)
38- endif ()
27+ configure_pch(streams_test stdafx.h stdafx.cpp)
Original file line number Diff line number Diff line change @@ -13,15 +13,4 @@ set(SOURCES
1313
1414add_casablanca_test(uri_test SOURCES )
1515
16- if (MSVC )
17- get_target_property (_srcs uri_test SOURCES )
18-
19- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
20- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /uri-tests-stdafx.pch" )
21- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /uri-tests-stdafx.pch" )
22- endif ()
23-
24- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fpuri-tests-stdafx.pch" )
25- target_sources (uri_test PRIVATE stdafx.cpp)
26- target_compile_options (uri_test PRIVATE /Yustdafx.h /Fpuri-tests-stdafx.pch)
27- endif ()
16+ configure_pch(uri_test stdafx.h stdafx.cpp)
Original file line number Diff line number Diff line change @@ -13,15 +13,4 @@ if(CMAKE_COMPILER_IS_GNUCXX)
1313 target_compile_options (utils_test PRIVATE "-Wno-deprecated-declarations" )
1414endif ()
1515
16- if (MSVC )
17- get_target_property (_srcs utils_test SOURCES )
18-
19- if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .*" )
20- set_property (SOURCE stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR} /utils-tests-stdafx.pch" )
21- set_property (SOURCE ${_srcs} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /utils-tests-stdafx.pch" )
22- endif ()
23-
24- set_source_files_properties (stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h /Fputils-tests-stdafx.pch" )
25- target_sources (utils_test PRIVATE stdafx.cpp)
26- target_compile_options (utils_test PRIVATE /Yustdafx.h /Fputils-tests-stdafx.pch)
27- endif ()
16+ configure_pch(utils_test stdafx.h stdafx.cpp)
You can’t perform that action at this time.
0 commit comments