Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify some cmake function definitions #33716

Merged
merged 8 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ while :; do
;;

stripsymbols|-stripsymbols)
__CMakeArgs="-DSTRIP_SYMBOLS=true $__CMakeArgs"
;;

verbose|-verbose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/configuretools.cmake)

# Set initial flags for each configuration

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -41,8 +43,6 @@ set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "")
add_compile_definitions("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:DEBUG;_DEBUG;_DBG;URTBLDENV_FRIENDLY=Checked;BUILDENV_CHECKED=1>")
add_compile_definitions("$<$<OR:$<CONFIG:RELEASE>,$<CONFIG:RELWITHDEBINFO>>:NDEBUG;URTBLDENV_FRIENDLY=Retail>")

set(CMAKE_CXX_STANDARD_LIBRARIES "") # do not link against standard win32 libs i.e. kernel32, uuid, user32, etc.

if (MSVC)
add_link_options(/GUARD:CF)

Expand Down Expand Up @@ -373,6 +373,9 @@ if(CLR_CMAKE_TARGET_UNIX)
if(CLR_CMAKE_TARGET_NETBSD)
add_definitions(-DTARGET_NETBSD)
endif(CLR_CMAKE_TARGET_NETBSD)
if(CLR_CMAKE_TARGET_ANDROID)
add_definitions(-DTARGET_ANDROID)
endif()
else(CLR_CMAKE_TARGET_UNIX)
add_definitions(-DTARGET_WINDOWS)
endif(CLR_CMAKE_TARGET_UNIX)
Expand Down Expand Up @@ -523,3 +526,61 @@ endif(CLR_CMAKE_ENABLE_CODE_COVERAGE)
if (CMAKE_BUILD_TOOL STREQUAL nmake)
set(CMAKE_RC_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
endif(CMAKE_BUILD_TOOL STREQUAL nmake)

# Ensure other tools are present
if (CLR_CMAKE_HOST_WIN32)
if(CLR_CMAKE_HOST_ARCH_ARM)

# Confirm that Windows SDK is present
if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
message(FATAL_ERROR "Windows SDK is required for the Arm32 build.")
else()
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

# Explicitly specify the assembler to be used for Arm32 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)

set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")

# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
elseif(CLR_CMAKE_HOST_ARCH_ARM64)

# Confirm that Windows SDK is present
if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
else()
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

# Explicitly specify the assembler to be used for Arm64 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)

set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")

# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
else()
enable_language(ASM_MASM)
endif()

# Ensure that MC is present
find_program(MC mc)
if (MC STREQUAL "MC-NOTFOUND")
message(FATAL_ERROR "MC not found")
endif()

else (CLR_CMAKE_HOST_WIN32)
enable_language(ASM)

# Ensure that awk is present
find_program(AWK awk)
if (AWK STREQUAL "AWK-NOTFOUND")
message(FATAL_ERROR "AWK not found")
endif()
endif(CLR_CMAKE_HOST_WIN32)
2 changes: 2 additions & 0 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ endif(CLR_CMAKE_HOST_OS STREQUAL Darwin)
if(CLR_CMAKE_HOST_OS STREQUAL iOS)
set(CLR_CMAKE_HOST_UNIX 1)
set(CLR_CMAKE_HOST_IOS 1)
set(CLR_CMAKE_HOST_DARWIN 1)
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved
if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "armv7")
Expand Down Expand Up @@ -255,6 +256,7 @@ endif(CLR_CMAKE_TARGET_OS STREQUAL Darwin)
if(CLR_CMAKE_TARGET_OS STREQUAL iOS)
set(CLR_CMAKE_TARGET_UNIX 1)
set(CLR_CMAKE_TARGET_IOS 1)
set(CLR_CMAKE_TARGET_DARWIN 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL iOS)

if(CLR_CMAKE_TARGET_OS STREQUAL FreeBSD)
Expand Down
4 changes: 2 additions & 2 deletions eng/native/configuretools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if(NOT WIN32)
locate_toolchain_exec(ranlib CMAKE_RANLIB)
endif()

if(NOT CLR_CMAKE_TARGET_DARWIN AND NOT CLR_CMAKE_TARGET_IOS)
if(NOT CLR_CMAKE_TARGET_DARWIN)
locate_toolchain_exec(objdump CMAKE_OBJDUMP)

if(CMAKE_SYSTEM_NAME STREQUAL Android)
Expand All @@ -60,5 +60,5 @@ if(NOT WIN32)
endif()

locate_toolchain_exec(objcopy CMAKE_OBJCOPY)
endif()
endif(NOT CLR_CMAKE_TARGET_DARWIN)
endif()
106 changes: 58 additions & 48 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function(preprocess_compile_asm)
set(oneValueArgs OUTPUT_OBJECTS)
set(multiValueArgs ASM_FILES)
cmake_parse_arguments(PARSE_ARGV 0 COMPILE_ASM "${options}" "${oneValueArgs}" "${multiValueArgs}")

