Skip to content

Commit 265d681

Browse files
jason-haBillyONeal
authored andcommitted
fix SxS debug-release builds with Visual Studio (microsoft#1220)
* On basic_string_view_support: fix SxS debug-release builds with Visual Studio place precompiled header implicitly in Debug/Release path with VS and explicitly in bin dir otherwise standardize pch setup across libraries with helper function * nudge pipeline to rerun
1 parent 44c4918 commit 265d681

File tree

10 files changed

+31
-104
lines changed

10 files changed

+31
-104
lines changed

Release/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,28 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
202202
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
203203
set(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
206228
set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
207229
set(Casablanca_LIBRARY cpprest)

Release/samples/BlackJack/BlackJack_Server/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,4 @@ add_executable(blackjackserver
1010

1111
target_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)

Release/src/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,7 @@ else()
174174
message(FATAL_ERROR "Invalid implementation")
175175
endif()
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

190179
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
191180
if(WERROR)

Release/tests/functional/http/client/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,7 @@ else()
3232
target_link_libraries(httpclient_test PRIVATE httptest_utilities)
3333
endif()
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

4837
if(NOT WIN32)
4938
cpprest_find_boost()

Release/tests/functional/http/listener/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff 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)
3526
endif()

Release/tests/functional/json/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,4 @@ if(UNIX AND NOT APPLE)
1616
target_link_libraries(json_test PRIVATE cpprestsdk_boost_internal)
1717
endif()
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)

Release/tests/functional/pplx/pplx_test/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,4 @@ set(SOURCES
66

77
add_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)

Release/tests/functional/streams/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,4 @@ if(NOT WIN32 OR CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp")
2424
endif()
2525
endif()
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)

Release/tests/functional/uri/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,4 @@ set(SOURCES
1313

1414
add_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)

Release/tests/functional/utils/CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,4 @@ if(CMAKE_COMPILER_IS_GNUCXX)
1313
target_compile_options(utils_test PRIVATE "-Wno-deprecated-declarations")
1414
endif()
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)

0 commit comments

Comments
 (0)