diff options
Diffstat (limited to 'cmake')
-rwxr-xr-x | cmake/config-ix.cmake | 32 | ||||
-rw-r--r-- | cmake/modules/AddLLVM.cmake | 122 | ||||
-rw-r--r-- | cmake/modules/AddSphinxTarget.cmake | 11 | ||||
-rw-r--r-- | cmake/modules/CMakeLists.txt | 4 | ||||
-rw-r--r-- | cmake/modules/CheckAtomic.cmake | 5 | ||||
-rw-r--r-- | cmake/modules/CrossCompile.cmake | 33 | ||||
-rw-r--r-- | cmake/modules/FindSphinx.cmake | 2 | ||||
-rw-r--r-- | cmake/modules/GetSVN.cmake | 54 | ||||
-rw-r--r-- | cmake/modules/HandleLLVMOptions.cmake | 79 | ||||
-rw-r--r-- | cmake/modules/LLVM-Config.cmake | 17 | ||||
-rw-r--r-- | cmake/modules/LLVMConfig.cmake.in | 7 | ||||
-rw-r--r-- | cmake/modules/LLVMProcessSources.cmake | 13 | ||||
-rw-r--r-- | cmake/modules/Makefile | 39 | ||||
-rw-r--r-- | cmake/modules/TableGen.cmake | 30 | ||||
-rw-r--r-- | cmake/platforms/iOS.cmake | 47 |
15 files changed, 381 insertions, 114 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index b862ceb..5204f6c 100755 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -42,7 +42,6 @@ function(check_type_exists type files variable) endfunction() # include checks -check_include_file_cxx(cxxabi.h HAVE_CXXABI_H) check_include_file(dirent.h HAVE_DIRENT_H) check_include_file(dlfcn.h HAVE_DLFCN_H) check_include_file(errno.h HAVE_ERRNO_H) @@ -50,6 +49,7 @@ check_include_file(execinfo.h HAVE_EXECINFO_H) check_include_file(fcntl.h HAVE_FCNTL_H) check_include_file(inttypes.h HAVE_INTTYPES_H) check_include_file(limits.h HAVE_LIMITS_H) +check_include_file(link.h HAVE_LINK_H) check_include_file(malloc.h HAVE_MALLOC_H) check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) check_include_file(ndir.h HAVE_NDIR_H) @@ -80,6 +80,13 @@ check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT) check_include_file(mach/mach.h HAVE_MACH_MACH_H) check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H) +# size_t must be defined before including cxxabi.h on FreeBSD 10.0. +check_cxx_source_compiles(" +#include <stddef.h> +#include <cxxabi.h> +int main() { return 0; } +" HAVE_CXXABI_H) + # library checks if( NOT PURE_WINDOWS ) check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) @@ -258,12 +265,12 @@ endif () if( LLVM_ENABLE_FFI ) find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR}) - if( FFI_INCLUDE_PATH ) + if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" ) set(FFI_HEADER ffi.h CACHE INTERNAL "") set(HAVE_FFI_H 1 CACHE INTERNAL "") else() find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR}) - if( FFI_INCLUDE_PATH ) + if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" ) set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "") set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "") endif() @@ -490,3 +497,22 @@ if (LLVM_ENABLE_SPHINX) else() message(STATUS "Sphinx disabled.") endif() + +set(LLVM_BINDINGS "") +if(WIN32) + message(STATUS "Go bindings disabled.") +else() + find_program(GO_EXECUTABLE NAMES go DOC "go executable") + if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND") + message(STATUS "Go bindings disabled.") + else() + execute_process(COMMAND ${GO_EXECUTABLE} run ${CMAKE_SOURCE_DIR}/bindings/go/conftest.go + RESULT_VARIABLE GO_CONFTEST) + if(GO_CONFTEST STREQUAL "0") + set(LLVM_BINDINGS "${LLVM_BINDINGS} go") + message(STATUS "Go bindings enabled.") + else() + message(STATUS "Go bindings disabled, need at least Go 1.2.") + endif() + endif() +endif() diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 31540d9..bc26f06 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -8,8 +8,13 @@ function(llvm_update_compile_flags name) set(update_src_props ON) endif() - if(LLVM_REQUIRES_EH) - set(LLVM_REQUIRES_RTTI ON) + # LLVM_REQUIRES_EH is an internal flag that individual + # targets can use to force EH + if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH) + if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) + message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}") + set(LLVM_REQUIRES_RTTI ON) + endif() else() if(LLVM_COMPILER_IS_GCC_COMPATIBLE) list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions") @@ -19,7 +24,9 @@ function(llvm_update_compile_flags name) endif() endif() - if(NOT LLVM_REQUIRES_RTTI) + # LLVM_REQUIRES_RTTI is an internal flag that individual + # targets can use to force RTTI + if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0) if (LLVM_COMPILER_IS_GCC_COMPATIBLE) list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti") @@ -78,27 +85,29 @@ function(add_llvm_symbol_exports target_name export_file) else() set(native_export_file "${target_name}.def") - set(CAT "type") - if(CYGWIN) - set(CAT "cat") + set(CAT "cat") + set(export_file_nativeslashes ${export_file}) + if(WIN32 AND NOT CYGWIN) + set(CAT "type") + # Convert ${export_file} to native format (backslashes) for "type" + # Does not use file(TO_NATIVE_PATH) as it doesn't create a native + # path but a build-system specific format (see CMake bug + # http://public.kitware.com/Bug/print_bug_page.php?bug_id=5939 ) + string(REPLACE / \\ export_file_nativeslashes ${export_file}) endif() - # Using ${export_file} in add_custom_command directly confuses cmd.exe. - file(TO_NATIVE_PATH ${export_file} export_file_backslashes) - add_custom_command(OUTPUT ${native_export_file} COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > ${native_export_file} - COMMAND ${CAT} ${export_file_backslashes} >> ${native_export_file} + COMMAND ${CAT} ${export_file_nativeslashes} >> ${native_export_file} DEPENDS ${export_file} VERBATIM COMMENT "Creating export file for ${target_name}") - if(CYGWIN OR MINGW) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") - else() - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " /DEF:${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") + set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") + if(MSVC) + set(export_file_linker_flag "/DEF:${export_file_linker_flag}") endif() + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " ${export_file_linker_flag}") endif() add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) @@ -133,18 +142,29 @@ function(add_llvm_symbol_exports target_name export_file) set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) endfunction(add_llvm_symbol_exports) -function(add_dead_strip target_name) +function(add_link_opts target_name) + # Pass -O3 to the linker. This enabled different optimizations on different + # linkers. + if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32)) + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-O3") + endif() + if(NOT LLVM_NO_DEAD_STRIP) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + # ld64's implementation of -dead_strip breaks tools that use plugins. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip") elseif(NOT WIN32) # Object files are compiled with -ffunction-data-sections. + # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks + # tools that use plugins. Always pass --gc-sections once we require + # a newer linker. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections") endif() endif() -endfunction(add_dead_strip) +endfunction(add_link_opts) # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, @@ -155,19 +175,28 @@ function(set_output_directory target bindir libdir) return() endif() + # moddir -- corresponding to LIBRARY_OUTPUT_DIRECTORY. + # It affects output of add_library(MODULE). + if(WIN32 OR CYGWIN) + # DLL platform + set(moddir ${bindir}) + else() + set(moddir ${libdir}) + endif() if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) string(TOUPPER "${build_mode}" CONFIG_SUFFIX) string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${bindir}) string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${libdir}) + string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir}) set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) - set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) + set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi}) endforeach() else() set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bindir}) set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libdir}) - set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libdir}) + set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir}) endif() endfunction() @@ -265,7 +294,7 @@ function(llvm_add_library name) endif() set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) llvm_update_compile_flags(${name}) - add_dead_strip( ${name} ) + add_link_opts( ${name} ) if(ARG_OUTPUT_NAME) set_target_properties(${name} PROPERTIES @@ -294,6 +323,12 @@ function(llvm_add_library name) endif() if(ARG_MODULE OR ARG_SHARED) + # Do not add -Dname_EXPORTS to the command-line when building files in this + # target. Doing so is actively harmful for the modules build because it + # creates extra module variants, and not useful because we don't use these + # macros. + set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) + if (LLVM_EXPORTED_SYMBOL_FILE) add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) endif() @@ -324,15 +359,8 @@ function(llvm_add_library name) ${lib_deps} ${llvm_libs} ) - elseif(ARG_SHARED AND BUILD_SHARED_LIBS) - # FIXME: It may be PRIVATE since SO knows its dependent libs. - target_link_libraries(${name} PUBLIC - ${ARG_LINK_LIBS} - ${lib_deps} - ${llvm_libs} - ) else() - # MODULE|SHARED + # We can use PRIVATE since SO knows its dependent libs. target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS} ${lib_deps} @@ -364,6 +392,7 @@ macro(add_llvm_library name) if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO") install(TARGETS ${name} EXPORT LLVMExports + RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) endif() @@ -382,9 +411,15 @@ macro(add_llvm_loadable_module name) set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) else() if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + if(WIN32 OR CYGWIN) + # DLL platform + set(dlldir "bin") + else() + set(dlldir "lib${LLVM_LIBDIR_SUFFIX}") + endif() install(TARGETS ${name} EXPORT LLVMExports - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} + LIBRARY DESTINATION ${dlldir} ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) endif() set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) @@ -403,7 +438,13 @@ macro(add_llvm_executable name) add_executable(${name} ${ALL_FILES}) endif() llvm_update_compile_flags(${name}) - add_dead_strip( ${name} ) + add_link_opts( ${name} ) + + # Do not add -Dname_EXPORTS to the command-line when building files in this + # target. Doing so is actively harmful for the modules build because it + # creates extra module variants, and not useful because we don't use these + # macros. + set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) if (LLVM_EXPORTED_SYMBOL_FILE) add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) @@ -609,21 +650,9 @@ function(configure_lit_site_cfg input output) set(HOST_OS ${CMAKE_SYSTEM_NAME}) set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR}) - if (CLANG_ENABLE_ARCMT) - set(ENABLE_CLANG_ARCMT "1") - else() - set(ENABLE_CLANG_ARCMT "0") - endif() - if (CLANG_ENABLE_REWRITER) - set(ENABLE_CLANG_REWRITER "1") - else() - set(ENABLE_CLANG_REWRITER "0") - endif() - if (CLANG_ENABLE_STATIC_ANALYZER) - set(ENABLE_CLANG_STATIC_ANALYZER "1") - else() - set(ENABLE_CLANG_STATIC_ANALYZER "0") - endif() + set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") + set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") + set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}") configure_file(${input} ${output} @ONLY) endfunction() @@ -650,6 +679,7 @@ function(add_lit_target target comment) add_custom_target(${target} COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS} COMMENT "${comment}" + ${cmake_3_2_USES_TERMINAL} ) add_dependencies(${target} ${ARG_DEPENDS}) else() diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake index fc28a49..045dc23 100644 --- a/cmake/modules/AddSphinxTarget.cmake +++ b/cmake/modules/AddSphinxTarget.cmake @@ -8,16 +8,23 @@ function (add_sphinx_target builder project) set(SPHINX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${builder}") set(SPHINX_DOC_TREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees") set(SPHINX_TARGET_NAME docs-${project}-${builder}) + + if (SPHINX_WARNINGS_AS_ERRORS) + set(SPHINX_WARNINGS_AS_ERRORS_FLAG "-W") + else() + set(SPHINX_WARNINGS_AS_ERRORS_FLAG "") + endif() + add_custom_target(${SPHINX_TARGET_NAME} COMMAND ${SPHINX_EXECUTABLE} -b ${builder} -d "${SPHINX_DOC_TREE_DIR}" -q # Quiet: no output other than errors and warnings. - -W # Warnings are errors. + ${SPHINX_WARNINGS_AS_ERRORS_FLAG} # Treat warnings as errors if requested "${CMAKE_CURRENT_SOURCE_DIR}" # Source "${SPHINX_BUILD_DIR}" # Output COMMENT - "Generating ${builder} Sphinx documentation for ${project}") + "Generating ${builder} Sphinx documentation for ${project} into \"${SPHINX_BUILD_DIR}\"") # When "clean" target is run, remove the Sphinx build directory set_property(DIRECTORY APPEND PROPERTY diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index 08aeeb9..c87193d 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -17,11 +17,9 @@ endforeach(lib) set(LLVM_CONFIG_CODE " # LLVM_BUILD_* values available only from LLVM build tree. set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\") -set(LLVM_BUILD_ENABLE_ASSERTIONS \"${LLVM_ENABLE_ASSERTIONS}\") set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\") set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\") set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\") -set(LLVM_BUILD_TOOLS_BINARY_DIR \"${LLVM_TOOLS_BINARY_DIR}\") ") set(LLVM_CONFIG_INCLUDE_DIRS "${LLVM_MAIN_INCLUDE_DIR}" @@ -31,6 +29,7 @@ set(LLVM_CONFIG_LIBRARY_DIRS "${LLVM_LIBRARY_DIR}" ) set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") set(LLVM_CONFIG_EXPORTS_FILE "${llvm_cmake_builddir}/LLVMExports.cmake") configure_file( LLVMConfig.cmake.in @@ -61,6 +60,7 @@ endforeach(p) set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib") set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") +set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") configure_file( LLVMConfig.cmake.in diff --git a/cmake/modules/CheckAtomic.cmake b/cmake/modules/CheckAtomic.cmake index 0d63a82..2ed4819 100644 --- a/cmake/modules/CheckAtomic.cmake +++ b/cmake/modules/CheckAtomic.cmake @@ -2,6 +2,11 @@ INCLUDE(CheckCXXSourceCompiles) +check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) +if (HAVE_LIBATOMIC) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") +endif() + CHECK_CXX_SOURCE_COMPILES(" #ifdef _MSC_VER #include <windows.h> diff --git a/cmake/modules/CrossCompile.cmake b/cmake/modules/CrossCompile.cmake new file mode 100644 index 0000000..400381c --- /dev/null +++ b/cmake/modules/CrossCompile.cmake @@ -0,0 +1,33 @@ +if(NOT DEFINED LLVM_NATIVE_BUILD) + set(LLVM_NATIVE_BUILD "${CMAKE_BINARY_DIR}/native") + message(STATUS "Setting native build dir to ${LLVM_NATIVE_BUILD}") +endif(NOT DEFINED LLVM_NATIVE_BUILD) + +add_custom_command(OUTPUT ${LLVM_NATIVE_BUILD} + COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_NATIVE_BUILD} + COMMENT "Creating ${LLVM_NATIVE_BUILD}...") + +add_custom_command(OUTPUT ${LLVM_NATIVE_BUILD}/CMakeCache.txt + COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} + DEPENDS ${LLVM_NATIVE_BUILD} + COMMENT "Configuring native LLVM...") + +add_custom_target(ConfigureNativeLLVM DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt) + +set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${LLVM_NATIVE_BUILD}) + +if(NOT IS_DIRECTORY ${LLVM_NATIVE_BUILD}) + if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") + set(HOST_SYSROOT_FLAGS -DCMAKE_OSX_SYSROOT=macosx) + endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") + + message(STATUS "Configuring native build...") + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory + ${LLVM_NATIVE_BUILD} ) + + message(STATUS "Configuring native targets...") + execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release + -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} ${HOST_SYSROOT_FLAGS} ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} ) +endif(NOT IS_DIRECTORY ${LLVM_NATIVE_BUILD}) diff --git a/cmake/modules/FindSphinx.cmake b/cmake/modules/FindSphinx.cmake index a2adcae..9d252e8 100644 --- a/cmake/modules/FindSphinx.cmake +++ b/cmake/modules/FindSphinx.cmake @@ -23,3 +23,5 @@ find_package_handle_standard_args(Sphinx # Provide options for controlling different types of output option(SPHINX_OUTPUT_HTML "Output standalone HTML files" ON) option(SPHINX_OUTPUT_MAN "Output man pages" ON) + +option(SPHINX_WARNINGS_AS_ERRORS "When building documentation treat warnings as errors" ON) diff --git a/cmake/modules/GetSVN.cmake b/cmake/modules/GetSVN.cmake index acccc12..4e32c09 100644 --- a/cmake/modules/GetSVN.cmake +++ b/cmake/modules/GetSVN.cmake @@ -2,24 +2,44 @@ # # Input variables: # FIRST_SOURCE_DIR - First source directory -# FIRST_REPOSITORY - The macro to define to the first revision number. -# SECOND_SOURCE_DIR - Second source directory -# SECOND_REPOSITORY - The macro to define to the second revision number. +# FIRST_NAME - The macro prefix for the first repository's info +# SECOND_SOURCE_DIR - Second source directory (opt) +# SECOND_NAME - The macro prefix for the second repository's info (opt) # HEADER_FILE - The header file to write -include(FindSubversion) -if (Subversion_FOUND AND EXISTS "${FIRST_SOURCE_DIR}/.svn") - # Repository information for the first repository. - Subversion_WC_INFO(${FIRST_SOURCE_DIR} MY) - file(WRITE ${HEADER_FILE}.txt "#define ${FIRST_REPOSITORY} \"${MY_WC_REVISION}\"\n") +# +# The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION, +# and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and +# "SECOND" are substituted with the names specified in the input variables. + +# Chop off cmake/modules/GetSVN.cmake +get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH) +get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH) +get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH) + +# Handle strange terminals +set(ENV{TERM} "dumb") - # Repository information for the second repository. - if (EXISTS "${SECOND_SOURCE_DIR}/.svn") - Subversion_WC_INFO(${SECOND_SOURCE_DIR} MY) - file(APPEND ${HEADER_FILE}.txt - "#define ${SECOND_REPOSITORY} \"${MY_WC_REVISION}\"\n") - endif () +function(append_info name path) + execute_process(COMMAND "${LLVM_DIR}/utils/GetSourceVersion" "${path}" + OUTPUT_VARIABLE revision) + string(STRIP "${revision}" revision) + execute_process(COMMAND "${LLVM_DIR}/utils/GetRepositoryPath" "${path}" + OUTPUT_VARIABLE repository + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(STRIP "${repository}" repository) + file(APPEND "${HEADER_FILE}.txt" + "#define ${name}_REVISION \"${revision}\"\n") + file(APPEND "${HEADER_FILE}.txt" + "#define ${name}_REPOSITORY \"${repository}\"\n") +endfunction() - # Copy the file only if it has changed. - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${HEADER_FILE}.txt ${HEADER_FILE}) +append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}") +if(DEFINED SECOND_SOURCE_DIR) + append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}") endif() + +# Copy the file only if it has changed. +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${HEADER_FILE}.txt" "${HEADER_FILE}") +file(REMOVE "${HEADER_FILE}.txt") + diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index b8577f7..6cc6d65 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -2,6 +2,10 @@ # options and executing the appropriate CMake commands to realize the users' # selections. +# This is commonly needed so make sure it's defined before we include anything +# else. +string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + include(HandleLLVMStdlib) include(AddLLVMDefinitions) include(CheckCCompilerFlag) @@ -25,9 +29,6 @@ if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN) set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) set(CMAKE_REQUIRED_FLAGS "-std=c++0x") - if (ANDROID) - set(CMAKE_REQUIRED_LIBRARIES "atomic") - endif() check_cxx_source_compiles(" #include <atomic> std::atomic<float> x(0.0f); @@ -131,7 +132,7 @@ endmacro() function(add_flag_or_print_warning flag name) check_c_compiler_flag("-Werror ${flag}" "C_SUPPORTS_${name}") check_cxx_compiler_flag("-Werror ${flag}" "CXX_SUPPORTS_${name}") - if ("C_SUPPORTS_${name}" AND "CXX_SUPPORTS_${name}") + if (C_SUPPORTS_${name} AND CXX_SUPPORTS_${name}) message(STATUS "Building with ${flag}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) @@ -170,6 +171,10 @@ if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) endif( LLVM_BUILD_32_BITS ) endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) +if (LLVM_BUILD_STATIC) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") +endif() + if( XCODE ) # For Xcode enable several build settings that correspond to # many warnings that are on by default in Clang but are @@ -240,11 +245,16 @@ if( MSVC ) -wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned' -wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored' -wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data' + -wd4258 # Suppress ''var' : definition from the for loop is ignored; the definition from the enclosing scope is used' -wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data' -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception' -wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized' -wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized' -wd4355 # Suppress ''this' : used in base member initializer list' + -wd4456 # Suppress 'declaration of 'var' hides local variable' + -wd4457 # Suppress 'declaration of 'var' hides function parameter' + -wd4458 # Suppress 'declaration of 'var' hides class member' + -wd4459 # Suppress 'declaration of 'var' hides global declaration' -wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated' -wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible' -wd4722 # Suppress 'function' : destructor never returns, potential memory leak @@ -270,6 +280,7 @@ if( MSVC ) elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) if (LLVM_ENABLE_WARNINGS) append("-Wall -W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + append("-Wcast-qual" CMAKE_CXX_FLAGS) # Turn off missing field initializer warnings for gcc to avoid noise from # false positives with empty {}. Turn them on otherwise (they're off by @@ -287,13 +298,25 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG) append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS) append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS) - check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG) - append_if(CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS) + + # Check if -Wnon-virtual-dtor warns even though the class is marked final. + # If it does, don't add it. So it won't be added on clang 3.4 and older. + # This also catches cases when -Wnon-virtual-dtor isn't supported by + # the compiler at all. + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11 -Werror=non-virtual-dtor") + CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();protected: ~base();}; + class derived final : public base { public: ~derived();}; + int main() { return 0; }" + CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + append_if(CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR + "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS) # Check if -Wcomment is OK with an // comment ending with '\' if the next # line is also a // comment. set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -Werror -Wcomment) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror -Wcomment") CHECK_C_SOURCE_COMPILES("// \\\\\\n//\\nint main() {return 0;}" C_WCOMMENT_ALLOWS_LINE_WRAP) set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) @@ -322,6 +345,25 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE ) message(FATAL_ERROR "LLVM requires C++11 support but the '-std=c++11' flag isn't supported.") endif() endif() + if (LLVM_ENABLE_MODULES) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fmodules -fcxx-modules") + # Check that we can build code with modules enabled, and that repeatedly + # including <cassert> still manages to respect NDEBUG properly. + CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG + #include <cassert> + #define NDEBUG + #include <cassert> + int main() { assert(this code is not compiled); }" + CXX_SUPPORTS_MODULES) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + if (CXX_SUPPORTS_MODULES) + append_if(CXX_SUPPORTS_MODULES "-fmodules" CMAKE_C_FLAGS) + append_if(CXX_SUPPORTS_MODULES "-fmodules -fcxx-modules" CMAKE_CXX_FLAGS) + else() + message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler") + endif() + endif(LLVM_ENABLE_MODULES) endif( MSVC ) macro(append_common_sanitizer_flags) @@ -350,6 +392,13 @@ if(LLVM_USE_SANITIZER) if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") append("-fsanitize-memory-track-origins" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() + elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") + append_common_sanitizer_flags() + append("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover" + CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + elseif (LLVM_USE_SANITIZER STREQUAL "Thread") + append_common_sanitizer_flags() + append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) else() message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") endif() @@ -360,7 +409,7 @@ endif() # Turn on -gsplit-dwarf if requested if(LLVM_USE_SPLIT_DWARF) - add_llvm_definitions("-gsplit-dwarf") + add_definitions("-gsplit-dwarf") endif() add_llvm_definitions( -D__STDC_CONSTANT_MACROS ) @@ -408,11 +457,21 @@ if(MSVC) string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() +# Provide public options to globally control RTTI and EH +option(LLVM_ENABLE_EH "Enable Exception handling" OFF) +option(LLVM_ENABLE_RTTI "Enable run time type information" OFF) +if(LLVM_ENABLE_EH AND NOT LLVM_ENABLE_RTTI) + message(FATAL_ERROR "Exception handling requires RTTI. You must set LLVM_ENABLE_RTTI to ON") +endif() + # Plugin support # FIXME: Make this configurable. if(WIN32 OR CYGWIN) - # DLL platform(s) don't support plugins. - set(LLVM_ENABLE_PLUGINS OFF) + if(BUILD_SHARED_LIBS) + set(LLVM_ENABLE_PLUGINS ON) + else() + set(LLVM_ENABLE_PLUGINS OFF) + endif() else() set(LLVM_ENABLE_PLUGINS ON) endif() diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake index 2783af8..e8c42fc 100644 --- a/cmake/modules/LLVM-Config.cmake +++ b/cmake/modules/LLVM-Config.cmake @@ -40,9 +40,9 @@ function(explicit_llvm_config executable) llvm_map_components_to_libnames(LIBRARIES ${link_components}) get_target_property(t ${executable} TYPE) - if("${t}" STREQUAL "STATIC_LIBRARY") + if("x${t}" STREQUAL "xSTATIC_LIBRARY") target_link_libraries(${executable} ${cmake_2_8_12_INTERFACE} ${LIBRARIES}) - elseif("${t}" STREQUAL "SHARED_LIBRARY" OR "${t}" STREQUAL "MODULE_LIBRARY") + elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY") target_link_libraries(${executable} ${cmake_2_8_12_PRIVATE} ${LIBRARIES}) else() # Use plain form for legacy user. @@ -51,12 +51,14 @@ function(explicit_llvm_config executable) endfunction(explicit_llvm_config) -# This is a variant intended for the final user: +# This is Deprecated function(llvm_map_components_to_libraries OUT_VAR) + message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead") explicit_map_components_to_libraries(result ${ARGN}) set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE ) endfunction(llvm_map_components_to_libraries) +# This is a variant intended for the final user: # Map LINK_COMPONENTS to actual libnames. function(llvm_map_components_to_libnames out_libs) set( link_components ${ARGN} ) @@ -105,6 +107,9 @@ function(llvm_map_components_to_libnames out_libs) if( TARGET LLVM${c}AsmParser ) list(APPEND expanded_components "LLVM${c}AsmParser") endif() + if( TARGET LLVM${c}Desc ) + list(APPEND expanded_components "LLVM${c}Desc") + endif() if( TARGET LLVM${c}Info ) list(APPEND expanded_components "LLVM${c}Info") endif() @@ -115,6 +120,12 @@ function(llvm_map_components_to_libnames out_libs) # already processed elseif( c STREQUAL "nativecodegen" ) list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") + if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc ) + list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc") + endif() + if( TARGET LLVM${LLVM_NATIVE_ARCH}Info ) + list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info") + endif() elseif( c STREQUAL "backend" ) # same case as in `native'. elseif( c STREQUAL "engine" ) diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in index 780001a..780a608 100644 --- a/cmake/modules/LLVMConfig.cmake.in +++ b/cmake/modules/LLVMConfig.cmake.in @@ -21,6 +21,12 @@ set(LLVM_TARGETS_WITH_JIT @LLVM_TARGETS_WITH_JIT@) set(TARGET_TRIPLE "@TARGET_TRIPLE@") +set(LLVM_ENABLE_ASSERTIONS @LLVM_ENABLE_ASSERTIONS@) + +set(LLVM_ENABLE_EH @LLVM_ENABLE_EH@) + +set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@) + set(LLVM_ENABLE_TERMINFO @LLVM_ENABLE_TERMINFO@) set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@) @@ -38,6 +44,7 @@ set(LLVM_INCLUDE_DIRS "@LLVM_CONFIG_INCLUDE_DIRS@") set(LLVM_LIBRARY_DIRS "@LLVM_CONFIG_LIBRARY_DIRS@") set(LLVM_DEFINITIONS "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS") set(LLVM_CMAKE_DIR "@LLVM_CONFIG_CMAKE_DIR@") +set(LLVM_TOOLS_BINARY_DIR "@LLVM_CONFIG_TOOLS_BINARY_DIR@") if(NOT TARGET LLVMSupport) include("@LLVM_CONFIG_EXPORTS_FILE@") diff --git a/cmake/modules/LLVMProcessSources.cmake b/cmake/modules/LLVMProcessSources.cmake index 08b9c8e..64ebce8 100644 --- a/cmake/modules/LLVMProcessSources.cmake +++ b/cmake/modules/LLVMProcessSources.cmake @@ -59,12 +59,17 @@ function(llvm_check_source_file_list) file(GLOB globbed *.c *.cpp) foreach(g ${globbed}) get_filename_component(fn ${g} NAME) - list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx) - if( idx LESS 0 ) - list(FIND listed ${fn} idx) + + # Don't reject hidden files. Some editors create backups in the + # same directory as the file. + if (NOT "${fn}" MATCHES "^\\.") + list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx) if( idx LESS 0 ) - message(SEND_ERROR "Found unknown source file ${g} + list(FIND listed ${fn} idx) + if( idx LESS 0 ) + message(SEND_ERROR "Found unknown source file ${g} Please update ${CMAKE_CURRENT_LIST_FILE}\n") + endif() endif() endif() endforeach() diff --git a/cmake/modules/Makefile b/cmake/modules/Makefile index 265c1f8..dd31aa7 100644 --- a/cmake/modules/Makefile +++ b/cmake/modules/Makefile @@ -15,6 +15,37 @@ include $(LEVEL)/Makefile.common PROJ_cmake := $(DESTDIR)$(PROJ_prefix)/share/llvm/cmake +ifeq ($(DISABLE_ASSERTIONS),1) + LLVM_ENABLE_ASSERTIONS := 0 +else + LLVM_ENABLE_ASSERTIONS := 1 +endif + +ifeq ($(REQUIRES_EH),1) + LLVM_ENABLE_EH := 1 +else + LLVM_ENABLE_EH := 0 +endif + +ifeq ($(REQUIRES_RTTI),1) + LLVM_ENABLE_RTTI := 1 +else + LLVM_ENABLE_RTTI := 0 +endif + +# Don't try to run llvm-config during clean because it won't be available +ifneq ($(MAKECMDGOALS),clean) +LLVM_LIBS_TO_EXPORT := $(subst -l,,$(shell $(LLVM_CONFIG) --libs $(LINK_COMPONENTS) || echo Error)) + +ifeq ($(LLVM_LIBS_TO_EXPORT),Error) +$(error llvm-config --libs failed) +endif + +ifndef LLVM_LIBS_TO_EXPORT +$(error LLVM_LIBS_TO_EXPORT cannot be empty) +endif +endif + OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag) @@ -27,11 +58,14 @@ $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag) -e 's/@LLVM_VERSION_PATCH@/'"$(LLVM_VERSION_PATCH)"'/' \ -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \ -e 's/@LLVM_COMMON_DEPENDS@//' \ - -e 's/@LLVM_AVAILABLE_LIBS@/'"$(subst -l,,$(LLVMConfigLibs))"'/' \ + -e 's/@LLVM_AVAILABLE_LIBS@/'"$(LLVM_LIBS_TO_EXPORT)"'/' \ -e 's/@LLVM_ALL_TARGETS@/'"$(ALL_TARGETS)"'/' \ -e 's/@LLVM_TARGETS_TO_BUILD@/'"$(TARGETS_TO_BUILD)"'/' \ -e 's/@LLVM_TARGETS_WITH_JIT@/'"$(TARGETS_WITH_JIT)"'/' \ -e 's/@TARGET_TRIPLE@/'"$(TARGET_TRIPLE)"'/' \ + -e 's/@LLVM_ENABLE_ASSERTIONS@/'"$(LLVM_ENABLE_ASSERTIONS)"'/' \ + -e 's/@LLVM_ENABLE_EH@/'"$(LLVM_ENABLE_EH)"'/' \ + -e 's/@LLVM_ENABLE_RTTI@/'"$(LLVM_ENABLE_RTTI)"'/' \ -e 's/@LLVM_ENABLE_TERMINFO@/'"$(ENABLE_TERMINFO)"'/' \ -e 's/@LLVM_ENABLE_THREADS@/'"$(ENABLE_THREADS)"'/' \ -e 's/@LLVM_ENABLE_ZLIB@/'"$(ENABLE_ZLIB)"'/' \ @@ -42,6 +76,7 @@ $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag) -e 's/@LLVM_CONFIG_INCLUDE_DIRS@/'"$(subst /,\/,$(PROJ_includedir))"'/' \ -e 's/@LLVM_CONFIG_LIBRARY_DIRS@/'"$(subst /,\/,$(PROJ_libdir))"'/' \ -e 's/@LLVM_CONFIG_CMAKE_DIR@/'"$(subst /,\/,$(PROJ_cmake))"'/' \ + -e 's/@LLVM_CONFIG_TOOLS_BINARY_DIR@/'"$(subst /,\/,$(PROJ_bindir))"'/' \ -e 's/@LLVM_CONFIG_EXPORTS_FILE@/$${LLVM_CMAKE_DIR}\/LLVMExports.cmake/' \ -e 's/@all_llvm_lib_deps@//' \ && \ @@ -61,7 +96,7 @@ $(PROJ_OBJ_DIR)/LLVMExports.cmake: $(LLVMBuildCMakeExportsFrag) $(Echo) 'Generating LLVM CMake target exports file' $(Verb) ( \ echo '# LLVM CMake target exports. Do not include directly.' && \ - for lib in $(subst -l,,$(LLVMConfigLibs)); do \ + for lib in $(LLVM_LIBS_TO_EXPORT); do \ echo 'add_library('"$$lib"' STATIC IMPORTED)' && \ echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION "'"$(PROJ_libdir)/lib$$lib.a"'")' ; \ done && \ diff --git a/cmake/modules/TableGen.cmake b/cmake/modules/TableGen.cmake index 34b0343..67031a5 100644 --- a/cmake/modules/TableGen.cmake +++ b/cmake/modules/TableGen.cmake @@ -70,26 +70,6 @@ function(add_public_tablegen_target target) set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${target} PARENT_SCOPE) endfunction() -if(CMAKE_CROSSCOMPILING) - set(CX_NATIVE_TG_DIR "${CMAKE_BINARY_DIR}/native") - - add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR} - COMMAND ${CMAKE_COMMAND} -E make_directory ${CX_NATIVE_TG_DIR} - COMMENT "Creating ${CX_NATIVE_TG_DIR}...") - - add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}/CMakeCache.txt - COMMAND ${CMAKE_COMMAND} -UMAKE_TOOLCHAIN_FILE -DCMAKE_BUILD_TYPE=Release - -DLLVM_BUILD_POLLY=OFF - -G "${CMAKE_GENERATOR}" ${CMAKE_SOURCE_DIR} - WORKING_DIRECTORY ${CX_NATIVE_TG_DIR} - DEPENDS ${CX_NATIVE_TG_DIR} - COMMENT "Configuring native TableGen...") - - add_custom_target(ConfigureNativeTableGen DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt) - - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CX_NATIVE_TG_DIR}) -endif() - macro(add_tablegen target project) set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) @@ -113,16 +93,16 @@ macro(add_tablegen target project) if(CMAKE_CROSSCOMPILING) if( ${${project}_TABLEGEN} STREQUAL "${target}" ) - set(${project}_TABLEGEN_EXE "${CX_NATIVE_TG_DIR}/bin/${target}") + set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/${target}") set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE) add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE} - COMMAND ${CMAKE_BUILD_TOOL} ${target} - DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt - WORKING_DIRECTORY ${CX_NATIVE_TG_DIR} + COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION> + DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt + WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} COMMENT "Building native TableGen...") add_custom_target(${project}NativeTableGen DEPENDS ${${project}_TABLEGEN_EXE}) - add_dependencies(${project}NativeTableGen ConfigureNativeTableGen) + add_dependencies(${project}NativeTableGen ConfigureNativeLLVM) add_dependencies(${target} ${project}NativeTableGen) endif() diff --git a/cmake/platforms/iOS.cmake b/cmake/platforms/iOS.cmake new file mode 100644 index 0000000..4973643 --- /dev/null +++ b/cmake/platforms/iOS.cmake @@ -0,0 +1,47 @@ +# Toolchain config for iOS. +# +# Usage: +# mkdir build; cd build +# cmake ..; make +# mkdir ios; cd ios +# cmake -DLLVM_IOS_TOOLCHAIN_DIR=/path/to/ios/ndk \ +# -DCMAKE_TOOLCHAIN_FILE=../../cmake/platforms/iOS.cmake ../.. +# make <target> + +SET(CMAKE_SYSTEM_NAME Darwin) +SET(CMAKE_SYSTEM_VERSION 13) +SET(CMAKE_CXX_COMPILER_WORKS True) +SET(CMAKE_C_COMPILER_WORKS True) +SET(DARWIN_TARGET_OS_NAME ios) + +IF(NOT DEFINED ENV{SDKROOT}) + MESSAGE(FATAL_ERROR "SDKROOT env var must be set: " $ENV{SDKROOT}) +ENDIF() + +IF(NOT CMAKE_C_COMPILER) + execute_process(COMMAND xcrun -sdk iphoneos -find clang + OUTPUT_VARIABLE CMAKE_C_COMPILER + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Using c compiler ${CMAKE_C_COMPILER}") +ENDIF() + +IF(NOT CMAKE_CXX_COMPILER) + execute_process(COMMAND xcrun -sdk iphoneos -find clang++ + OUTPUT_VARIABLE CMAKE_CXX_COMPILER + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Using c compiler ${CMAKE_CXX_COMPILER}") +ENDIF() + +IF (NOT DEFINED IOS_MIN_TARGET) +execute_process(COMMAND xcodebuild -sdk iphoneos -version SDKVersion + OUTPUT_VARIABLE IOS_MIN_TARGET + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +ENDIF() + +SET(IOS_COMMON_FLAGS "-isysroot $ENV{SDKROOT} -mios-version-min=${IOS_MIN_TARGET}") +SET(CMAKE_C_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cflags" FORCE) +SET(CMAKE_CXX_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cxxflags" FORCE) +SET(CMAKE_LINK_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_linkflags" FORCE) |