diff --git a/cmake/ExternalProjectGem5Specific.cmake b/cmake/ExternalProjectGem5Specific.cmake new file mode 100644 index 00000000..f08a0c8b --- /dev/null +++ b/cmake/ExternalProjectGem5Specific.cmake @@ -0,0 +1,1181 @@ +# - Create custom targets to build projects in external trees +# The 'ExternalProject_Add2_Gem5Specific' function creates a custom target to drive +# download, update/patch, configure, build, install and test steps of an +# external project: +# ExternalProject_Add2_Gem5Specific( # Name for custom target +# [DEPENDS projects...] # Targets on which the project depends +# [PREFIX dir] # Root dir for entire project +# [LIST_SEPARATOR sep] # Sep to be replaced by ; in cmd lines +# [TMP_DIR dir] # Directory to store temporary files +# [STAMP_DIR dir] # Directory to store step timestamps +# #--Download step-------------- +# [DOWNLOAD_DIR dir] # Directory to store downloaded files +# [DOWNLOAD_COMMAND cmd...] # Command to download source tree +# [CVS_REPOSITORY cvsroot] # CVSROOT of CVS repository +# [CVS_MODULE mod] # Module to checkout from CVS repo +# [CVS_TAG tag] # Tag to checkout from CVS repo +# [SVN_REPOSITORY url] # URL of Subversion repo +# [SVN_REVISION rev] # Revision to checkout from Subversion repo +# [SVN_USERNAME john ] # Username for Subversion checkout and update +# [SVN_PASSWORD doe ] # Password for Subversion checkout and update +# [GIT_REPOSITORY url] # URL of git repo +# [GIT_TAG tag] # Git branch name, commit id or tag +# [URL /.../src.tgz] # Full path or URL of source +# [URL_MD5 md5] # MD5 checksum of file at URL +# [TIMEOUT seconds] # Time allowed for file download operations +# #--Update/Patch step---------- +# [UPDATE_COMMAND cmd...] # Source work-tree update command +# [PATCH_COMMAND cmd...] # Command to patch downloaded source +# #--Configure step------------- +# [SOURCE_DIR dir] # Source dir to be used for build +# [CONFIGURE_COMMAND cmd...] # Build tree configuration command +# [CMAKE_COMMAND /.../cmake] # Specify alternative cmake executable +# [CMAKE_GENERATOR gen] # Specify generator for native build +# [CMAKE_ARGS args...] # Arguments to CMake command line +# #--Build step----------------- +# [BINARY_DIR dir] # Specify build dir location +# [BUILD_COMMAND cmd...] # Command to drive the native build +# [BUILD_IN_SOURCE 1] # Use source dir for build dir +# #--Install step--------------- +# [INSTALL_DIR dir] # Installation prefix +# [INSTALL_COMMAND cmd...] # Command to drive install after build +# #--Test step--------------- +# [TEST_BEFORE_INSTALL 1] # Add test step executed before install step +# [TEST_AFTER_INSTALL 1] # Add test step executed after install step +# [TEST_COMMAND cmd...] # Command to drive test +# ) +# The *_DIR options specify directories for the project, with default +# directories computed as follows. +# If the PREFIX option is given to ExternalProject_Add2_Gem5Specific() or the EP_PREFIX +# directory property is set, then an external project is built and installed +# under the specified prefix: +# TMP_DIR = /tmp +# STAMP_DIR = /src/-stamp +# DOWNLOAD_DIR = /src +# SOURCE_DIR = /src/ +# BINARY_DIR = /src/-build +# INSTALL_DIR = +# Otherwise, if the EP_BASE directory property is set then components +# of an external project are stored under the specified base: +# TMP_DIR = /tmp/ +# STAMP_DIR = /Stamp/ +# DOWNLOAD_DIR = /Download/ +# SOURCE_DIR = /Source/ +# BINARY_DIR = /Build/ +# INSTALL_DIR = /Install/ +# If no PREFIX, EP_PREFIX, or EP_BASE is specified then the default +# is to set PREFIX to "-prefix". +# Relative paths are interpreted with respect to the build directory +# corresponding to the source directory in which ExternalProject_Add2_Gem5Specific is +# invoked. +# +# If SOURCE_DIR is explicitly set to an existing directory the project +# will be built from it. +# Otherwise a download step must be specified using one of the +# DOWNLOAD_COMMAND, CVS_*, SVN_*, or URL options. +# The URL option may refer locally to a directory or source tarball, +# or refer to a remote tarball (e.g. http://.../src.tgz). +# +# The 'ExternalProject_Add2_Gem5Specific_Step' function adds a custom step to an external +# project: +# ExternalProject_Add2_Gem5Specific_Step( # Names of project and custom step +# [COMMAND cmd...] # Command line invoked by this step +# [COMMENT "text..."] # Text printed when step executes +# [DEPENDEES steps...] # Steps on which this step depends +# [DEPENDERS steps...] # Steps that depend on this step +# [DEPENDS files...] # Files on which this step depends +# [ALWAYS 1] # No stamp file, step always runs +# [WORKING_DIRECTORY dir] # Working directory for command +# ) +# The command line, comment, and working directory of every standard +# and custom step is processed to replace tokens +# , +# , +# , +# and +# with corresponding property values. +# +# The 'ExternalProject_Get_Property' function retrieves external project +# target properties: +# ExternalProject_Get_Property( [prop1 [prop2 [...]]]) +# It stores property values in variables of the same name. +# Property names correspond to the keyword argument names of +# 'ExternalProject_Add2_Gem5Specific'. + +#============================================================================= +# Copyright 2008-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +# Pre-compute a regex to match documented keywords for each command. +file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines LIMIT_COUNT 103 + REGEX "^# ( \\[[A-Z0-9_]+ [^]]*\\] +#.*$|[A-Za-z0-9_]+\\()") +foreach(line IN LISTS lines) + if("${line}" MATCHES "^# [A-Za-z0-9_]+\\(") + if(_ep_func) + set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$") + endif() + string(REGEX REPLACE "^# ([A-Za-z0-9_]+)\\(.*" "\\1" _ep_func "${line}") + #message("function [${_ep_func}]") + set(_ep_keywords_${_ep_func} "^(") + set(_ep_keyword_sep) + else() + string(REGEX REPLACE "^# \\[([A-Z0-9_]+) .*" "\\1" _ep_key "${line}") + #message(" keyword [${_ep_key}]") + set(_ep_keywords_${_ep_func} + "${_ep_keywords_${_ep_func}}${_ep_keyword_sep}${_ep_key}") + set(_ep_keyword_sep "|") + endif() +endforeach() +if(_ep_func) + set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$") +endif() + + +function(_ep_parse_arguments f name ns args) + # Transfer the arguments to this function into target properties for the + # new custom target we just added so that we can set up all the build steps + # correctly based on target properties. + # + # We loop through ARGN and consider the namespace starting with an + # upper-case letter followed by at least two more upper-case letters + # or underscores to be keywords. + set(key) + + foreach(arg IN LISTS args) + set(is_value 1) + + if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND + NOT ((arg STREQUAL "${key}") AND (key STREQUAL "COMMAND")) AND + NOT arg MATCHES "^(TRUE|FALSE)$") + if(_ep_keywords_${f} AND arg MATCHES "${_ep_keywords_${f}}") + set(is_value 0) + else() + if(NOT (key STREQUAL "COMMAND") + AND NOT (key STREQUAL "CVS_MODULE") + AND NOT (key STREQUAL "DEPENDS") + AND NOT (key STREQUAL "DOWNLOAD_COMMAND") + ) + message(AUTHOR_WARNING "unknown ${f} keyword: ${arg}") + endif() + endif() + endif() + + if(is_value) + if(key) + # Value + if(NOT arg STREQUAL "") + set_property(TARGET ${name} APPEND PROPERTY ${ns}${key} "${arg}") + else() + get_property(have_key TARGET ${name} PROPERTY ${ns}${key} SET) + if(have_key) + get_property(value TARGET ${name} PROPERTY ${ns}${key}) + set_property(TARGET ${name} PROPERTY ${ns}${key} "${value};${arg}") + else() + set_property(TARGET ${name} PROPERTY ${ns}${key} "${arg}") + endif() + endif() + else() + # Missing Keyword + message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}") + endif() + else() + set(key "${arg}") + endif() + endforeach() +endfunction(_ep_parse_arguments) + + +define_property(DIRECTORY PROPERTY "EP_BASE" INHERITED + BRIEF_DOCS "Base directory for External Project storage." + FULL_DOCS + "See documentation of the ExternalProject_Add2_Gem5Specific() function in the " + "ExternalProject module." + ) + +define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED + BRIEF_DOCS "Top prefix for External Project storage." + FULL_DOCS + "See documentation of the ExternalProject_Add2_Gem5Specific() function in the " + "ExternalProject module." + ) + + +function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag src_name work_dir) + file(WRITE ${script_filename} +"if(\"${git_tag}\" STREQUAL \"\") + message(FATAL_ERROR \"Tag for git checkout should not be empty.\") +endif() + +execute_process( + COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\" + RESULT_VARIABLE error_code + ) +if(error_code) + message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\") +endif() + +execute_process( + COMMAND \"${git_EXECUTABLE}\" clone \"${git_repository}\" \"${src_name}\" + WORKING_DIRECTORY \"${work_dir}\" + RESULT_VARIABLE error_code + ) +if(error_code) + message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\") +endif() + +execute_process( + COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag} + WORKING_DIRECTORY \"${work_dir}/${src_name}\" + RESULT_VARIABLE error_code + ) +if(error_code) + message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\") +endif() + +execute_process( + COMMAND \"${git_EXECUTABLE}\" submodule init + WORKING_DIRECTORY \"${work_dir}/${src_name}\" + RESULT_VARIABLE error_code + ) +if(error_code) + message(FATAL_ERROR \"Failed to init submodules in: '${work_dir}/${src_name}'\") +endif() + +execute_process( + COMMAND \"${git_EXECUTABLE}\" submodule update --recursive + WORKING_DIRECTORY \"${work_dir}/${src_name}\" + RESULT_VARIABLE error_code + ) +if(error_code) + message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\") +endif() + +" +) + +endfunction(_ep_write_gitclone_script) + + +function(_ep_write_downloadfile_script script_filename remote local timeout md5) + if(timeout) + set(timeout_args TIMEOUT ${timeout}) + set(timeout_msg "${timeout} seconds") + else() + set(timeout_args "# no TIMEOUT") + set(timeout_msg "none") + endif() + + if(md5) + set(md5_args EXPECTED_MD5 ${md5}) + else() + set(md5_args "# no EXPECTED_MD5") + endif() + + file(WRITE ${script_filename} +"message(STATUS \"downloading... + src='${remote}' + dst='${local}' + timeout='${timeout_msg}'\") + +file(DOWNLOAD + \"${remote}\" + \"${local}\" + SHOW_PROGRESS + ${md5_args} + ${timeout_args} + STATUS status + LOG log) + +list(GET status 0 status_code) +list(GET status 1 status_string) + +if(NOT status_code EQUAL 0) + message(FATAL_ERROR \"error: downloading '${remote}' failed + status_code: \${status_code} + status_string: \${status_string} + log: \${log} +\") +endif() + +message(STATUS \"downloading... done\") +" +) + +endfunction(_ep_write_downloadfile_script) + + +function(_ep_write_verifyfile_script script_filename local md5) + file(WRITE ${script_filename} +"message(STATUS \"verifying file... + file='${local}'\") + +set(verified 0) + +# If an expected md5 checksum exists, compare against it: +# +if(NOT \"${md5}\" STREQUAL \"\") + execute_process(COMMAND \${CMAKE_COMMAND} -E md5sum \"${local}\" + OUTPUT_VARIABLE ov + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE rv) + + if(NOT rv EQUAL 0) + message(FATAL_ERROR \"error: computing md5sum of '${local}' failed\") + endif() + + string(REGEX MATCH \"^([0-9A-Fa-f]+)\" md5_actual \"\${ov}\") + + string(TOLOWER \"\${md5_actual}\" md5_actual) + string(TOLOWER \"${md5}\" md5) + + if(NOT \"\${md5}\" STREQUAL \"\${md5_actual}\") + message(FATAL_ERROR \"error: md5sum of '${local}' does not match expected value + md5_expected: \${md5} + md5_actual: \${md5_actual} +\") + endif() + + set(verified 1) +endif() + +if(verified) + message(STATUS \"verifying file... done\") +else() + message(STATUS \"verifying file... warning: did not verify file - no URL_MD5 checksum argument? corrupt file?\") +endif() +" +) + +endfunction(_ep_write_verifyfile_script) + + +function(_ep_write_extractfile_script script_filename name filename directory) + set(args "") + + if(filename MATCHES "(\\.bz2|\\.tar\\.gz|\\.tgz|\\.zip)$") + set(args xfz) + endif() + + if(filename MATCHES "\\.tar$") + set(args xf) + endif() + + if(args STREQUAL "") + message(SEND_ERROR "error: do not know how to extract '${filename}' -- known types are .bz2, .tar, .tar.gz, .tgz and .zip") + return() + endif() + + file(WRITE ${script_filename} +"# Make file names absolute: +# +get_filename_component(filename \"${filename}\" ABSOLUTE) +get_filename_component(directory \"${directory}\" ABSOLUTE) + +message(STATUS \"extracting... + src='\${filename}' + dst='\${directory}'\") + +if(NOT EXISTS \"\${filename}\") + message(FATAL_ERROR \"error: file to extract does not exist: '\${filename}'\") +endif() + +# Prepare a space for extracting: +# +set(i 1234) +while(EXISTS \"\${directory}/../ex-${name}\${i}\") + math(EXPR i \"\${i} + 1\") +endwhile() +set(ut_dir \"\${directory}/../ex-${name}\${i}\") +file(MAKE_DIRECTORY \"\${ut_dir}\") + +# Extract it: +# +message(STATUS \"extracting... [tar ${args}]\") +execute_process(COMMAND \${CMAKE_COMMAND} -E tar ${args} \${filename} + WORKING_DIRECTORY \${ut_dir} + RESULT_VARIABLE rv) + +if(NOT rv EQUAL 0) + message(STATUS \"extracting... [error clean up]\") + file(REMOVE_RECURSE \"\${ut_dir}\") + message(FATAL_ERROR \"error: extract of '\${filename}' failed\") +endif() + +# Analyze what came out of the tar file: +# +message(STATUS \"extracting... [analysis]\") +file(GLOB contents \"\${ut_dir}/*\") +list(LENGTH contents n) +if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\") + set(contents \"\${ut_dir}\") +endif() + +# Move \"the one\" directory to the final directory: +# +message(STATUS \"extracting... [rename]\") +file(REMOVE_RECURSE \${directory}) +get_filename_component(contents \${contents} ABSOLUTE) +file(RENAME \${contents} \${directory}) + +# Clean up: +# +message(STATUS \"extracting... [clean up]\") +file(REMOVE_RECURSE \"\${ut_dir}\") + +message(STATUS \"extracting... done\") +" +) + +endfunction(_ep_write_extractfile_script) + + +function(_ep_set_directories name) + get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX) + if(NOT prefix) + get_property(prefix DIRECTORY PROPERTY EP_PREFIX) + if(NOT prefix) + get_property(base DIRECTORY PROPERTY EP_BASE) + if(NOT base) + set(prefix "${name}-prefix") + endif() + endif() + endif() + if(prefix) + set(tmp_default "${prefix}/tmp") + set(download_default "${prefix}/src") + set(source_default "${prefix}/src/${name}") + set(binary_default "${prefix}/src/${name}-build") + set(stamp_default "${prefix}/src/${name}-stamp") + set(install_default "${prefix}") + else() # assert(base) + set(tmp_default "${base}/tmp/${name}") + set(download_default "${base}/Download/${name}") + set(source_default "${base}/Source/${name}") + set(binary_default "${base}/Build/${name}") + set(stamp_default "${base}/Stamp/${name}") + set(install_default "${base}/Install/${name}") + endif() + get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE) + if(build_in_source) + get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET) + if(have_binary_dir) + message(FATAL_ERROR + "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!") + endif() + endif() + set(top "${CMAKE_CURRENT_BINARY_DIR}") + set(places stamp download source binary install tmp) + foreach(var ${places}) + string(TOUPPER "${var}" VAR) + get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR) + if(NOT ${var}_dir) + set(${var}_dir "${${var}_default}") + endif() + if(NOT IS_ABSOLUTE "${${var}_dir}") + get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE) + endif() + set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}") + endforeach() + if(build_in_source) + get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR) + set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}") + endif() + + # Make the directories at CMake configure time *and* add a custom command + # to make them at build time. They need to exist at makefile generation + # time for Borland make and wmake so that CMake may generate makefiles + # with "cd C:\short\paths\with\no\spaces" commands in them. + # + # Additionally, the add_custom_command is still used in case somebody + # removes one of the necessary directories and tries to rebuild without + # re-running cmake. + foreach(var ${places}) + string(TOUPPER "${var}" VAR) + get_property(dir TARGET ${name} PROPERTY _EP_${VAR}_DIR) + file(MAKE_DIRECTORY "${dir}") + if(NOT EXISTS "${dir}") + message(FATAL_ERROR "dir '${dir}' does not exist after file(MAKE_DIRECTORY)") + endif() + endforeach() +endfunction(_ep_set_directories) + + +function(ExternalProject_Get_Property name) + foreach(var ${ARGN}) + string(TOUPPER "${var}" VAR) + get_property(${var} TARGET ${name} PROPERTY _EP_${VAR}) + if(NOT ${var}) + message(FATAL_ERROR "External project \"${name}\" has no ${var}") + endif() + set(${var} "${${var}}" PARENT_SCOPE) + endforeach() +endfunction(ExternalProject_Get_Property) + + +function(_ep_get_configure_command_id name cfg_cmd_id_var) + get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND) + + if(cmd STREQUAL "") + # Explicit empty string means no configure step for this project + set(${cfg_cmd_id_var} "none" PARENT_SCOPE) + else() + if(NOT cmd) + # Default is "use cmake": + set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE) + else() + # Otherwise we have to analyze the value: + if(cmd MATCHES "^[^;]*/configure") + set(${cfg_cmd_id_var} "configure" PARENT_SCOPE) + elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];") + set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE) + elseif(cmd MATCHES "config") + set(${cfg_cmd_id_var} "configure" PARENT_SCOPE) + else() + set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE) + endif() + endif() + endif() +endfunction(_ep_get_configure_command_id) + + +function(_ep_get_build_command name step cmd_var) + set(cmd "${${cmd_var}}") + if(NOT cmd) + set(args) + _ep_get_configure_command_id(${name} cfg_cmd_id) + if(cfg_cmd_id STREQUAL "cmake") + # CMake project. Select build command based on generator. + get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR) + if("${cmake_generator}" MATCHES "Make" AND + "${cmake_generator}" STREQUAL "${CMAKE_GENERATOR}") + # The project uses the same Makefile generator. Use recursive make. + set(cmd "$(MAKE)") + if(step STREQUAL "INSTALL") + set(args install) + endif() + if(step STREQUAL "TEST") + set(args test) + endif() + else() + # Drive the project with "cmake --build". + get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND) + if(cmake_command) + set(cmd "${cmake_command}") + else() + set(cmd "${CMAKE_COMMAND}") + endif() + set(args --build ${binary_dir} --config ${CMAKE_CFG_INTDIR}) + if(step STREQUAL "INSTALL") + list(APPEND args --target install) + endif() + # But for "TEST" drive the project with corresponding "ctest". + if(step STREQUAL "TEST") + string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}") + set(args "") + endif() + endif() + else() # if(cfg_cmd_id STREQUAL "configure") + # Non-CMake project. Guess "make" and "make install" and "make test". + set(cmd "make") + if(step STREQUAL "INSTALL") + set(args install) + endif() + if(step STREQUAL "TEST") + set(args test) + endif() + endif() + + # Use user-specified arguments instead of default arguments, if any. + get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET) + if(have_args) + get_target_property(args ${name} _EP_${step}_ARGS) + endif() + + list(APPEND cmd ${args}) + endif() + + set(${cmd_var} "${cmd}" PARENT_SCOPE) +endfunction(_ep_get_build_command) + + +# This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced +# makefiles with "/./" in paths for custom command dependencies. Which +# resulted in problems with parallel make -j invocations. +# +# This function was added so that the suffix (search below for ${cfgdir}) is +# only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to +# be "." (multi-configuration build systems like Visual Studio and Xcode...) +# +function(_ep_get_configuration_subdir_suffix suffix_var) + set(suffix "") + if(CMAKE_CONFIGURATION_TYPES) + set(suffix "/${CMAKE_CFG_INTDIR}") + endif() + set(${suffix_var} "${suffix}" PARENT_SCOPE) +endfunction(_ep_get_configuration_subdir_suffix) + + +function(ExternalProject_Add2_Gem5Specific_Step name step) + set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles) + ExternalProject_Get_Property(${name} stamp_dir) + + _ep_get_configuration_subdir_suffix(cfgdir) + + add_custom_command(APPEND + OUTPUT ${cmf_dir}${cfgdir}/${name}-complete + DEPENDS ${stamp_dir}${cfgdir}/${name}-${step} + ) + _ep_parse_arguments(ExternalProject_Add2_Gem5Specific_Step + ${name} _EP_${step}_ "${ARGN}") + + # Steps depending on this step. + get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS) + foreach(depender IN LISTS dependers) + add_custom_command(APPEND + OUTPUT ${stamp_dir}${cfgdir}/${name}-${depender} + DEPENDS ${stamp_dir}${cfgdir}/${name}-${step} + ) + endforeach() + + # Dependencies on files. + get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS) + + # Dependencies on steps. + get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES) + foreach(dependee IN LISTS dependees) + list(APPEND depends ${stamp_dir}${cfgdir}/${name}-${dependee}) + endforeach() + + # The command to run. + get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND) + if(command) + set(comment "Performing ${step} step for '${name}'") + else() + set(comment "No ${step} step for '${name}'") + endif() + get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY) + + # Replace list separators. + get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR) + if(sep AND command) + string(REPLACE "${sep}" "\\;" command "${command}") + endif() + + # Replace location tags. + foreach(var comment command work_dir) + if(${var}) + foreach(dir SOURCE_DIR BINARY_DIR INSTALL_DIR TMP_DIR) + get_property(val TARGET ${name} PROPERTY _EP_${dir}) + string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}") + endforeach() + endif() + endforeach() + + # Custom comment? + get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET) + if(comment_set) + get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT) + endif() + + # Run every time? + get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS) + if(always) + set_property(SOURCE ${stamp_dir}${cfgdir}/${name}-${step} PROPERTY SYMBOLIC 1) + set(touch) + else() + set(touch ${CMAKE_COMMAND} -E touch ${stamp_dir}${cfgdir}/${name}-${step}) + endif() + + add_custom_command( + OUTPUT ${stamp_dir}${cfgdir}/${name}-${step} + COMMENT ${comment} + COMMAND ${command} + COMMAND ${touch} + DEPENDS ${depends} + WORKING_DIRECTORY ${work_dir} + VERBATIM + ) +endfunction(ExternalProject_Add2_Gem5Specific_Step) + + +function(_ep_add_mkdir_command name) + ExternalProject_Get_Property(${name} + source_dir binary_dir install_dir stamp_dir download_dir tmp_dir) + + _ep_get_configuration_subdir_suffix(cfgdir) + + ExternalProject_Add2_Gem5Specific_Step(${name} mkdir + COMMENT "Creating directories for '${name}'" + COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir} + COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir} + COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir} + COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir} + COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir} + COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir} + ) +endfunction(_ep_add_mkdir_command) + + +function(_ep_get_git_version git_EXECUTABLE git_version_var) + if(git_EXECUTABLE) + execute_process( + COMMAND "${git_EXECUTABLE}" --version + OUTPUT_VARIABLE ov + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX REPLACE "^git version (.+)$" "\\1" version "${ov}") + set(${git_version_var} "${version}" PARENT_SCOPE) + endif() +endfunction() + + +function(_ep_is_dir_empty dir empty_var) + file(GLOB gr "${dir}/*") + if("${gr}" STREQUAL "") + set(${empty_var} 1 PARENT_SCOPE) + else() + set(${empty_var} 0 PARENT_SCOPE) + endif() +endfunction() + + +function(_ep_add_download_command name) + ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir) + + get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET) + get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND) + get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY) + get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY) + get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY) + get_property(url TARGET ${name} PROPERTY _EP_URL) + + # TODO: Perhaps file:// should be copied to download dir before extraction. + string(REGEX REPLACE "^file://" "" url "${url}") + + set(depends) + set(comment) + set(work_dir) + + if(cmd_set) + set(work_dir ${download_dir}) + elseif(cvs_repository) + find_package(CVS) + if(NOT CVS_EXECUTABLE) + message(FATAL_ERROR "error: could not find cvs for checkout of ${name}") + endif() + + get_target_property(cvs_module ${name} _EP_CVS_MODULE) + if(NOT cvs_module) + message(FATAL_ERROR "error: no CVS_MODULE") + endif() + + get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG) + + set(repository ${cvs_repository}) + set(module ${cvs_module}) + set(tag ${cvs_tag}) + configure_file( + "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in" + "${stamp_dir}/${name}-cvsinfo.txt" + @ONLY + ) + + get_filename_component(src_name "${source_dir}" NAME) + get_filename_component(work_dir "${source_dir}" PATH) + set(comment "Performing download step (CVS checkout) for '${name}'") + set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module}) + list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt) + elseif(svn_repository) + find_package(Subversion) + if(NOT Subversion_SVN_EXECUTABLE) + message(FATAL_ERROR "error: could not find svn for checkout of ${name}") + endif() + + get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION) + get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME) + get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD) + + set(repository "${svn_repository} user=${svn_username} password=${svn_password}") + set(module) + set(tag ${svn_revision}) + configure_file( + "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in" + "${stamp_dir}/${name}-svninfo.txt" + @ONLY + ) + + get_filename_component(src_name "${source_dir}" NAME) + get_filename_component(work_dir "${source_dir}" PATH) + set(comment "Performing download step (SVN checkout) for '${name}'") + set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision} + --username=${svn_username} --password=${svn_password} ${src_name}) + list(APPEND depends ${stamp_dir}/${name}-svninfo.txt) + elseif(git_repository) + find_package(Git) + if(NOT GIT_EXECUTABLE) + message(FATAL_ERROR "error: could not find git for clone of ${name}") + endif() + + # The git submodule update '--recursive' flag requires git >= v1.6.5 + # + _ep_get_git_version("${GIT_EXECUTABLE}" git_version) + if(git_version VERSION_LESS 1.6.5) + message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': git_version='${git_version}'") + endif() + + get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG) + if(NOT git_tag) + set(git_tag "master") + endif() + + set(repository ${git_repository}) + set(module) + set(tag ${git_tag}) + configure_file( + "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in" + "${stamp_dir}/${name}-gitinfo.txt" + @ONLY + ) + + get_filename_component(src_name "${source_dir}" NAME) + get_filename_component(work_dir "${source_dir}" PATH) + + # Since git clone doesn't succeed if the non-empty source_dir exists, + # create a cmake script to invoke as download command. + # The script will delete the source directory and then call git clone. + # + _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir} + ${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${src_name} ${work_dir} + ) + set(comment "Performing download step (git clone) for '${name}'") + set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake) + list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt) + elseif(url) + get_filename_component(work_dir "${source_dir}" PATH) + get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5) + set(repository "external project URL") + set(module "${url}") + set(tag "${md5}") + configure_file( + "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in" + "${stamp_dir}/${name}-urlinfo.txt" + @ONLY + ) + list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt) + if(IS_DIRECTORY "${url}") + get_filename_component(abs_dir "${url}" ABSOLUTE) + set(comment "Performing download step (DIR copy) for '${name}'") + set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir} + COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir}) + else() + if("${url}" MATCHES "^[a-z]+://") + # TODO: Should download and extraction be different steps? + string(REGEX MATCH "[^/]*$" fname "${url}") + if(NOT "${fname}" MATCHES "\\.(bz2|tar|tgz|tar\\.gz|zip)$") + message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}") + endif() + set(file ${download_dir}/${fname}) + get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT) + _ep_write_downloadfile_script("${stamp_dir}/download-${name}.cmake" "${url}" "${file}" "${timeout}" "${md5}") + set(cmd ${CMAKE_COMMAND} -P ${stamp_dir}/download-${name}.cmake + COMMAND) + set(comment "Performing download step (download, verify and extract) for '${name}'") + else() + set(file "${url}") + set(comment "Performing download step (verify and extract) for '${name}'") + endif() + _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${md5}") + list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake) + _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}") + list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake) + endif() + else() + _ep_is_dir_empty("${source_dir}" empty) + if(${empty}) + message(SEND_ERROR "error: no download info for '${name}' -- please specify existing/non-empty SOURCE_DIR or one of URL, CVS_REPOSITORY and CVS_MODULE, SVN_REPOSITORY, GIT_REPOSITORY or DOWNLOAD_COMMAND") + endif() + endif() + + ExternalProject_Add2_Gem5Specific_Step(${name} download + COMMENT ${comment} + COMMAND ${cmd} + WORKING_DIRECTORY ${work_dir} + DEPENDS ${depends} + DEPENDEES mkdir + ) +endfunction(_ep_add_download_command) + + +function(_ep_add_update_command name) + ExternalProject_Get_Property(${name} source_dir) + + get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET) + get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND) + get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY) + get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY) + get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY) + + set(work_dir) + set(comment) + set(always) + + if(cmd_set) + set(work_dir ${source_dir}) + elseif(cvs_repository) + if(NOT CVS_EXECUTABLE) + message(FATAL_ERROR "error: could not find cvs for update of ${name}") + endif() + set(work_dir ${source_dir}) + set(comment "Performing update step (CVS update) for '${name}'") + get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG) + set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag}) + set(always 1) + elseif(svn_repository) + if(NOT Subversion_SVN_EXECUTABLE) + message(FATAL_ERROR "error: could not find svn for update of ${name}") + endif() + set(work_dir ${source_dir}) + set(comment "Performing update step (SVN update) for '${name}'") + get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION) + get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME) + get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD) + set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision} + --username=${svn_username} --password=${svn_password}) + set(always 1) + elseif(git_repository) + if(NOT GIT_EXECUTABLE) + message(FATAL_ERROR "error: could not find git for fetch of ${name}") + endif() + set(work_dir ${source_dir}) + set(comment "Performing update step (git fetch) for '${name}'") + get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG) + if(NOT git_tag) + set(git_tag "master") + endif() + set(cmd ${GIT_EXECUTABLE} fetch + COMMAND ${GIT_EXECUTABLE} checkout ${git_tag} + COMMAND ${GIT_EXECUTABLE} submodule update --recursive + ) + set(always 1) + endif() + + ExternalProject_Add2_Gem5Specific_Step(${name} update + COMMENT ${comment} + COMMAND ${cmd} + ALWAYS ${always} + WORKING_DIRECTORY ${work_dir} + DEPENDEES download + ) +endfunction(_ep_add_update_command) + + +function(_ep_add_patch_command name) + ExternalProject_Get_Property(${name} source_dir) + + get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET) + get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND) + + set(work_dir) + + if(cmd_set) + set(work_dir ${source_dir}) + endif() + + ExternalProject_Add2_Gem5Specific_Step(${name} patch + COMMAND ${cmd} + WORKING_DIRECTORY ${work_dir} + DEPENDEES download + ) +endfunction(_ep_add_patch_command) + + +# TODO: Make sure external projects use the proper compiler +function(_ep_add_configure_command name) + ExternalProject_Get_Property(${name} source_dir binary_dir tmp_dir) + + _ep_get_configuration_subdir_suffix(cfgdir) + + # Depend on other external projects (file-level). + set(file_deps) + get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS) + foreach(dep IN LISTS deps) + get_property(dep_stamp_dir TARGET ${dep} PROPERTY _EP_STAMP_DIR) + list(APPEND file_deps ${dep_stamp_dir}${cfgdir}/${dep}-done) + if(dep_stamp_dir) + list(APPEND file_deps ${dep_stamp_dir}${cfgdir}/${dep}-done) + else(dep_stamp_dir) + list(APPEND file_deps ${dep}) + endif(dep_stamp_dir) + endforeach() + + get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET) + if(cmd_set) + get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND) + else() + get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND) + if(cmake_command) + set(cmd "${cmake_command}") + else() + set(cmd "${CMAKE_COMMAND}") + endif() + + get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS) + list(APPEND cmd ${cmake_args}) + + get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR) + if(cmake_generator) + list(APPEND cmd "-G${cmake_generator}" "${source_dir}") + else() + list(APPEND cmd "-G${CMAKE_GENERATOR}" "${source_dir}") + endif() + endif() + + # If anything about the configure command changes, (command itself, cmake + # used, cmake args or cmake generator) then re-run the configure step. + # Fixes issue http://public.kitware.com/Bug/view.php?id=10258 + # + if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in) + file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='@cmd@'\n") + endif() + configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt) + list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt) + + ExternalProject_Add2_Gem5Specific_Step(${name} configure + COMMAND ${cmd} + WORKING_DIRECTORY ${binary_dir} + DEPENDEES update patch + DEPENDS ${file_deps} + ) +endfunction(_ep_add_configure_command) + + +function(_ep_add_build_command name) + ExternalProject_Get_Property(${name} binary_dir) + + get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET) + if(cmd_set) + get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND) + else() + _ep_get_build_command(${name} BUILD cmd) + endif() + + ExternalProject_Add2_Gem5Specific_Step(${name} build + COMMAND ${cmd} + WORKING_DIRECTORY ${binary_dir} + DEPENDEES configure + ) +endfunction(_ep_add_build_command) + + +function(_ep_add_install_command name) + ExternalProject_Get_Property(${name} binary_dir) + + get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET) + if(cmd_set) + get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND) + else() + _ep_get_build_command(${name} INSTALL cmd) + endif() + + ExternalProject_Add2_Gem5Specific_Step(${name} install + COMMAND ${cmd} + WORKING_DIRECTORY ${binary_dir} + DEPENDEES build + ) +endfunction(_ep_add_install_command) + + +function(_ep_add_test_command name) + ExternalProject_Get_Property(${name} binary_dir) + + get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL) + get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL) + get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET) + + # Only actually add the test step if one of the test related properties is + # explicitly set. (i.e. the test step is omitted unless requested...) + # + if(cmd_set OR before OR after) + if(cmd_set) + get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND) + else() + _ep_get_build_command(${name} TEST cmd) + endif() + + if(before) + set(dep_args DEPENDEES build DEPENDERS install) + else() + set(dep_args DEPENDEES install) + endif() + + ExternalProject_Add2_Gem5Specific_Step(${name} test + COMMAND ${cmd} + WORKING_DIRECTORY ${binary_dir} + ${dep_args} + ) + endif() +endfunction(_ep_add_test_command) + + +function(ExternalProject_Add2_Gem5Specific name) + _ep_get_configuration_subdir_suffix(cfgdir) + + # Add a custom target for the external project. + set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles) + add_custom_target(${name} ALL DEPENDS ${cmf_dir}${cfgdir}/${name}-complete) + set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1) + _ep_parse_arguments(ExternalProject_Add2_Gem5Specific ${name} _EP_ "${ARGN}") + _ep_set_directories(${name}) + ExternalProject_Get_Property(${name} stamp_dir) + + # The 'complete' step depends on all other steps and creates a + # 'done' mark. A dependent external project's 'configure' step + # depends on the 'done' mark so that it rebuilds when this project + # rebuilds. It is important that 'done' is not the output of any + # custom command so that CMake does not propagate build rules to + # other external project targets. + add_custom_command( + OUTPUT ${cmf_dir}${cfgdir}/${name}-complete + COMMENT "Completed '${name}'" + COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir} + COMMAND ${CMAKE_COMMAND} -E touch ${cmf_dir}${cfgdir}/${name}-complete + COMMAND ${CMAKE_COMMAND} -E touch ${stamp_dir}${cfgdir}/${name}-done + DEPENDS ${stamp_dir}${cfgdir}/${name}-install + VERBATIM + ) + + + # Depend on other external projects (target-level). + get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS) + foreach(arg IN LISTS deps) + add_dependencies(${name} ${arg}) + endforeach() + + # Set up custom build steps based on the target properties. + # Each step depends on the previous one. + # + # The target depends on the output of the final step. + # (Already set up above in the DEPENDS of the add_custom_target command.) + # + _ep_add_mkdir_command(${name}) + _ep_add_download_command(${name}) + _ep_add_update_command(${name}) + _ep_add_patch_command(${name}) + _ep_add_configure_command(${name}) + _ep_add_build_command(${name}) + _ep_add_install_command(${name}) + + # Test is special in that it might depend on build, or it might depend + # on install. + # + _ep_add_test_command(${name}) +endfunction(ExternalProject_Add2_Gem5Specific) diff --git a/cmake/gem5.cmake b/cmake/gem5.cmake index a926cbc6..21b8f417 100644 --- a/cmake/gem5.cmake +++ b/cmake/gem5.cmake @@ -6,13 +6,29 @@ if(BUILD_GEM5) set(gem5_src_dir ${PROJECT_SOURCE_DIR}/simulators/gem5) set(gem5_wrapper ${PROJECT_SOURCE_DIR}/src/core/sal/gem5) set(gem5_build_config build/ARM/gem5.debug) - set(core_count 9) + ## Determine the number of cores: + set(core_count 0) # unknown + # Linux: + set(cpuinfo_file "/proc/cpuinfo") + if(EXISTS "${cpuinfo_file}") + file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$") + list(LENGTH procs core_count) + endif() + # Mac: + if(APPLE) + find_program(cmd_sys_pro "system_profiler") + if(cmd_sys_pro) + execute_process(COMMAND ${cmd_sys_pro} OUTPUT_VARIABLE info) + string(REGEX REPLACE "^.*Total Number Of Cores: ([0-9]+).*$" "\\1" + core_count "${info}") + endif() + endif() + MATH(EXPR VAR "${core_count}+1") # CPU++ + MESSAGE(STATUS "Using ${core_count} core(s) for compiling with scons ...") # FIXMEs: - # - incremental builds working? - # - dependency for modified .cc files not correctly checked - # - core_count should be derived from the parent make -jX parameter - # - make gem5_build_config configurable in CMake + # - ${core_count} should be derived from the parent make -jX parameter + # - make ${gem5_build_config} configurable in CMake # (alternative: gem5_build_config is set based on the CMake build # config, e.g., "Debug" or "Release") # - Ideally, there is no additional "gem5-clean" target. Instead, @@ -20,29 +36,65 @@ if(BUILD_GEM5) # gem5 root dir. This seems easy for "make only" projects--things # get shaky due to "scons". - # Enable ExternalProject CMake module - include(ExternalProject) + # Enable ExternalProject CMake module (located in $FAIL/cmake/) + include(ExternalProjectGem5Specific) - # Use cmake's external project feature to build gem5 (and link FailGem5) - ExternalProject_Add( - FailGem5_binary_external # the (unique) name of this custom target (= external project) + add_custom_target(gem5-force-re-linking + COMMAND @echo "Removing gem5 binary and CMake build stamp ..." + COMMAND rm "${gem5_src_dir}/${gem5_build_config}" -f + COMMAND rm "${PROJECT_BINARY_DIR}/FailGem5_binary_external-prefix/src/FailGem5_binary_external-stamp/FailGem5_binary_external-build" -f + ) + # WARNING: This requires a known (and "fixed") implementation of + # ExternalProject_Add() because we enforce re-linking by deleting + # some internal CMake time-stamp files generated by the external + # project stuff. We therefore provide our own version + # ("ExternalProjectGem5Specific") using a different name. + + # Generate gem5 headers using the scons build system (in our custom "dummy" mode): + # This effectivly calls the whole gem5 toolchain but replaces the compiler, the + # linker, ar and ranlib with usr/bin/true. It allows us to just generate the headers + # which, in turn, are required for fail compilation. This target has no dependencies. + ExternalProject_Add2_Gem5Specific( + FailGem5_generation # the (unique) name of this custom target (= external project) # Disable update, patch and configure step: UPDATE_COMMAND "" PATCH_COMMAND "" CONFIGURE_COMMAND "" SOURCE_DIR ${gem5_src_dir} BINARY_DIR ${gem5_src_dir} + BUILD_COMMAND scons ${gem5_build_config} --dummy + # Disable install step (for now) + INSTALL_COMMAND "" + ) + + # Use cmake's external project feature to build gem5 (and link FailGem5): + ExternalProject_Add2_Gem5Specific( + FailGem5_binary_external + DEPENDS FailGem5_generation + # Disable update, patch and configure step: + UPDATE_COMMAND "" + PATCH_COMMAND "" + SOURCE_DIR ${gem5_src_dir} + BINARY_DIR ${gem5_src_dir} + CONFIGURE_COMMAND "" # Build gem5 using scons build system: BUILD_COMMAND scons "CXX=${CMAKE_CXX_COMPILER} -p ${gem5_src_dir} --Xcompiler" EXTRAS=${gem5_wrapper} ${gem5_build_config} -j${core_count} # Disable install step (for now) INSTALL_COMMAND "" ) + + # Cleans up everything (gem5 and Fail related): add_custom_target(gem5-allclean COMMAND @echo "Cleaning Fail* and gem5 ..." COMMAND cd "${PROJECT_BINARY_DIR}/" && make clean COMMAND cd "${gem5_src_dir}/" && scons -c build/ARM + COMMAND cd "${gem5_src_dir}/" && rm -rf build/ ) - # Build "fail" library first (will be statically linked to gem5) + # Resolve header dependencies first (i.e., generate the header files): + add_dependencies(fail-sal FailGem5_generation) + # Always enforce re-linking (bugfix for cmake/scons): + add_dependencies(fail gem5-force-re-linking) + # Re-build/link gem5 if Fail code has changed: add_dependencies(FailGem5_binary_external fail) endif(BUILD_GEM5) diff --git a/doc/how-to-build.txt b/doc/how-to-build.txt index f04735a5..608dacc4 100644 --- a/doc/how-to-build.txt +++ b/doc/how-to-build.txt @@ -199,12 +199,7 @@ For the first time (incl. selecting an experiment): $ ccmake . At least, you should set an experiment and turn on the following flags: BUILD_GEM5 = BUILD_ARM = ON. Additionally, all config - options specific for other simulator should be turned OFF. Finally, - edit ${FAIL_DIR}/src/core/sal/gem5/SConscript: search for a line - with "gStaticLibs" and ensure that this line lists all the various - target you want to include in the binary (especially your experiment - target and perhabs an additional plugin), i.e. change - -lfail-arch-test to -lfail-[EXPERIMENTNAME|PLUGINNAME]. + options specific for other simulator should be turned OFF. 5. Typing $ make (or nice make -jN) will start the build process of Fail* and gem5. This automatically @@ -225,10 +220,8 @@ After changes to Fail*/gem5 code (incl. aspect headers): $ make gem5-allclean (in your build dir ${FAIL_DIR}/build). This cleans the current Fail* and gem5 build directories. Note that "make clean" only cleans - the Fail* build directory. Additionally note, that changing the - specified experiment target requires editing - ${FAIL_DIR}/src/core/sal/gem5/SConscript (see above). Furthermore, all - remaining CMake remnants should be deleted: + the Fail* build directory. Furthermore, all remaining CMake remnants + should be deleted: $ find -name CMakeCache.txt | xargs rm 2. Rebuild by typing $ make (or nice make -jN) diff --git a/simulators/gem5/SConstruct b/simulators/gem5/SConstruct index 2b15f1b3..ca62786b 100755 --- a/simulators/gem5/SConstruct +++ b/simulators/gem5/SConstruct @@ -169,6 +169,9 @@ AddLocalOption('--update-ref', dest='update_ref', action='store_true', help='Update test reference outputs') AddLocalOption('--verbose', dest='verbose', action='store_true', help='Print full tool command lines') +# DanceOS-specific: +AddLocalOption('--dummy', dest='dummy', action='store_true', + help='Only generate files (do not actually compile)') termcap = get_termcap(GetOption('use_colors')) @@ -488,9 +491,19 @@ if main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: print 'Error: How can we have two at the same time?' Exit(1) +# DanceOS-specific: BEGIN main['GCC'] = True main['GCC_VERSION'] = '4.4.5' +if '--dummy' in sys.argv: + print 'Info: Compiling in dummy-mode (generate files only)!' + # Set the dummy build tools: + main['CXX'] = 'true' + main['AR'] = 'true' + main['RANLIB'] = 'true' + main['LINK'] = 'true' +# DanceOS-specific: END + # Set up default C++ compiler flags if main['GCC']: main.Append(CCFLAGS=['-pipe']) @@ -499,6 +512,7 @@ if main['GCC']: # Read the GCC version to check for versions with bugs # Note CCVERSION doesn't work here because it is run with the CC # before we override it from the command line +# DanceOS (commented out): # gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) # main['GCC_VERSION'] = gcc_version # if not compareVersions(gcc_version, '4.4.1') or \ diff --git a/src/core/sal/gem5/Gem5Controller.cc b/src/core/sal/gem5/Gem5Controller.cc index b01d9b3d..0975eee2 100644 --- a/src/core/sal/gem5/Gem5Controller.cc +++ b/src/core/sal/gem5/Gem5Controller.cc @@ -2,7 +2,6 @@ #include "Gem5Wrapper.hpp" #include "../Listener.hpp" #include "base/trace.hh" -#include "debug/FailState.hh" #include "sim/root.hh" #include @@ -38,8 +37,6 @@ Gem5Controller::~Gem5Controller() bool Gem5Controller::save(const std::string &path) { - DPRINTF(FailState, "Saving state to %s.\n", path); - Serializable::serializeAll(path); // Test if save was successful