|
| 1 | +# Package: dyncall |
| 2 | +# File: CMakeLists.txt |
| 3 | +# Description: DynCall Project cmake files |
| 4 | +# License: |
| 5 | +# |
| 6 | +# Copyright (c) 2010-2020 Daniel Adler <[email protected]> |
| 7 | +# 2020 armasm64 support: Bernhard Urban-Forster <[email protected]> |
| 8 | +# |
| 9 | +# Permission to use, copy, modify, and distribute this software for any |
| 10 | +# purpose with or without fee is hereby granted, provided that the above |
| 11 | +# copyright notice and this permission notice appear in all copies. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 14 | +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 15 | +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 16 | +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 17 | +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 18 | +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 19 | +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 20 | +# |
| 21 | + |
| 22 | +cmake_minimum_required (VERSION 2.6) |
| 23 | +project(DynCall C) |
| 24 | + |
| 25 | +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "dyncall enables dynamic invocation of machine-level function calls") |
| 26 | +set(CPACK_PACKAGE_VENDOR "dyncall project") |
| 27 | +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") |
| 28 | +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") |
| 29 | +if(APPLE) |
| 30 | +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README") |
| 31 | +endif(APPLE) |
| 32 | +set(CPACK_PACKAGE_NAME "dyncall") |
| 33 | +include(CPack) |
| 34 | + |
| 35 | +# add cmake modules shipped with the package to cmake's module path. |
| 36 | +# currently we have no use for this, but maybe later.. |
| 37 | +#set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/buildsys/cmake/Modules" "${CMAKE_MODULE_PATH}") |
| 38 | + |
| 39 | +option(LANG_CXX "Enable and build C++ tests" ON) |
| 40 | + |
| 41 | +if(LANG_CXX) |
| 42 | + enable_language(CXX) |
| 43 | +endif() |
| 44 | + |
| 45 | +include(CheckCCompilerFlag) |
| 46 | +check_c_compiler_flag("-fPIC -Werror" COMPILER_HAS_FPIC) |
| 47 | + |
| 48 | + |
| 49 | +add_custom_target(show-compiler-predefs COMMAND ${CMAKE_C_COMPILER_PREDEFINES_COMMAND}) |
| 50 | + |
| 51 | + |
| 52 | +# compile_asm(TARGET target ASM_FILES file1 [file2 ...] OUTPUT_OBJECTS [variableName]) |
| 53 | +# CMake does not support the ARM or ARM64 assemblers on Windows when using the |
| 54 | +# MSBuild generator. |
| 55 | +# credit to dotnet/runtime: |
| 56 | +# https://github.com/dotnet/runtime/blob/e98fb61d8b4bb6687ccddead861d8b140751647b/eng/native/functions.cmake#L173-L207 |
| 57 | +function(compile_asm) |
| 58 | + set(options "") |
| 59 | + set(oneValueArgs TARGET OUTPUT_OBJECTS) |
| 60 | + set(multiValueArgs ASM_FILES) |
| 61 | + cmake_parse_arguments(COMPILE_ASM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGV}) |
| 62 | + |
| 63 | + set (ASSEMBLED_OBJECTS "") |
| 64 | + |
| 65 | + foreach(ASM_FILE ${COMPILE_ASM_ASM_FILES}) |
| 66 | + get_filename_component(name ${ASM_FILE} NAME_WE) |
| 67 | + # Produce object file where CMake would store .obj files for an OBJECT library. |
| 68 | + # ex: artifacts\obj\coreclr\windows.arm64.Debug\src\vm\wks\cee_wks.dir\Debug\AsmHelpers.obj |
| 69 | + set (OBJ_FILE "${CMAKE_CURRENT_BINARY_DIR}/${COMPILE_ASM_TARGET}.dir/${CMAKE_CFG_INTDIR}/${name}.obj") |
| 70 | + |
| 71 | + # Need to compile asm file using custom command as include directories are not provided to asm compiler |
| 72 | + add_custom_command(OUTPUT ${OBJ_FILE} |
| 73 | + COMMAND "${CMAKE_ASM_COMPILER}" ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_FILE} |
| 74 | + DEPENDS ${ASM_FILE} |
| 75 | + COMMENT "Assembling ${ASM_FILE} ---> \"${CMAKE_ASM_COMPILER}\" ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_FILE}"+ COMMENT "Assembling ${ASM_FILE} ---> \"${CMAKE_ASM_COMPILER}\" ${ASM_INCLUDE_DIRECTORIES} -o ${OBJ_FILE} ${ASM_FILE}") |
| 76 | + |
| 77 | + # mark obj as source that does not require compile |
| 78 | + set_source_files_properties(${OBJ_FILE} PROPERTIES EXTERNAL_OBJECT TRUE) |
| 79 | + |
| 80 | + # Add the generated OBJ in the dependency list so that it gets consumed during linkage |
| 81 | + list(APPEND ASSEMBLED_OBJECTS ${OBJ_FILE}) |
| 82 | + endforeach() |
| 83 | + |
| 84 | + set(${COMPILE_ASM_OUTPUT_OBJECTS} ${ASSEMBLED_OBJECTS} PARENT_SCOPE) |
| 85 | +endfunction() |
| 86 | + |
| 87 | + |
| 88 | +if(MSVC) |
| 89 | + if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64") |
| 90 | + # Explicitly specify the assembler to be used for Arm64 compile |
| 91 | + file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX64\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER) |
| 92 | + # file(TO_CMAKE_PATH "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER) |
| 93 | + |
| 94 | + set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER}) |
| 95 | + message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}") |
| 96 | + # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly |
| 97 | + # use ml[64].exe as the assembler. |
| 98 | + enable_language(ASM) |
| 99 | + set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") |
| 100 | + set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "") |
| 101 | + set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "") |
| 102 | + set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "") |
| 103 | + set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>") |
| 104 | + else() |
| 105 | + enable_language(ASM_MASM) |
| 106 | + |
| 107 | + #if(CMAKE_SIZEOF_VOID_P MATCHES 8) |
| 108 | + # set(CMAKE_ASM_COMPILER "ml64") |
| 109 | + #else() |
| 110 | + # set(CMAKE_ASM_COMPILER "ml") |
| 111 | + #endif() |
| 112 | + #set(CMAKE_ASM_COMPILER_ARG1 "/c") |
| 113 | + #set(CMAKE_ASM_MASM_SOURCE_FILE_EXTENSIONS asm) |
| 114 | + #set(CMAKE_ASM_MASM_COMPILE_OBJECT "<CMAKE_ASM_MASM_COMPILER> <FLAGS> /c /Fo <OBJECT> <SOURCE>") |
| 115 | + endif() |
| 116 | +elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Intel") |
| 117 | + if(COMPILER_HAS_FPIC) |
| 118 | + # when used in shared libraries, -fPIC is required by several architectures |
| 119 | + # and platforms (observed on AMD64, Solaris/Sparc). |
| 120 | + # we enable it per default here. |
| 121 | + add_definitions("-fPIC") |
| 122 | + endif() |
| 123 | + # enable gcc as front-end to assembler for .S files |
| 124 | + set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}") |
| 125 | + set(CMAKE_ASM_COMPILER_ARG1 "${CPPFLAGS} -c") |
| 126 | + enable_language(ASM) |
| 127 | +elseif(CMAKE_COMPILER_IS_CLANG) |
| 128 | +elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "SunPro") |
| 129 | + set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}") |
| 130 | + set(CMAKE_ASM_COMPILER_ARG1 "${CPPFLAGS} -c") |
| 131 | + enable_language(ASM) |
| 132 | +else() |
| 133 | + if (CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 134 | + if(COMPILER_HAS_FPIC) |
| 135 | + add_definitions("-fPIC") |
| 136 | + endif() |
| 137 | + # enable gcc as front-end to assembler for .S files |
| 138 | + set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}") |
| 139 | + set(CMAKE_ASM_COMPILER_ARG1 "${CPPFLAGS} -c") |
| 140 | + enable_language(ASM) |
| 141 | + endif() |
| 142 | +endif() |
| 143 | + |
| 144 | +add_subdirectory(dynload) |
| 145 | +add_subdirectory(dyncall) |
| 146 | +add_subdirectory(dyncallback) |
| 147 | +add_subdirectory(doc/manual EXCLUDE_FROM_ALL) |
| 148 | +add_subdirectory(test EXCLUDE_FROM_ALL) |
| 149 | + |
| 150 | +# install cmake Find scripts (disabled per default) |
| 151 | + |
| 152 | +option(INSTALL_CMAKE_MODULES "install cmake modules to locate dyncall" "NO") |
| 153 | + |
| 154 | +if(INSTALL_CMAKE_MODULES) |
| 155 | +file(GLOB INSTALL_CMAKE_MODULES_FILES buildsys/cmake/Modules/Find*.cmake) |
| 156 | +install(FILES ${INSTALL_CMAKE_MODULES_FILES} DESTINATION ${CMAKE_ROOT}/Modules) |
| 157 | +endif(INSTALL_CMAKE_MODULES) |
| 158 | + |
0 commit comments