Cleanup native build (dotnet/core-setup#5228)
authorVitek Karas <vitek.karas@microsoft.com>
Thu, 21 Feb 2019 21:29:34 +0000 (13:29 -0800)
committerGitHub <noreply@github.com>
Thu, 21 Feb 2019 21:29:34 +0000 (13:29 -0800)
Refactor cmake files to avoid code duplication.
Fix comhost to have native resources on Windows - that is version and other properties.
Turn on parallel build on Windows - on my machine the native build took 125 second before and 40 after this change.

Commit migrated from https://github.com/dotnet/core-setup/commit/758461c8933699dca0cb5f8e4fa712ab35d1d277

src/installer/corehost/build.cmd
src/installer/corehost/build.proj
src/installer/corehost/cli/apphost/CMakeLists.txt
src/installer/corehost/cli/comhost/CMakeLists.txt
src/installer/corehost/cli/common.cmake [new file with mode: 0644]
src/installer/corehost/cli/dotnet/CMakeLists.txt
src/installer/corehost/cli/exe.cmake
src/installer/corehost/cli/fxr/CMakeLists.txt
src/installer/corehost/cli/hostpolicy/CMakeLists.txt
src/installer/corehost/cli/lib.cmake [new file with mode: 0644]

index 5f102b9..ee992a0 100644 (file)
@@ -141,8 +141,8 @@ cd %__rootDir%
 SET __NativeBuildArgs=/t:rebuild
 if /i "%__IncrementalNativeBuild%" == "1" SET __NativeBuildArgs=
 
-echo msbuild "%__IntermediatesDir%\ALL_BUILD.vcxproj" %__NativeBuildArgs% /p:Configuration=%CMAKE_BUILD_TYPE% %__msbuildArgs%
-call msbuild "%__IntermediatesDir%\ALL_BUILD.vcxproj" %__NativeBuildArgs% /p:Configuration=%CMAKE_BUILD_TYPE% %__msbuildArgs%
+echo msbuild "%__IntermediatesDir%\ALL_BUILD.vcxproj" %__NativeBuildArgs% /m /p:Configuration=%CMAKE_BUILD_TYPE% %__msbuildArgs%
+call msbuild "%__IntermediatesDir%\ALL_BUILD.vcxproj" %__NativeBuildArgs% /m /p:Configuration=%CMAKE_BUILD_TYPE% %__msbuildArgs%
 IF ERRORLEVEL 1 (
     goto :Failure
 )
index 72bf02e..51c297b 100644 (file)
@@ -62,6 +62,9 @@
       <HostFiles Include="hostpolicy">
         <FileDescription>.NET Core Host Policy - $(HostPolicyVersion)</FileDescription>
       </HostFiles>
+      <HostFiles Include="comhost">
+        <FileDescription>.NET Core COM Host</FileDescription>
+      </HostFiles>
     </ItemGroup>
     
     <MSBuild Projects="$(MSBuildProjectFullPath)"
index 4dac1f3..1db4cc3 100644 (file)
@@ -3,7 +3,7 @@
 
 cmake_minimum_required (VERSION 2.6)
 project(apphost)
-set(DOTNET_HOST_EXE_NAME "apphost")
+set(DOTNET_PROJECT_NAME "apphost")
 
 # Add RPATH to the apphost binary that allows using local copies of shared libraries
 # dotnet core depends on for special scenarios when system wide installation of such 
index 2d3ae3b..407ee27 100644 (file)
@@ -4,16 +4,13 @@
 cmake_minimum_required (VERSION 2.6)
 project(comhost)
 
-include(../setup.cmake)
+set(DOTNET_PROJECT_NAME "comhost")
 
 # Include directories
-include_directories(./)
-include_directories(../)
 include_directories(../fxr)
-include_directories(../../)
-include_directories(../../common)
 include_directories(../json/casablanca/include)
 
+# CMake does not recommend using globbing since it messes with the freshness checks
 set(SOURCES
     ../../corehost.cpp
     exports.cpp
@@ -27,16 +24,7 @@ set(SOURCES
     ../json/casablanca/src/utilities/asyncrt_utils.cpp
 )
 
-if(WIN32)
-    list(APPEND SOURCES
-        ../../common/pal.windows.cpp
-        ../../common/longfile.windows.cpp
-        Exports.def)
-else()
-    list(APPEND SOURCES
-        ../../common/pal.unix.cpp
-        ${VERSION_FILE_PATH})
-endif()
+include(../lib.cmake)
 
 # Move to setup.cmake if COMHOST is ever built on non-Windows
 if("${CLI_CMAKE_COMHOST_VER}" STREQUAL "")
@@ -45,11 +33,8 @@ else()
     add_definitions(-DLIBHOST_PKG_VER="${CLI_CMAKE_COMHOST_VER}")
 endif()
 
-add_definitions(-DEXPORT_SHARED_API=1)
 add_definitions(-DFEATURE_LIBHOST=1)
 
-add_library(comhost SHARED ${SOURCES})
-
 # Specify non-default Windows libs to be used for Arm/Arm64 builds
 if (WIN32 AND (CLI_CMAKE_PLATFORM_ARCH_ARM OR CLI_CMAKE_PLATFORM_ARCH_ARM64))
     target_link_libraries(comhost Advapi32.lib Ole32.lib OleAut32.lib)
diff --git a/src/installer/corehost/cli/common.cmake b/src/installer/corehost/cli/common.cmake
new file mode 100644 (file)
index 0000000..b0fd5e0
--- /dev/null
@@ -0,0 +1,40 @@
+# Copyright (c) .NET Foundation and contributors. All rights reserved.
+# Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+project(${DOTNET_PROJECT_NAME})
+
+if(WIN32)
+    add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
+    add_compile_options($<$<CONFIG:Release>:/MT>)
+    add_compile_options($<$<CONFIG:Debug>:/MTd>)
+else()
+    add_compile_options(-fPIC)
+    add_compile_options(-fvisibility=hidden)
+endif()
+
+include(${CMAKE_CURRENT_LIST_DIR}/setup.cmake)
+
+# Include directories
+if(WIN32)
+    include_directories("${CLI_CMAKE_RESOURCE_DIR}/${DOTNET_PROJECT_NAME}")
+endif()
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
+include_directories(${CMAKE_CURRENT_LIST_DIR}/)
+include_directories(${CMAKE_CURRENT_LIST_DIR}/../)
+include_directories(${CMAKE_CURRENT_LIST_DIR}/../common)
+
+if(WIN32)
+    list(APPEND SOURCES 
+        ${CMAKE_CURRENT_LIST_DIR}/../common/pal.windows.cpp
+        ${CMAKE_CURRENT_LIST_DIR}/../common/longfile.windows.cpp)
+else()
+    list(APPEND SOURCES
+        ${CMAKE_CURRENT_LIST_DIR}/../common/pal.unix.cpp
+        ${VERSION_FILE_PATH})
+endif()
+
+set(RESOURCES)
+if(WIN32 AND NOT SKIP_VERSIONING)
+    list(APPEND RESOURCES ${CMAKE_CURRENT_LIST_DIR}/native.rc)
+endif()
+
index fa666cf..aec6149 100644 (file)
@@ -3,7 +3,7 @@
 
 cmake_minimum_required (VERSION 2.6)
 project(dotnet)
-set(DOTNET_HOST_EXE_NAME "dotnet")
+set(DOTNET_PROJECT_NAME "dotnet")
 set(SOURCES 
     ../fxr/fx_ver.cpp)
 
index 93e4863..3869ae8 100644 (file)
@@ -1,68 +1,36 @@
 # Copyright (c) .NET Foundation and contributors. All rights reserved.
 # Licensed under the MIT license. See LICENSE file in the project root for full license information.
-project (${DOTNET_HOST_EXE_NAME})
 
-if(WIN32)
-    add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
-    add_compile_options($<$<CONFIG:Release>:/MT>)
-    add_compile_options($<$<CONFIG:Debug>:/MTd>)
-else()
-    add_compile_options(-fPIE)
-    add_compile_options(-fvisibility=hidden)
-endif()
+project (${DOTNET_PROJECT_NAME})
 
-include(../setup.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)
 
 # Include directories
-if(WIN32)
-    include_directories("${CLI_CMAKE_RESOURCE_DIR}/${DOTNET_HOST_EXE_NAME}")
-endif()
-include_directories(../../)
-include_directories(../../common)
-include_directories(../)
-include_directories(../fxr)
+include_directories(${CMAKE_CURRENT_LIST_DIR}/fxr)
 
 # CMake does not recommend using globbing since it messes with the freshness checks
 list(APPEND SOURCES
-    ../../corehost.cpp
-    ../../common/trace.cpp
-    ../../common/utils.cpp)
-
-if(WIN32)
-    list(APPEND SOURCES
-        ../../common/pal.windows.cpp
-        ../../common/longfile.windows.cpp)
-else()
-    list(APPEND SOURCES
-        ../../common/pal.unix.cpp
-        ${VERSION_FILE_PATH})
-endif()
+    ${CMAKE_CURRENT_LIST_DIR}/../corehost.cpp
+    ${CMAKE_CURRENT_LIST_DIR}/../common/trace.cpp
+    ${CMAKE_CURRENT_LIST_DIR}/../common/utils.cpp)
 
-set(RESOURCES)
-if(WIN32 AND NOT SKIP_VERSIONING)
-    list(APPEND RESOURCES ../native.rc)
-endif()
-
-add_executable(${DOTNET_HOST_EXE_NAME} ${SOURCES} ${RESOURCES})
+add_executable(${DOTNET_PROJECT_NAME} ${SOURCES} ${RESOURCES})
 
 if(NOT WIN32)
-    disable_pax_mprotect(${DOTNET_HOST_EXE_NAME})
+    disable_pax_mprotect(${DOTNET_PROJECT_NAME})
 endif()
 
-install(TARGETS ${DOTNET_HOST_EXE_NAME} DESTINATION bin)
-
-# Specify the import library to link against for Arm32 build since the default set is minimal
-if (WIN32 AND CLI_CMAKE_PLATFORM_ARCH_ARM)
-    target_link_libraries(${DOTNET_HOST_EXE_NAME} shell32.lib)
-endif()
+install(TARGETS ${DOTNET_PROJECT_NAME} DESTINATION bin)
 
 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD")
-    target_link_libraries (${DOTNET_HOST_EXE_NAME} "pthread")
+    target_link_libraries (${DOTNET_PROJECT_NAME} "pthread")
 endif()
 
 if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
-    target_link_libraries (${DOTNET_HOST_EXE_NAME} "dl")
+    target_link_libraries (${DOTNET_PROJECT_NAME} "dl")
 endif()
 
-
-
+# Specify the import library to link against for Arm32 build since the default set is minimal
+if (WIN32 AND CLI_CMAKE_PLATFORM_ARCH_ARM)
+    target_link_libraries(${DOTNET_PROJECT_NAME} shell32.lib)
+endif()
index c7c33a5..4b45037 100644 (file)
@@ -4,25 +4,9 @@
 cmake_minimum_required (VERSION 2.6)
 project(hostfxr)
 
-if(WIN32)
-    add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
-    add_compile_options($<$<CONFIG:Release>:/MT>)
-    add_compile_options($<$<CONFIG:Debug>:/MTd>)
-else()
-    add_compile_options(-fPIC)
-    add_compile_options(-fvisibility=hidden)
-endif()
-
-include(../setup.cmake)
+set(DOTNET_PROJECT_NAME "hostfxr")
 
 # Include directories
-if(WIN32)
-    include_directories("${CLI_CMAKE_RESOURCE_DIR}/hostfxr")
-endif()
-include_directories(./)
-include_directories(../)
-include_directories(../../)
-include_directories(../../common)
 include_directories(../json/casablanca/include)
 
 # CMake does not recommend using globbing since it messes with the freshness checks
@@ -50,30 +34,6 @@ set(SOURCES
     ./sdk_resolver.cpp
 )
 
-if(WIN32)
-    list(APPEND SOURCES
-        ../../common/pal.windows.cpp
-        ../../common/longfile.windows.cpp)
-else()
-    list(APPEND SOURCES
-        ../../common/pal.unix.cpp
-        ${VERSION_FILE_PATH})
-endif()
-
-add_definitions(-D_NO_ASYNCRTIMP)
-add_definitions(-D_NO_PPLXIMP)
-add_definitions(-DEXPORT_SHARED_API=1)
-
-set(RESOURCES)
-if(WIN32)
-    list(APPEND RESOURCES ../native.rc)
-endif()
-add_library(hostfxr SHARED ${SOURCES} ${RESOURCES})
-set_target_properties(hostfxr PROPERTIES MACOSX_RPATH TRUE)
-
-# Specify the import library to link against for Arm32 build since the default set is minimal
-if (WIN32 AND CLI_CMAKE_PLATFORM_ARCH_ARM)
-    target_link_libraries(hostfxr shell32.lib)
-endif()
+include(../lib.cmake)
 
 install_library_and_symbols (hostfxr)
index a8fa341..203b652 100644 (file)
@@ -4,24 +4,9 @@
 cmake_minimum_required (VERSION 2.6)
 project(hostpolicy)
 
-if(WIN32)
-    add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
-    add_compile_options($<$<CONFIG:Release>:/MT>)
-    add_compile_options($<$<CONFIG:Debug>:/MTd>)
-else()
-    add_compile_options(-fPIC)
-    add_compile_options(-fvisibility=hidden)
-endif()
-
-include(../setup.cmake)
+set(DOTNET_PROJECT_NAME "hostpolicy")
 
 # Include directories
-if(WIN32)
-    include_directories("${CLI_CMAKE_RESOURCE_DIR}/hostpolicy")
-endif()
-include_directories(../)
-include_directories(../../)
-include_directories(../../common)
 include_directories(../fxr)
 include_directories(../json/casablanca/include)
 
@@ -49,31 +34,6 @@ set(SOURCES
     ../version.cpp
 )
 
-
-if(WIN32)
-    list(APPEND SOURCES 
-        ../../common/pal.windows.cpp
-        ../../common/longfile.windows.cpp)
-else()
-    list(APPEND SOURCES
-        ../../common/pal.unix.cpp
-        ${VERSION_FILE_PATH})
-endif()
-
-add_definitions(-D_NO_ASYNCRTIMP)
-add_definitions(-D_NO_PPLXIMP)
-add_definitions(-DEXPORT_SHARED_API=1)
-
-set(RESOURCES)
-if(WIN32)
-    list(APPEND RESOURCES ../native.rc)
-endif()
-add_library(hostpolicy SHARED ${SOURCES} ${RESOURCES})
-set_target_properties(hostpolicy PROPERTIES MACOSX_RPATH TRUE)
-
-# Specify the import library to link against for Arm32 build since the default set is minimal
-if (WIN32 AND CLI_CMAKE_PLATFORM_ARCH_ARM)
-    target_link_libraries(hostpolicy shell32.lib)
-endif()
+include(../lib.cmake)
 
 install_library_and_symbols (hostpolicy)
diff --git a/src/installer/corehost/cli/lib.cmake b/src/installer/corehost/cli/lib.cmake
new file mode 100644 (file)
index 0000000..4ba895e
--- /dev/null
@@ -0,0 +1,19 @@
+# Copyright (c) .NET Foundation and contributors. All rights reserved.
+# Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+project(${DOTNET_PROJECT_NAME})
+
+include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)
+
+add_definitions(-D_NO_ASYNCRTIMP)
+add_definitions(-D_NO_PPLXIMP)
+add_definitions(-DEXPORT_SHARED_API=1)
+
+add_library(${DOTNET_PROJECT_NAME} SHARED ${SOURCES} ${RESOURCES})
+
+set_target_properties(${DOTNET_PROJECT_NAME} PROPERTIES MACOSX_RPATH TRUE)
+
+# Specify the import library to link against for Arm32 build since the default set is minimal
+if (WIN32 AND CLI_CMAKE_PLATFORM_ARCH_ARM)
+    target_link_libraries(${DOTNET_PROJECT_NAME} shell32.lib)
+endif()
\ No newline at end of file