get_include_directories_asm(ASM_INCLUDE_DIRECTORIES)

set (ASSEMBLED_OBJECTS "")
Expand Down Expand Up @@ -250,48 +250,62 @@ function(target_precompile_header)
endif(MSVC)
endfunction()

function(strip_symbols targetName outputFilename skipStrip)
function(strip_symbols targetName outputFilename)
if (CLR_CMAKE_HOST_UNIX)
if (STRIP_SYMBOLS)
set(strip_source_file $<TARGET_FILE:${targetName}>)

if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(strip_destination_file ${strip_source_file}.dwarf)

if(NOT ${skipStrip})
add_custom_command(
TARGET ${targetName}
POST_BUILD
VERBATIM
COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
COMMAND ${STRIP} -S ${strip_source_file}
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
)
endif()
else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(strip_destination_file ${strip_source_file}.dbg)

if(NOT ${skipStrip})
add_custom_command(
TARGET ${targetName}
POST_BUILD
VERBATIM
COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
COMMAND ${CMAKE_OBJCOPY} --strip-debug ${strip_source_file}
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
)
endif()
endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(strip_source_file $<TARGET_FILE:${targetName}>)

set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
endif (STRIP_SYMBOLS)
if (CLR_CMAKE_TARGET_DARWIN)
set(strip_destination_file ${strip_source_file}.dwarf)

# Ensure that dsymutil and strip are present
find_program(DSYMUTIL dsymutil)
if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
message(FATAL_ERROR "dsymutil not found")
endif()

find_program(STRIP strip)
if (STRIP STREQUAL "STRIP-NOTFOUND")
message(FATAL_ERROR "strip not found")
endif()

add_custom_command(
TARGET ${targetName}
POST_BUILD
VERBATIM
COMMAND ${DSYMUTIL} --flat --minimize ${strip_source_file}
COMMAND ${STRIP} -S ${strip_source_file}
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
)
else (CLR_CMAKE_TARGET_DARWIN)
set(strip_destination_file ${strip_source_file}.dbg)

add_custom_command(
TARGET ${targetName}
POST_BUILD
VERBATIM
COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file}
COMMAND ${CMAKE_OBJCOPY} --strip-debug ${strip_source_file}
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file}
)
endif (CLR_CMAKE_TARGET_DARWIN)

set(${outputFilename} ${strip_destination_file} PARENT_SCOPE)
endif(CLR_CMAKE_HOST_UNIX)
endfunction()

# install_clr(TARGETS TARGETS targetName [targetName2 ...] [DESTINATION destination] [SKIP_STRIP])
function(install_symbols targetName destination_path)
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 weird that we always strip symbols for libraries and strip them conditionally for coreclr. Since you are touching this code, I would take this opportunity to make the stripping unconditional. It should be fine (debugging should not be affected, I believe neither lldb nor gdb cares whether the symbols are in the .so files or in separate files) and it would also fix #32957 on OSX where debugging a core dump from checked / debug build is currently broken due to missing symbols.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we start by removing the top-level option:

echo "-stripsymbols: skip native image generation."

Copy link
Member

Choose a reason for hiding this comment

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

II would do it in 3 steps in this order:

  • Make stripping the symbols unconditional in the cmake files (essentially just ignore the -stripsymbols option as part of this PR
  • Remove passing in the -stripsymbols to the build scripts in the CI / build lab scripts in a follow up PR
  • Remove the -stripsymbols option support from the build-commons.sh

The point is that we don't want to have intermediate period where we would not be stripping the symbols and we also cannot pass in the -stripsymbols from the CI / build lab scripts after we remove support for that option from the build-commons.sh

Copy link
Member Author

Choose a reason for hiding this comment

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

Part 1 is pushed f193079. I will make followup PRs for 2 and 3. Thanks!

strip_symbols(${targetName} strip_destination_file)

if(CLR_CMAKE_TARGET_WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION ${destination_path}/PDB)
else()
install(FILES ${strip_destination_file} DESTINATION ${destination_path})
endif()
endfunction()

# install_clr(TARGETS TARGETS targetName [targetName2 ...] [DESTINATION destination])
function(install_clr)
set(options SKIP_STRIP)
set(oneValueArgs DESTINATION)
set(multiValueArgs TARGETS)
cmake_parse_arguments(PARSE_ARGV 0 INSTALL_CLR "${options}" "${oneValueArgs}" "${multiValueArgs}")
Expand All @@ -307,21 +321,12 @@ function(install_clr)
foreach(targetName ${INSTALL_CLR_TARGETS})
list(FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
if("${INSTALL_CLR_SKIP_STRIP}" STREQUAL "")
set(INSTALL_CLR_SKIP_STRIP FALSE)
endif()
strip_symbols(${targetName} strip_destination_file ${INSTALL_CLR_SKIP_STRIP})
install_symbols(${targetName} ${INSTALL_CLR_DESTINATION})

# We don't need to install the export libraries for our DLLs
# since they won't be directly linked against.
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${INSTALL_CLR_DESTINATION})
if(WIN32)
# We can't use the $<TARGET_PDB_FILE> generator expression here since
# the generator expression isn't supported on resource DLLs.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pdb DESTINATION ${INSTALL_CLR_DESTINATION}/PDB)
else()
install(FILES ${strip_destination_file} DESTINATION ${INSTALL_CLR_DESTINATION})
endif()

if(CLR_CMAKE_PGO_INSTRUMENT)
if(WIN32)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${targetName}.pgd DESTINATION ${INSTALL_CLR_DESTINATION}/PGD OPTIONAL)
Expand All @@ -339,6 +344,11 @@ endfunction()
# - creating executable pages from anonymous memory,
# - making read-only-after-relocations (RELRO) data pages writable again.
function(disable_pax_mprotect targetName)
# Try to locate the paxctl tool. Failure to find it is not fatal,
# but the generated executables won't work on a system where PAX is set
# to prevent applications to create executable memory mappings.
find_program(PAXCTL paxctl)

