diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 924b661c8dfde5..24ab3c8cd96bb1 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -127,17 +127,13 @@ if (MSVC) add_linker_flag(/OPT:NOICF CHECKED) # Release build specific flags - add_linker_flag(/LTCG RELEASE) add_linker_flag(/OPT:REF RELEASE) add_linker_flag(/OPT:ICF RELEASE) add_linker_flag(/INCREMENTAL:NO RELEASE) - set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG") # ReleaseWithDebugInfo build specific flags - add_linker_flag(/LTCG RELWITHDEBINFO) add_linker_flag(/OPT:REF RELWITHDEBINFO) add_linker_flag(/OPT:ICF RELWITHDEBINFO) - set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") elseif (CLR_CMAKE_HOST_UNIX) # Set the values to display when interactively configuring CMAKE_BUILD_TYPE diff --git a/src/coreclr/debug/runtimeinfo/CMakeLists.txt b/src/coreclr/debug/runtimeinfo/CMakeLists.txt index 018e49645cd0de..f7ff177b130a79 100644 --- a/src/coreclr/debug/runtimeinfo/CMakeLists.txt +++ b/src/coreclr/debug/runtimeinfo/CMakeLists.txt @@ -56,7 +56,9 @@ else() # turn off whole program optimization: # 1. it creates object files that cdac-build-tool can't read # 2. we never link cdac_data_descriptor into the final product - it's only job is to be scraped - target_compile_options(cdac_data_descriptor PRIVATE /GL-) + set_target_properties(cdac_data_descriptor PROPERTIES + INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF + INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO OFF) endif() target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR}) target_include_directories(cdac_data_descriptor BEFORE PRIVATE ${VM_DIR}/${ARCH_SOURCES_DIR}) diff --git a/src/coreclr/dlls/clretwrc/CMakeLists.txt b/src/coreclr/dlls/clretwrc/CMakeLists.txt index 2729a6072269bc..6ad0ec3e39a871 100644 --- a/src/coreclr/dlls/clretwrc/CMakeLists.txt +++ b/src/coreclr/dlls/clretwrc/CMakeLists.txt @@ -1,12 +1,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) if(CLR_CMAKE_HOST_WIN32) - # remove /ltcg from resource-only libraries - string(REPLACE "/LTCG" "" CMAKE_SHARED_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}) - string(REPLACE "/LTCG" "" CMAKE_STATIC_LINKER_FLAGS_RELEASE ${CMAKE_STATIC_LINKER_FLAGS_RELEASE}) - string(REPLACE "/LTCG" "" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}) - string(REPLACE "/LTCG" "" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}) - # remove /guard:cf, /guard:ehcont, and /CETCOMPAT from resource-only libraries set_property(DIRECTORY PROPERTY CLR_CONTROL_FLOW_GUARD OFF) diff --git a/src/coreclr/dlls/mscorrc/CMakeLists.txt b/src/coreclr/dlls/mscorrc/CMakeLists.txt index a8a363b1cc34db..16894714a4a633 100644 --- a/src/coreclr/dlls/mscorrc/CMakeLists.txt +++ b/src/coreclr/dlls/mscorrc/CMakeLists.txt @@ -4,9 +4,6 @@ add_definitions(-DFX_VER_INTERNALNAME_STR=mscorrc.dll) if(CLR_CMAKE_HOST_WIN32) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NOENTRY") - # remove /ltcg from resource-only libraries - string(REPLACE "/LTCG" "" CMAKE_SHARED_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}) - string(REPLACE "/LTCG" "" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}) # remove /guard:cf, /guard:ehcont, and /CETCOMPAT from resource-only libraries set_property(DIRECTORY PROPERTY CLR_CONTROL_FLOW_GUARD OFF) diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index 25c1d55e7360cd..7548062ca88a45 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -25,7 +25,7 @@ include_directories(${CLR_ARTIFACTS_OBJ_DIR}) # Generated version files add_subdirectory(../../hostmisc hostmisc) configure_file(${CLR_SRC_NATIVE_DIR}/corehost/configure.h.in ${GENERATED_INCLUDE_DIR}/corehost/configure.h) -target_include_directories(hostmisc PUBLIC ${GENERATED_INCLUDE_DIR}/corehost) +target_include_directories(hostmisc_interface INTERFACE ${GENERATED_INCLUDE_DIR}/corehost) if ((NOT DEFINED CLR_CMAKE_USE_SYSTEM_RAPIDJSON) OR (NOT CLR_CMAKE_USE_SYSTEM_RAPIDJSON)) include_directories(${CLR_SRC_NATIVE_DIR}/external/) diff --git a/src/native/corehost/fxr/staticlib/CMakeLists.txt b/src/native/corehost/fxr/staticlib/CMakeLists.txt index 9ab84349d1adcc..e28ac12681297c 100644 --- a/src/native/corehost/fxr/staticlib/CMakeLists.txt +++ b/src/native/corehost/fxr/staticlib/CMakeLists.txt @@ -40,9 +40,6 @@ if (MSVC) # LTCG must be disabled to ensure that non-MSVC toolchains can work with it. set_target_properties(libhostfxr PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) - - string(REPLACE "/LTCG" "" CMAKE_STATIC_LINKER_FLAGS_RELEASE ${CMAKE_STATIC_LINKER_FLAGS_RELEASE}) - string(REPLACE "/LTCG" "" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}) endif() # Only Windows creates a symbols file for static libs. @@ -52,4 +49,4 @@ else() install(TARGETS libhostfxr DESTINATION corehost) endif(WIN32) -target_link_libraries(libhostfxr PRIVATE hostmisc) +target_link_libraries(libhostfxr PRIVATE hostmisc::public) diff --git a/src/native/corehost/hostmisc/CMakeLists.txt b/src/native/corehost/hostmisc/CMakeLists.txt index f39b586590c62a..c381ddab0a117a 100644 --- a/src/native/corehost/hostmisc/CMakeLists.txt +++ b/src/native/corehost/hostmisc/CMakeLists.txt @@ -31,23 +31,34 @@ endif() # hostmisc must be an "object library" as we want to build it once # and embed the objects into static libraries we ship (like libnethost). -add_library(hostmisc OBJECT ${SOURCES}) - -target_include_directories(hostmisc PUBLIC +add_library(hostmisc_interface INTERFACE) +target_include_directories(hostmisc_interface INTERFACE ${CMAKE_CURRENT_BINARY_DIR} ${CLR_SRC_NATIVE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (MSVC) - target_sources(hostmisc PRIVATE ${HEADERS}) - target_link_libraries(hostmisc PUBLIC advapi32) + target_link_libraries(hostmisc_interface INTERFACE advapi32) endif() -target_link_libraries(hostmisc PUBLIC +target_link_libraries(hostmisc_interface INTERFACE ${CMAKE_DL_LIBS} $<$:${PTHREAD_LIB}>) if(CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARMV6) - target_link_libraries(hostmisc PUBLIC + target_link_libraries(hostmisc_interface INTERFACE $<$:${ATOMIC_SUPPORT_LIB}>) endif() + + +add_library(hostmisc STATIC ${SOURCES}) +target_link_libraries(hostmisc PUBLIC hostmisc_interface) +if (MSVC) + target_sources(hostmisc PRIVATE ${HEADERS}) +endif() + +add_library(hostmisc_public OBJECT ${SOURCES}) +target_link_libraries(hostmisc_public PUBLIC hostmisc_interface) +set_target_properties(hostmisc_public PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + +add_library(hostmisc::public ALIAS hostmisc_public) diff --git a/src/native/corehost/nethost/CMakeLists.txt b/src/native/corehost/nethost/CMakeLists.txt index 38b103b7178bee..83c6f4aac8e3ec 100644 --- a/src/native/corehost/nethost/CMakeLists.txt +++ b/src/native/corehost/nethost/CMakeLists.txt @@ -34,7 +34,7 @@ if (WIN32) endif(WIN32) target_link_libraries(nethost PRIVATE hostmisc fxr_resolver) -target_link_libraries(libnethost PRIVATE hostmisc fxr_resolver) +target_link_libraries(libnethost PRIVATE hostmisc::public fxr_resolver) target_compile_definitions(nethost PRIVATE FEATURE_LIBHOST NETHOST_EXPORT) target_compile_definitions(libnethost PRIVATE FEATURE_LIBHOST NETHOST_EXPORT) @@ -55,9 +55,6 @@ if (MSVC) # LTCG must be disabled to ensure that non-MSVC toolchains can work with it. set_target_properties(libnethost PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) - - string(REPLACE "/LTCG" "" CMAKE_STATIC_LINKER_FLAGS_RELEASE ${CMAKE_STATIC_LINKER_FLAGS_RELEASE}) - string(REPLACE "/LTCG" "" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}) endif() # Only Windows creates a symbols file for static libs. diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index 2f8b16276783f6..51320228df5ea5 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -18,6 +18,16 @@ else() include(${CLR_SRC_NATIVE_DIR}/external/brotli.cmake) endif() +if (STATIC_LIBS_ONLY) + # For every vendored library that we're actually vendoring (and not referencing the system one) + # mark it as "no interprocedural optimization" so that it's compatible with our NativeAOT shipping story. + foreach(VENDORED_LIB IN LISTS BROTLI_LIBRARIES ITEMS zlib) + if (TARGET ${VENDORED_LIB}) + set_target_properties(${VENDORED_LIB} PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) + endif() + endforeach() +endif() + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../Common/pal_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/pal_config.h)