From c3561a7fcbec5830b4d775b270ae6b2aadc32b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 17 May 2016 16:49:45 +0200 Subject: [PATCH] Add CMake scripts for building dependencies Add CMake scripts and helper functions to build this dependencies: - boost (ported from .bat script, version bump to 1.61), - LLVM, - OpenCL ICD Loader. Also added install_deps.cmake scripts that downloads all dependencies (including Qt) from GitHub release page. --- .gitignore | 4 ++ build_boost.bat | 23 ------- bundle_boost.bat | 15 ----- install_boost.bat | 10 --- install_deps.cmake | 21 +++++++ main.bat | 4 -- scripts/build_boost.cmake | 30 +++++++++ scripts/build_llvm.cmake | 32 ++++++++++ scripts/build_opencl-icd-loader.cmake | 23 +++++++ scripts/helpers.cmake | 90 +++++++++++++++++++++++++++ 10 files changed, 200 insertions(+), 52 deletions(-) delete mode 100644 build_boost.bat delete mode 100644 bundle_boost.bat delete mode 100644 install_boost.bat create mode 100644 install_deps.cmake create mode 100644 scripts/build_boost.cmake create mode 100644 scripts/build_llvm.cmake create mode 100644 scripts/build_opencl-icd-loader.cmake create mode 100644 scripts/helpers.cmake diff --git a/.gitignore b/.gitignore index 796b96d..2d2845d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ /build +/cache +/install +/package +/packages diff --git a/build_boost.bat b/build_boost.bat deleted file mode 100644 index 5326dbb..0000000 --- a/build_boost.bat +++ /dev/null @@ -1,23 +0,0 @@ -REM download boost -if not exist build\boost mkdir build\boost - -cd build\boost - -if not exist boost ( - curl -o boost_1_55_0.tar.gz -L http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download - tar -zxvf boost_1_55_0.tar.gz - cmake -E rename boost_1_55_0 boost -) - -cd boost - -REM build boost -if not exist b2.exe call bootstrap.bat - -if not exist "stage/%PLATFORM%" ( - if %PLATFORM% == Win32 b2.exe -j4 --build-type=complete link=static runtime-link=shared variant=debug,release threading=multi --with-filesystem --with-system --with-thread --with-date_time --with-regex --with-test --with-program_options --with-random --with-atomic stage - if %PLATFORM% == x64 b2.exe -j4 --build-type=complete link=static runtime-link=shared variant=debug,release threading=multi address-model=64 --with-filesystem --with-system --with-thread --with-date_time --with-regex --with-test --with-program_options --with-random --with-atomic stage - cmake -E rename stage/lib stage/%PLATFORM% -) - -cd ..\..\.. diff --git a/bundle_boost.bat b/bundle_boost.bat deleted file mode 100644 index 1ef3ac4..0000000 --- a/bundle_boost.bat +++ /dev/null @@ -1,15 +0,0 @@ -REM packaging boost -if not exist package\boost mkdir package\boost - -if not exist package\boost\%PLATFORM% mkdir package\boost\%PLATFORM% -if not exist package\boost\%PLATFORM%\lib mkdir package\boost\%PLATFORM%\lib -if not exist package\boost\%PLATFORM%\include mkdir package\boost\%PLATFORM%\include -if not exist package\boost\%PLATFORM%\include\boost mkdir package\boost\%PLATFORM%\include\boost - -cd package\boost\%PLATFORM% - -cmake -E copy_directory ..\..\..\build\boost\boost\boost include\boost -cmake -E copy_directory ..\..\..\build\boost\boost\stage\%PLATFORM% lib - -cd ..\..\.. - diff --git a/install_boost.bat b/install_boost.bat deleted file mode 100644 index d4a1416..0000000 --- a/install_boost.bat +++ /dev/null @@ -1,10 +0,0 @@ -REM installing boost -cmake -E copy_directory package\boost install - -REM zipping boost -cd package -if exist boost-1.55.0 cmake -E remove_directory boost-1.55.0 -cmake -E rename boost boost-1.55.0 -tar -zcvf boost-1.55.0.tar.gz boost-1.55.0 -cd .. - diff --git a/install_deps.cmake b/install_deps.cmake new file mode 100644 index 0000000..4f38ff2 --- /dev/null +++ b/install_deps.cmake @@ -0,0 +1,21 @@ +include("${CMAKE_CURRENT_LIST_DIR}/scripts/helpers.cmake") + +set(INSTALL_DIR "${ROOT_DIR}/install") +set(SERVER "https://github.com/ethereum/cpp-dependencies/releases/download/vc140/") + +function(download_and_install PACKAGE_NAME) + download_and_unpack("${SERVER}${PACKAGE_NAME}.tar.gz" ${INSTALL_DIR}) +endfunction(download_and_install) + + +download_and_install("boost-1.61") +download_and_install("cryptopp-5.6.2") +download_and_install("curl-7.4.2") +download_and_install("json-rpc-cpp-0.5.0") +download_and_install("jsoncpp-1.6.2") +download_and_install("opencl-icd-loader-0.0") +download_and_install("leveldb-1.2") +download_and_install("llvm-3.8.0") +download_and_install("microhttpd-0.9.2") +download_and_install("miniupnpc-1.9") +download_and_install("qt-5.6") diff --git a/main.bat b/main.bat index ea91eaf..4aa3ec0 100644 --- a/main.bat +++ b/main.bat @@ -32,9 +32,6 @@ call :setup x64 Debug & call build_cryptopp.bat & call bundle_cryptopp.ba call :setup x64 Release & call build_cryptopp.bat & call bundle_cryptopp.bat || goto :error call install_cryptopp.bat || goto :error -call :setup x64 both & call build_boost.bat & call bundle_boost.bat || goto :error -call install_boost.bat - call :setup x64 Debug & call build_leveldb.bat & call bundle_leveldb.bat || goto :error call :setup x64 Release & call build_leveldb.bat & call bundle_leveldb.bat || goto :error call install_leveldb.bat || goto :error @@ -56,4 +53,3 @@ echo Failed with error %errorlevel% exit /b %errorlevel% :EOF - diff --git a/scripts/build_boost.cmake b/scripts/build_boost.cmake new file mode 100644 index 0000000..5e5b10c --- /dev/null +++ b/scripts/build_boost.cmake @@ -0,0 +1,30 @@ +include("${CMAKE_CURRENT_LIST_DIR}/helpers.cmake") + +prepare_package_source(boost 1.61 http://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.gz) + +if (NOT EXISTS ${SOURCE_DIR}/b2.exe) + execute_process(COMMAND bootstrap.bat WORKING_DIRECTORY ${SOURCE_DIR}) +endif() + +execute_process(COMMAND ./b2 -j4 + stage --stagedir=${INSTALL_DIR}/win64 --build-dir=${BUILD_DIR} + link=static + runtime-link=shared + variant=release + threading=multi + address-model=64 + --with-filesystem + --with-system + --with-thread + --with-date_time + --with-regex + --with-test + --with-program_options + --with-random + --with-atomic + WORKING_DIRECTORY ${SOURCE_DIR}) + +message("Copying boost headers") +file(COPY ${SOURCE_DIR}/boost DESTINATION ${INSTALL_DIR}/win64/include) + +create_package(${PACKAGE_NAME} ${INSTALL_DIR}) diff --git a/scripts/build_llvm.cmake b/scripts/build_llvm.cmake new file mode 100644 index 0000000..75427e0 --- /dev/null +++ b/scripts/build_llvm.cmake @@ -0,0 +1,32 @@ +# This script downloads LLVM source and builds it with Visual Studio. + +include("${CMAKE_CURRENT_LIST_DIR}/helpers.cmake") + +function(build_llvm CONFIGURATION) + if (CONFIGURATION STREQUAL "Release") + set(ASSERTS OFF) + set(CONFIG "Release") + elseif (CONFIGURATION STREQUAL "Debug") + set(ASSERTS ON) + set(CONFIG "RelWithDebInfo") + else() + message(FATAL_ERROR "Wrong configuration") + endif() + set(INSTALL_DIR "${INSTALL_DIR}/win64/${CONFIGURATION}") + + execute_process(COMMAND cmake ${SOURCE_DIR} -G "Visual Studio 14 2015 Win64" + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} + -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BUILD_TOOLS=OFF + -DLLVM_ENABLE_ASSERTIONS=${ASSERTS} + WORKING_DIRECTORY ${BUILD_DIR}) + + execute_process(COMMAND cmake --build ${BUILD_DIR} + --target install --config ${CONFIG}) +endfunction(build_llvm) + +prepare_package_source(llvm 3.8.0 http://llvm.org/releases/3.8.0/llvm-3.8.0.src.tar.xz) + +build_llvm("Release") +# build_llvm("Debug") + +create_package(${PACKAGE_NAME} ${INSTALL_DIR}) diff --git a/scripts/build_opencl-icd-loader.cmake b/scripts/build_opencl-icd-loader.cmake new file mode 100644 index 0000000..a1a4dd6 --- /dev/null +++ b/scripts/build_opencl-icd-loader.cmake @@ -0,0 +1,23 @@ +# This scirpt builds universal OpenCL ICD Loader that searches for OpenCL +# implementations at run-time. The package also includes OpenCL headers. + +include("${CMAKE_CURRENT_LIST_DIR}/helpers.cmake") + +prepare_package_source(opencl-icd-loader 0.0 https://github.com/KhronosGroup/OpenCL-ICD-Loader/archive/master/OpenCL-ICD-Loader.tar.gz) + +if (NOT EXISTS ${SOURCE_DIR}/inc/CL) + download_and_unpack(https://github.com/KhronosGroup/OpenCL-Headers/archive/master/OpenCL-Headers.tar.gz ${SOURCE_DIR} STATUS) + file(RENAME ${SOURCE_DIR}/OpenCL-Headers-master ${SOURCE_DIR}/inc/CL) +endif() + +execute_process(COMMAND cmake ${SOURCE_DIR} -G "Visual Studio 14 2015 Win64" + WORKING_DIRECTORY ${BUILD_DIR}) + +execute_process(COMMAND cmake --build ${BUILD_DIR} + --target OpenCL --config Release) + +file(COPY ${BUILD_DIR}/Release/OpenCl.lib DESTINATION ${INSTALL_DIR}/win64/lib/) +file(COPY ${BUILD_DIR}/bin/Release/OpenCl.dll DESTINATION ${INSTALL_DIR}/win64/bin/) +file(COPY ${SOURCE_DIR}/inc/CL DESTINATION ${INSTALL_DIR}/win64/include/) + +create_package(${PACKAGE_NAME} ${INSTALL_DIR}) diff --git a/scripts/helpers.cmake b/scripts/helpers.cmake new file mode 100644 index 0000000..c8c653b --- /dev/null +++ b/scripts/helpers.cmake @@ -0,0 +1,90 @@ +get_filename_component(ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) + +set(CACHE_DIR "${ROOT_DIR}/cache") +set(PACKAGES_DIR "${ROOT_DIR}/packages") + +function(download URL DST_FILE STATUS) + set(TMP_FILE "${DST_FILE}.part") + + get_filename_component(FILE_NAME ${DST_FILE} NAME) + if (NOT EXISTS ${DST_FILE}) + message("Downloading ${FILE_NAME}") + file(DOWNLOAD ${URL} ${TMP_FILE} SHOW_PROGRESS STATUS DOWNLOAD_STATUS) + list(GET DOWNLOAD_STATUS 0 STATUS_CODE) + if (STATUS_CODE EQUAL 0) + file(RENAME ${TMP_FILE} ${DST_FILE}) + else() + file(REMOVE ${TMP_FILE}) + list(GET DOWNLOAD_STATUS 1 ERROR_MSG) + + message("ERROR! Downloading '${FILE_NAME}' failed.") + message(STATUS "URL: ${URL}") + message(STATUS "Error: ${STATUS_CODE} ${ERROR_MSG}") + set(STATUS FALSE PARENT_SCOPE) + return() + endif() + else() + message("Using cached ${FILE_NAME}") + endif() + set(STATUS TRUE PARENT_SCOPE) +endfunction(download) + +function(download_and_unpack PACKAGE_URL DST_DIR) + get_filename_component(FILE_NAME ${PACKAGE_URL} NAME) + + set(DST_FILE "${CACHE_DIR}/${FILE_NAME}") + set(TMP_FILE "${DST_FILE}.part") + + file(MAKE_DIRECTORY ${CACHE_DIR}) + file(MAKE_DIRECTORY ${DST_DIR}) + + download(${PACKAGE_URL} ${DST_FILE} STATUS) + + if (STATUS) + message("Unpacking ${FILE_NAME} to ${DST_DIR}") + execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf ${DST_FILE} + WORKING_DIRECTORY ${DST_DIR}) + endif() +endfunction(download_and_unpack) + +# Packs installed package binaries and headers into an archive. +function(create_package NAME DIR) + message("Creating package ${NAME}") + file(MAKE_DIRECTORY ${PACKAGES_DIR}) + + # To create an archive without addicional top level directory + # (like package-X.Y.Z) we need to know all top level files/dirs. + # Usually it is just "win64" dir. + file(GLOB TOP_FILES RELATIVE ${DIR} "${DIR}/*") + + set(PACKAGE_FILE "${PACKAGES_DIR}/${NAME}.tar.gz") + execute_process(COMMAND ${CMAKE_COMMAND} -E + tar -czf ${PACKAGE_FILE} ${TOP_FILES} + WORKING_DIRECTORY ${DIR}) +endfunction(create_package) + +# Downloads the source code of the package and unpacks it to dedicated 'src' +# dir. Also creates 'build' and 'install' dir to be used by a build script. +function(prepare_package_source NAME VERSION URL) + set(PACKAGE_NAME "${NAME}-${VERSION}") + + set(PACKAGE_DIR "${CACHE_DIR}/${PACKAGE_NAME}") + set(SOURCE_DIR "${PACKAGE_DIR}/src") + set(BUILD_DIR "${PACKAGE_DIR}/build") + set(INSTALL_DIR "${PACKAGE_DIR}/install") + + if (NOT EXISTS ${SOURCE_DIR}) + download_and_unpack(${URL} ${PACKAGE_DIR} STATUS) + file(GLOB ORIG_SOURCE_DIR_NAME "${PACKAGE_DIR}/*") + file(RENAME ${ORIG_SOURCE_DIR_NAME} ${SOURCE_DIR}) + endif() + + file(MAKE_DIRECTORY ${BUILD_DIR}) + file(MAKE_DIRECTORY ${INSTALL_DIR}) + + # Export names and dirs to be used by a package-specific build script. + set(PACKAGE_NAME ${PACKAGE_NAME} PARENT_SCOPE) + set(SOURCE_DIR ${SOURCE_DIR} PARENT_SCOPE) + set(BUILD_DIR ${BUILD_DIR} PARENT_SCOPE) + set(INSTALL_DIR ${INSTALL_DIR} PARENT_SCOPE) +endfunction()