if (NOT PAXCTL STREQUAL "PAXCTL-NOTFOUND")
add_custom_command(
TARGET ${targetName}
Expand Down
File renamed without changes.
93 changes: 5 additions & 88 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ cmake_policy(SET CMP0042 NEW)
# Set the project name
project(CoreCLR)

include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake)
include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake)

if (CLR_CMAKE_HOST_WIN32)
message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
endif (CLR_CMAKE_HOST_WIN32)

if(MSVC)
set(CMAKE_CXX_STANDARD_LIBRARIES "") # do not link against standard win32 libs i.e. kernel32, uuid, user32, etc.
endif (MSVC)

# Set commonly used directory names
set(CLR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vm)
Expand All @@ -31,93 +35,6 @@ endif(CORECLR_SET_RPATH)

OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)

# Ensure other tools are present
if (CLR_CMAKE_HOST_WIN32)
if(CLR_CMAKE_HOST_ARCH_ARM)

# Confirm that Windows SDK is present
if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
message(FATAL_ERROR "Windows SDK is required for the Arm32 build.")
else()
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

# Explicitly specify the assembler to be used for Arm32 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)

set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")

# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
elseif(CLR_CMAKE_HOST_ARCH_ARM64)

# Confirm that Windows SDK is present
if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
else()
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

# Explicitly specify the assembler to be used for Arm64 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)

set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")

# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
else()
enable_language(ASM_MASM)
endif()

# Ensure that MC is present
find_program(MC mc)
if (MC STREQUAL "MC-NOTFOUND")
message(FATAL_ERROR "MC not found")
endif()

else (CLR_CMAKE_HOST_WIN32)
enable_language(ASM)

# Ensure that awk is present
find_program(AWK awk)
if (AWK STREQUAL "AWK-NOTFOUND")
message(FATAL_ERROR "AWK not found")
endif()

# Try to locate the paxctl tool. Failure to find it is not fatal,
# but the generated executables won't work on a system where PAX is set
# to prevent applications to create executable memory mappings.
find_program(PAXCTL paxctl)

if (CLR_CMAKE_HOST_DARWIN)

# Ensure that dsymutil and strip are present
find_program(DSYMUTIL dsymutil)
if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
message(FATAL_ERROR "dsymutil not found")
endif()

find_program(STRIP strip)
if (STRIP STREQUAL "STRIP-NOTFOUND")
message(FATAL_ERROR "strip not found")
endif()

endif()
endif(CLR_CMAKE_HOST_WIN32)

if(CLR_CMAKE_TARGET_ANDROID)
add_definitions(-DTARGET_ANDROID)
endif()

#----------------------------------------------------
# Configure compiler settings for environment
#----------------------------------------------------
include(configurecompiler.cmake)

#----------------------------------------------------
# Cross target Component build specific configuration
#----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ target_link_libraries(createdump
add_dependencies(createdump mscordaccore)

install_clr(TARGETS createdump)
install_clr(TARGETS createdump DESTINATION sharedFramework SKIP_STRIP)
install_clr(TARGETS createdump DESTINATION sharedFramework)
2 changes: 1 addition & 1 deletion src/coreclr/src/dlls/clretwrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ add_library_clr(clretwrc SHARED

# add the install targets
install_clr(TARGETS clretwrc)
install_clr(TARGETS clretwrc DESTINATION sharedFramework SKIP_STRIP)
install_clr(TARGETS clretwrc DESTINATION sharedFramework)

add_dependencies(clretwrc eventing_headers)
Loading