Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cad3f29
Move DacTableGen out of the CMake build and into tools-local.
jkoritzinsky Jan 9, 2020
e921ecc
Merge branch 'master' of https://github.com/dotnet/runtime into dacta…
jkoritzinsky Mar 12, 2020
a69c346
Attempt: usenmakefiles means ninja.
jkoritzinsky Mar 17, 2020
d1b12b5
Make changes to Windows build to support non-VS generators like ninja.
jkoritzinsky Mar 18, 2020
df589ef
Use CMake 3.16 PCHs.
jkoritzinsky Mar 18, 2020
0524739
Remove explicit process count.
jkoritzinsky Mar 18, 2020
e99246f
Build and run DacTableGen via the .NET CLI we pull down for the build…
jkoritzinsky Aug 24, 2020
03140d8
Update configurecompiler.cmake to specify language (needed for Ninja).
jkoritzinsky Aug 24, 2020
9bdf0f1
Merge branch 'ninja-windows' of github.com:jkoritzinsky/runtime into …
jkoritzinsky Aug 24, 2020
417b07a
Get Ninja build working again.
jkoritzinsky Aug 24, 2020
db7454a
Merge branch 'master' of https://github.com/dotnet/runtime into ninja…
jkoritzinsky Aug 24, 2020
b70eeca
Pass configuration to cmake configure step for Ninja build.
jkoritzinsky Aug 31, 2020
36cc91e
Rename flag
jkoritzinsky Aug 31, 2020
fe484c9
Fix configure step for cross-arch native build
jkoritzinsky Aug 31, 2020
cba81df
Support building via Ninja for coreclr via an MSBuild property
jkoritzinsky Aug 31, 2020
c20b356
Implement support for opening the CoreCLR solution in VS via the -vs …
jkoritzinsky Sep 1, 2020
86f5f90
Fix setting generator to Ninja.
jkoritzinsky Sep 1, 2020
a2478cc
Merge libraries gen-buildsys-win.bat with runtime gen-buildsys.cmd to…
jkoritzinsky Sep 3, 2020
ca84dd2
Enable building libraries native build with ninja.
jkoritzinsky Sep 3, 2020
3b17211
Centralize setting CMAKE_SYSTEM_VERSION for windows builds.
jkoritzinsky Sep 3, 2020
8422b09
Update host build to use shared gen-buildsys.cmd
jkoritzinsky Sep 3, 2020
885974e
Fix multi-config generator detection.
jkoritzinsky Sep 4, 2020
a8feb74
Exit with success when we build successfully.
jkoritzinsky Sep 4, 2020
e7b9280
Enable and fix up Ninja build for hosts.
jkoritzinsky Sep 4, 2020
6bcaec4
Only link delayimp.lib on Windows
jkoritzinsky Sep 4, 2020
cb1f6a1
Remove "overriding /W3 with /W1" warning in Ninja build of hosts by t…
jkoritzinsky Sep 4, 2020
03c4cc9
Reduce command line override warnings by adopting the MSVC_RUNTIME_LI…
jkoritzinsky Sep 4, 2020
0378122
Use the delayed expansion syntax to correctly pass in the config to c…
jkoritzinsky Sep 8, 2020
195fa3e
Move all usages of MSVC runtime library selection to the CMake abstra…
jkoritzinsky Sep 8, 2020
7c7c168
Condition the rest of the compiler options correctly so they don't sh…
jkoritzinsky Sep 8, 2020
5dc02c0
Correctly build DIALib and DacTableGen as AnyCPU
jkoritzinsky Sep 9, 2020
86019b9
Fix WRITE_BARRIER_CHECK define
jkoritzinsky Sep 9, 2020
823cef9
Fix passing arch for MSBuild build.
jkoritzinsky Sep 9, 2020
3e60c98
Configure ASM compiler command line format in configurecompiler.cmake…
jkoritzinsky Sep 9, 2020
4d81fe8
Cleanup after fixing ARM/ARM64 support.
jkoritzinsky Sep 9, 2020
8286fba
Rename variable
jkoritzinsky Sep 9, 2020
0d9205a
Merge branch 'master' into ninja-windows
jkoritzinsky Sep 9, 2020
82f0491
Condition PCH's for C++-only as needed to fix using them on non-Windo…
jkoritzinsky Sep 10, 2020
6541aeb
Fix CoreCLR native test build on windows to point to new gen-buildsys…
jkoritzinsky Sep 10, 2020
ca101e9
Add missing compilation options in Ninja build that are implicitly de…
jkoritzinsky Sep 14, 2020
78fd252
Merge branch 'master' into ninja-windows
jkoritzinsky Sep 29, 2020
18acb6f
Disable analyzers for DacTableGen. Remove /MAP linker flag (that's fo…
jkoritzinsky Sep 30, 2020
d38ae03
Upgrade to CMake 3.16.4
jkoritzinsky Oct 7, 2020
5051f71
Merge branch 'master' of github.com:dotnet/runtime into ninja-windows
jkoritzinsky Oct 19, 2020
43e8a7b
Don't warn on unused variables in CMake (these usually vary on platfo…
jkoritzinsky Oct 19, 2020
a34284e
Manually compile ARM and ARM64 asm files when using the VS generator …
jkoritzinsky Oct 20, 2020
ccd66f5
Merge branch 'master' of github.com:dotnet/runtime into ninja-windows
jkoritzinsky Oct 20, 2020
992817d
Enable CMake policy in test build to use CMAKE_MSVC_RUNTIME_LIBRARY v…
jkoritzinsky Oct 20, 2020
7db1ecb
Merge branch 'ninja-windows' of github.com:jkoritzinsky/runtime; bran…
jkoritzinsky Oct 20, 2020
aa79e4f
Update initially disabled warnings in host.
jkoritzinsky Oct 21, 2020
327b002
Add -ninja arg to root scripts to enable using Ninja.
jkoritzinsky Oct 21, 2020
bc701d1
Enable using Ninja in CoreCLR CI.
jkoritzinsky Oct 21, 2020
d95091e
Merge branch 'master' of github.com:dotnet/runtime into ninja-windows
jkoritzinsky Oct 21, 2020
334293c
Try to fix passing the -ninja arg in yaml.
jkoritzinsky Oct 21, 2020
c1b3676
Add ninja to the Windows invocation
jkoritzinsky Oct 21, 2020
2945f4d
Merge branch 'master' of github.com:dotnet/runtime into ninja-windows
jkoritzinsky Oct 21, 2020
cfc26f5
Fix 2-phase cross targeting to do one phase at a time and initialize …
jkoritzinsky Oct 21, 2020
343690e
Restore old /Ox optimization setting for Release.
jkoritzinsky Oct 22, 2020
9af32b3
Fix typos, don't pass exception flags to C files.
jkoritzinsky Oct 22, 2020
61e4c81
Remove unneeded pragma.
jkoritzinsky Oct 22, 2020
a437115
Merge branch 'master' of github.com:dotnet/runtime into ninja-windows
jkoritzinsky Oct 27, 2020
83939c6
Fix .pgd file installation.
jkoritzinsky Oct 27, 2020
f95c8f6
Add mention of the `-ninja` flag in the Building CoreCLR documentation.
jkoritzinsky Oct 27, 2020
ff80bab
Mention installation locations for Ninja and warn while building if C…
jkoritzinsky Oct 28, 2020
4db3105
Update docs/workflow/requirements/windows-requirements.md
jkoritzinsky Oct 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<ItemGroup>
<!-- CoreClr -->
<SubsetName Include="Clr" Description="The CoreCLR runtime, LinuxDac, CoreLib (+ native), tools and packages." />
<SubsetName Include="Clr.DacTools" Description="Managed tools that support building a runtime that supports debugging (such as DacTableGen)." />
<SubsetName Include="Clr.Runtime" Description="The CoreCLR .NET runtime." />
<SubsetName Include="Clr.CoreLib" Description="The managed System.Private.CoreLib library for CoreCLR." />
<SubsetName Include="Clr.NativeCoreLib" Description="Run crossgen on System.Private.CoreLib library for CoreCLR." />
Expand Down Expand Up @@ -132,6 +133,12 @@
<ProjectToBuild Include="$(CoreClrProjectRoot)src\System.Private.CoreLib\System.Private.CoreLib.csproj" Category="clr" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Windows_NT' and ($(_subset.Contains('+clr.dactools+')) or $(_subset.Contains('+clr.runtime+')))">
<ProjectToBuild Include="$(CoreClrProjectRoot)src\ToolBox\SOS\DacTableGen\DacTableGen.csproj;
$(CoreClrProjectRoot)src\ToolBox\SOS\DIALib\DIALib.ilproj"
Category="clr"/>
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+clr.runtime+'))">
<ProjectToBuild Include="$(CoreClrProjectRoot)runtime.proj" Category="clr" />
</ItemGroup>
Expand Down
27 changes: 24 additions & 3 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,28 @@ if ($subset -eq 'help') {
}

if ($vs) {
. $PSScriptRoot\common\tools.ps1

if (-Not (Test-Path $vs)) {
if ($vs -ieq "coreclr.sln") {
# If someone passes in coreclr.sln (case-insensitive),
# launch the generated CMake solution.
$archToOpen = $arch[0]
$configToOpen = $configuration[0]
if ($runtimeConfiguration) {
$configToOpen = $runtimeConfiguration
}
$vs = Split-Path $PSScriptRoot -Parent | Join-Path -ChildPath "artifacts\obj\coreclr" | Join-Path -ChildPath "Windows_NT.$archToOpen.$((Get-Culture).TextInfo.ToTitleCase($configToOpen))" | Join-Path -ChildPath "CoreCLR.sln"
if (-Not (Test-Path $vs)) {
$repoRoot = Split-Path $PSScriptRoot -Parent
Invoke-Expression "& `"$repoRoot/src/coreclr/build-runtime.cmd`" -configureonly -$archToOpen -$configToOpen"
if ($lastExitCode -ne 0) {
Write-Error "Failed to generate the CoreCLR solution file."
exit 1
}
if (-Not (Test-Path $vs)) {
Write-Error "Unable to find the CoreCLR solution file at $vs."
}
}
}
elseif (-Not (Test-Path $vs)) {
$solution = $vs
# Search for the solution in libraries
$vs = Split-Path $PSScriptRoot -Parent | Join-Path -ChildPath "src\libraries" | Join-Path -ChildPath $vs | Join-Path -ChildPath "$vs.sln"
Expand All @@ -133,6 +152,8 @@ if ($vs) {
}
}
}

. $PSScriptRoot\common\tools.ps1

# This tells .NET Core to use the bootstrapped runtime
$env:DOTNET_ROOT=InitializeDotNetCli -install:$true -createSdkLocationFile:$true
Expand Down
86 changes: 56 additions & 30 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -425,26 +425,41 @@ endif(CLR_CMAKE_HOST_UNIX)
if (MSVC)
# Compile options for targeting windows

add_compile_options(/TP) # compile all files as C++
add_compile_options(/nologo) # Suppress Startup Banner
add_compile_options(/W3) # set warning level to 3
add_compile_options(/WX) # treat warnings as errors
add_compile_options(/Oi) # enable intrinsics
add_compile_options(/Oy-) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls
add_compile_options(/Gm-) # disable minimal rebuild
add_compile_options(/Zp8) # pack structs on 8-byte boundary
add_compile_options(/Gy) # separate functions for linker
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") # disable C++ RTTI
add_compile_options(/FC) # use full pathnames in diagnostics
add_compile_options(/MP) # Build with Multiple Processes (number of processes equal to the number of processors)
add_compile_options(/Zm200) # Specify Precompiled Header Memory Allocation Limit of 150MB
add_compile_options(/Zc:strictStrings) # Disable string-literal to char* or wchar_t* conversion

add_compile_options(/wd4960 /wd4961 /wd4603 /wd4627 /wd4838 /wd4456 /wd4457 /wd4458 /wd4459 /wd4091 /we4640)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/TP>) # compile all files as C++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder - why was this change in specifying options needed for enabling Ninja?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were needed because both MASM and RC are CMake langauges, so add_compile_options was adding all of these flags to files of those languages as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, multiple languages in the COMPILE_LANGUAGE are not supported until CMake 3.15, according to cmake doc. Some of the test legs in this CI are failing due to that. Also, the doc discourages using this generator expression:

This generator expression has limited use because it is not possible to use it with the Visual Studio generators. Portable buildsystems would not use this expression, and would create separate libraries for each source file language instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point me to where that doc is from? I haven’t seen that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the COMPILE_LANGUAGE doc: https://cmake.org/cmake/help/v3.6/manual/cmake-generator-expressions.7.html?highlight=compile_language. The doc for 3.15+ use a little different wording, but it is there as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for 3.15+ describe the behavior I expect, with the VS generator treating everything as C++. Since all cases we use this generator expressions here we apply to both C and C++, we’re in the supported zone.

Re outdated CMake on the CI machines: I’m working on getting 3.16 installed on CI along with Ninja so the new precompiled header functionality works on CI machines.

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/nologo>) # Suppress Startup Banner
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W3>) # set warning level to 3
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Oi>) # enable intrinsics
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Oy->) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gm->) # disable minimal rebuild
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zp8>) # pack structs on 8-byte boundary
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gy>) # separate functions for linker

# disable C++ RTTI
# /GR is added by default by CMake, so remove it manually.
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we can use add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/GR>) instead.
Also, we don't need to remove the /GR from the flags. The Visual C++ doc says that if CL encounters conflicting options, it uses the rightmost one. I think that the ones that cmake defines as default could be viewed as overridable defaults.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CL does use the rightmost option, but it emits an unsuppressable warning when doing so.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/FC>) # use full pathnames in diagnostics
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/MP>) # Build with Multiple Processes (number of processes equal to the number of processors)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zm200>) # Specify Precompiled Header Memory Allocation Limit of 150MB
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zc:strictStrings>) # Disable string-literal to char* or wchar_t* conversion

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4960>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4961>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4603>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4627>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4838>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4456>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4457>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4458>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4459>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4091>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4640>)

# Disable Warnings:
# 4291: Delete not defined for new, c++ exception may cause leak.
add_compile_options(/wd4291)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4291>)

# Treat Warnings as Errors:
# 4007: 'main' : must be __cdecl.
Expand All @@ -453,7 +468,12 @@ if (MSVC)
# 4551: Function call missing argument list.
# 4700: Local used w/o being initialized.
# 4806: Unsafe operation involving type 'bool'.
add_compile_options(/we4007 /we4013 /we4102 /we4551 /we4700 /we4806)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4007>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4013>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4102>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4551>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4700>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4806>)

# Set Warning Level 3:
# 4092: Sizeof returns 'unsigned long'.
Expand All @@ -464,22 +484,30 @@ if (MSVC)
# 4212: Function declaration used ellipsis.
# 4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX.
# 35038: data member 'member1' will be initialized after data member 'member2'.
add_compile_options(/w34092 /w34121 /w34125 /w34130 /w34132 /w34212 /w34530 /w35038)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34092>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34121>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34125>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34130>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34132>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34212>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34530>)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w35038>)

# Set Warning Level 4:
# 4177: Pragma data_seg s/b at global scope.
add_compile_options(/w44177)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w44177>)

add_compile_options(/Zi) # enable debugging information
add_compile_options(/ZH:SHA_256) # use SHA256 for generating hashes of compiler processed source files.
add_compile_options(/source-charset:utf-8) # Force MSVC to compile source as UTF-8.
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zi>) # enable debugging information
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/ZH:SHA_256>) # use SHA256 for generating hashes of compiler processed source files.
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/source-charset:utf-8>) # Force MSVC to compile source as UTF-8.

if (CLR_CMAKE_HOST_ARCH_I386)
add_compile_options(/Gz)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gz>)
endif (CLR_CMAKE_HOST_ARCH_I386)

add_compile_options($<$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>:/GL>)
add_compile_options($<$<OR:$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>,$<CONFIG:Checked>>:/O1>)
add_compile_options($<$<CONFIG:Checked>:/O1>)
add_compile_options($<$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>:/Ob2iy->)

if (CLR_CMAKE_HOST_ARCH_AMD64)
# The generator expression in the following command means that the /homeparams option is added only for debug builds
Expand All @@ -497,9 +525,7 @@ if (MSVC)
# For Release builds, we shall dynamically link into uCRT [ucrtbase.dll] (which is pushed down as a Windows Update on downlevel OS) but
# wont do the same for debug/checked builds since ucrtbased.dll is not redistributable and Debug/Checked builds are not
# production-time scenarios.

add_compile_options($<$<OR:$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>,$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>:/MT>)
add_compile_options($<$<AND:$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>,$<NOT:$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>>:/MTd>)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<AND:$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>,$<NOT:$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>>:Debug>)

add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/ZH:SHA_256>)

Expand Down Expand Up @@ -527,9 +553,9 @@ if(CLR_CMAKE_ENABLE_CODE_COVERAGE)

endif(CLR_CMAKE_ENABLE_CODE_COVERAGE)

if (CMAKE_BUILD_TOOL STREQUAL nmake)
if (CMAKE_GENERATOR MATCHES "(Makefile|Ninja)")
set(CMAKE_RC_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
endif(CMAKE_BUILD_TOOL STREQUAL nmake)
endif()

# Ensure other tools are present
if (CLR_CMAKE_HOST_WIN32)
Expand Down
70 changes: 21 additions & 49 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -236,52 +236,6 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix)
PROPERTIES GENERATED TRUE)
endfunction()

# target_precompile_header(TARGET targetName HEADER headerName [ADDITIONAL_INCLUDE_DIRECTORIES includeDirs])
function(target_precompile_header)
set(options "")
set(oneValueArgs TARGET HEADER)
set(multiValueArgs ADDITIONAL_INCLUDE_DIRECTORIES)
cmake_parse_arguments(PRECOMPILE_HEADERS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGV})

if ("${PRECOMPILE_HEADERS_TARGET}" STREQUAL "")
message(SEND_ERROR "No target supplied to target_precompile_header.")
endif()
if ("${PRECOMPILE_HEADERS_HEADER}" STREQUAL "")
message(SEND_ERROR "No header supplied to target_precompile_header.")
endif()

if(MSVC)
get_filename_component(PCH_NAME ${PRECOMPILE_HEADERS_HEADER} NAME_WE)
# We need to use the $<TARGET_PROPERTY:NAME> generator here instead of the ${targetName} variable since
# CMake evaluates source file properties once per directory. If we just use ${targetName}, we end up sharing
# the same PCH between targets, which doesn't work.
set(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${PCH_NAME}.$<TARGET_PROPERTY:NAME>.pch")
set(pchSourceFile "${CMAKE_CURRENT_BINARY_DIR}/${PCH_NAME}.${PRECOMPILE_HEADERS_TARGET}.cpp")

file(GENERATE OUTPUT ${pchSourceFile} CONTENT "#include \"${PRECOMPILE_HEADERS_HEADER}\"")

set(PCH_SOURCE_FILE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${PRECOMPILE_HEADERS_ADDITIONAL_INCLUDE_DIRECTORIES})

set_source_files_properties(${pchSourceFile}
PROPERTIES COMPILE_FLAGS "/Yc\"${PRECOMPILE_HEADERS_HEADER}\" /Fp\"${precompiledBinary}\""
OBJECT_OUTPUTS "${precompiledBinary}"
INCLUDE_DIRECTORIES "${PCH_SOURCE_FILE_INCLUDE_DIRECTORIES}")
get_target_property(TARGET_SOURCES ${PRECOMPILE_HEADERS_TARGET} SOURCES)

foreach (SOURCE ${TARGET_SOURCES})
get_source_file_property(SOURCE_LANG ${SOURCE} LANGUAGE)
if (("${SOURCE_LANG}" STREQUAL "C") OR ("${SOURCE_LANG}" STREQUAL "CXX"))
set_source_files_properties(${SOURCE}
PROPERTIES COMPILE_FLAGS "/Yu\"${PRECOMPILE_HEADERS_HEADER}\" /Fp\"${precompiledBinary}\""
OBJECT_DEPENDS "${precompiledBinary}")
endif()
endforeach()

# Add pchSourceFile to PRECOMPILE_HEADERS_TARGET target
target_sources(${PRECOMPILE_HEADERS_TARGET} PRIVATE ${pchSourceFile})
endif(MSVC)
endfunction()

function(strip_symbols targetName outputFilename)
if (CLR_CMAKE_HOST_UNIX)
set(strip_source_file $<TARGET_FILE:${targetName}>)
Expand Down Expand Up @@ -331,7 +285,16 @@ function(strip_symbols targetName outputFilename)

set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
else(CLR_CMAKE_HOST_UNIX)
set(${outputFilename} ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb PARENT_SCOPE)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
# We can't use the $<TARGET_PDB_FILE> generator expression here since
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand how this comment relates to files being stripped. Do we ever call stripping for resource DLLs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when I first wrote this, we end up coming down this path for the resource dlls. It's possible with the numerous refactorings since then that this has changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep we still call strip_symbols for resource dlls.

# the generator expression isn't supported on resource DLLs.
set(${outputFilename} ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb PARENT_SCOPE)
else()
# We can't use the $<TARGET_PDB_FILE> generator expression here since
# the generator expression isn't supported on resource DLLs.
set(${outputFilename} ${CMAKE_CURRENT_BINARY_DIR}/${targetName}.pdb PARENT_SCOPE)
endif()
endif(CLR_CMAKE_HOST_UNIX)
endfunction()

Expand Down Expand Up @@ -384,8 +347,11 @@ function(install_clr)
install_symbols(${symbol_file} ${destination})

if(CLR_CMAKE_PGO_INSTRUMENT)
if(WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig AND WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${targetName}.pgd DESTINATION ${destination}/PGD OPTIONAL)
endif()
endif()
endforeach()
Expand Down Expand Up @@ -425,6 +391,12 @@ if (CMAKE_VERSION VERSION_LESS "3.12")
endfunction()
endif()

if (CMAKE_VERSION VERSION_LESS "3.16")
# Provide a no-op polyfill for precompiled headers on old CMake versions
function(target_precompile_headers)
endfunction()
endif()

function(_add_executable)
if(NOT WIN32)
add_executable(${ARGV} ${VERSION_FILE_PATH})
Expand Down
78 changes: 78 additions & 0 deletions eng/native/gen-buildsys.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@if not defined _echo @echo off
rem
rem This file invokes cmake and generates the build system for windows.

set argC=0
for %%x in (%*) do Set /A argC+=1

if %argC% lss 4 GOTO :USAGE
if %1=="/?" GOTO :USAGE

setlocal
set basePath=%~dp0
:: remove quotes
set "basePath=%basePath:"=%"
:: remove trailing slash
if %basePath:~-1%==\ set "basePath=%basePath:~0,-1%"

set __SourceDir=%1
set __IntermediatesDir=%2
set __VSVersion=%3
set __Arch=%4
set __CmakeGenerator=Visual Studio
set __UseEmcmake=0

if /i "%__Ninja%" == "1" (
set __CmakeGenerator=Ninja
) else (
if /i NOT "%__Arch%" == "wasm" (
if /i "%__VSVersion%" == "vs2019" (set __CmakeGenerator=%__CmakeGenerator% 16 2019)
if /i "%__VSVersion%" == "vs2017" (set __CmakeGenerator=%__CmakeGenerator% 15 2017)

if /i "%__Arch%" == "x64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64)
if /i "%__Arch%" == "arm" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM)
if /i "%__Arch%" == "arm64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM64)
if /i "%__Arch%" == "x86" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A Win32)
) else (
set __CmakeGenerator=NMake Makefiles
)
)

if /i "%__Arch%" == "wasm" (
if "%EMSDK_PATH%" == "" (
echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root.
exit /B 1
)

if "%EMSCRIPTEN_ROOT%" == "" (
set EMSCRIPTEN_ROOT="%EMSDK_PATH/upstream/emscripten%"
)
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1" "-DCMAKE_TOOLCHAIN_FILE=%EMSCRIPTEN%/cmake/Modules/Platform/Emscripten.cmake"
set __UseEmcmake=1
) else (
set __ExtraCmakeParams="-DCMAKE_SYSTEM_VERSION=10.0"
)

:loop
if [%5] == [] goto end_loop
set __ExtraCmakeParams=%__ExtraCmakeParams% %5
shift
goto loop
:end_loop

set __ExtraCmakeParams="-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams%

if /i "%__UseEmcmake%" == "1" (
emcmake "%CMakePath%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir%
) else (
"%CMakePath%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir%
)
endlocal
exit /B %errorlevel%

:USAGE
echo "Usage..."
echo "gen-buildsys.cmd <path to top level CMakeLists.txt> <path to location for intermediate files> <VSVersion> <arch>"
echo "Specify the path to the top level CMake file - <ProjectK>/src/NDP"
echo "Specify the VSVersion to be used - VS2017 or VS2019"
EXIT /B 1
5 changes: 5 additions & 0 deletions eng/pipelines/coreclr/templates/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ jobs:
df -h
displayName: Disk Usage before Build

# Build DacTableGen (Windows-only)
- ${{ if eq(parameters.osGroup, 'Windows_NT') }}:
- script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset clr.dactools $(crossArg) -arch $(archType) $(osArg) -c $(buildConfig) $(officialBuildIdArg) -ci /bl:$(Build.SourcesDirectory)artifacts/logs/$(buildConfig)/DacTools.binlog
displayName: Build managed product components and packages

# Build CoreCLR Runtime
- ${{ if ne(parameters.osGroup, 'Windows_NT') }}:
- script: $(Build.SourcesDirectory)/src/coreclr/build-runtime$(scriptExt) $(buildConfig) $(archType) $(crossArg) $(osArg) -ci $(compilerArg) $(officialBuildIdArg) $(clrInterpreterBuildArg)
Expand Down
Loading