From cec426a0781c0cca148cedf46117fd90277303d0 Mon Sep 17 00:00:00 2001 From: Daniel Krebs Date: Tue, 11 Apr 2017 13:21:39 +0200 Subject: [PATCH] cmake: add intermediate target hermit-bootstrap to build with bootstrap compiler --- .gitignore | 1 + CMakeLists.txt | 40 +++++++++++++++---- .../HermitCore-Toolchain-x86-bootstrap.cmake | 4 +- cmake/HermitCore.cmake | 6 ++- include/hermit/CMakeLists.txt | 7 ++++ 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index fabe22240..841e46c24 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ **/build/* .idea/* qemu-vlan0.pcap +cmake/cmake-3.7.2-Linux-x86_64/* diff --git a/CMakeLists.txt b/CMakeLists.txt index e69e14459..970a1c753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,21 +58,23 @@ list(APPEND KERNEL_OBJECTS $) # finally build libhermit.a -add_library(hermit STATIC ${KERNEL_OBJECTS}) +add_library(hermit-bootstrap STATIC ${KERNEL_OBJECTS}) +set_target_properties(hermit-bootstrap PROPERTIES + ARCHIVE_OUTPUT_NAME hermit) # after compiling ASM sources, we need to post-process them. Adding this # dependency makes sure that this is done before hermit is linked -add_dependencies(hermit ${X86_KERNEL_TARGET}) +add_dependencies(hermit-bootstrap ${X86_KERNEL_TARGET}) add_custom_command( TARGET - hermit POST_BUILD + hermit-bootstrap POST_BUILD # rename sections in final library COMMAND ${CMAKE_OBJCOPY} --rename-section .bss=.kbss --rename-section .text=.ktext --rename-section .data=.kdata - $ + $ # copy libhermit.a into local prefix directory so that all subsequent # targets can link against the freshly built version (as opposed to @@ -81,7 +83,7 @@ add_custom_command( ${CMAKE_COMMAND} -E make_directory ${LOCAL_PREFIX_ARCH_LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_if_different - $ + $ ${LOCAL_PREFIX_ARCH_LIB_DIR}/ # and also copy headers into local prefix @@ -96,11 +98,33 @@ add_custom_command( ${CMAKE_BINARY_DIR}/include/hermit/*.asm ${LOCAL_PREFIX_ARCH_INCLUDE_DIR}/hermit/) + # deploy libhermit.a and headers for package creation -install(TARGETS hermit - DESTINATION ${TARGET_ARCH}/lib) +install(TARGETS hermit-bootstrap + DESTINATION ${TARGET_ARCH}/lib + COMPONENT bootstrap) + install(DIRECTORY include/hermit - DESTINATION ${TARGET_ARCH}/include/) + DESTINATION ${TARGET_ARCH}/include/ + COMPONENT bootstrap + FILES_MATCHING + PATTERN *.h) + +# provide custom target to only install libhermit without its runtimes which is +# needed during the compilation of the cross toolchain +add_custom_target(hermit-bootstrap-install + DEPENDS + hermit-bootstrap + COMMAND + ${CMAKE_COMMAND} + -DCMAKE_INSTALL_COMPONENT=bootstrap + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -P cmake_install.cmake) + +# The target 'hermit' includes the HermitCore kernel and several runtimes. +# Applications should depend on this target if they link against HermitCore. +add_custom_target(hermit + DEPENDS hermit-bootstrap) ### External projects diff --git a/cmake/HermitCore-Toolchain-x86-bootstrap.cmake b/cmake/HermitCore-Toolchain-x86-bootstrap.cmake index aa83a3900..4471196e2 100644 --- a/cmake/HermitCore-Toolchain-x86-bootstrap.cmake +++ b/cmake/HermitCore-Toolchain-x86-bootstrap.cmake @@ -4,8 +4,6 @@ include_guard() set(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "") set(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "") -# unset unneeded compilers +# bootstrap toolchain cannot compile neither Go nor Fortran unset(CMAKE_Go_COMPILER) unset(CMAKE_Fortran_COMPILER) - -set(BOOTSTRAP true) diff --git a/cmake/HermitCore.cmake b/cmake/HermitCore.cmake index e5134f44b..4d6ac9d00 100644 --- a/cmake/HermitCore.cmake +++ b/cmake/HermitCore.cmake @@ -27,7 +27,11 @@ endif() # use default toolchain if not specified by user if(NOT CMAKE_TOOLCHAIN_FILE) - set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/HermitCore-Toolchain-${HERMIT_ARCH}.cmake) + if(BOOTSTRAP) + # use bootstrap toolchain if requested + set(_BOOTSTRAP_ARCH_SUFFIX -bootstrap) + endif() + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/HermitCore-Toolchain-${HERMIT_ARCH}${_BOOTSTRAP_ARCH_SUFFIX}.cmake) endif() # NASM detection will change binary format depending on host system, but diff --git a/include/hermit/CMakeLists.txt b/include/hermit/CMakeLists.txt index 921ca40f1..5f4dee9b4 100644 --- a/include/hermit/CMakeLists.txt +++ b/include/hermit/CMakeLists.txt @@ -6,3 +6,10 @@ configure_file(config.asm.in config.asm) # Show include files in IDE file(GLOB_RECURSE HERMIT_INCLUDES "*") add_custom_target(hermit_includes_ide SOURCES ${HERMIT_INCLUDES}) + +# install generated config files when building libhermit for bootstrapping +install(FILES + ${GENERATED_CONFIG_DIR}/hermit/config.h + ${GENERATED_CONFIG_DIR}/hermit/config.asm + DESTINATION ${TARGET_ARCH}/include/hermit/ + COMPONENT bootstrap)