From fa39179be7d6edb52afab4525fe11c6c7862db73 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Thu, 7 Sep 2017 09:05:41 -0700 Subject: [PATCH] Fix up doing builds script, add packaging up results. --- CMakeLists.txt | 7 +--- build.py | 53 ++++++++++++++++++++------- examples/send-presence/CMakeLists.txt | 7 ++++ src/CMakeLists.txt | 24 ++++++++---- 4 files changed, 64 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 431a9ca..2ffc1ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,9 +51,4 @@ add_library(rapidjson STATIC IMPORTED ${RAPIDJSON}) # add subdirs add_subdirectory(src) -add_subdirectory(examples/send-presence) - -add_custom_target(bundle - WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}" - COMMAND ${CMAKE_COMMAND} -E tar cfvz "${CMAKE_BINARY_DIR}/discord-rpc.tar.gz" . -) +add_subdirectory(examples/send-presence) \ No newline at end of file diff --git a/build.py b/build.py index e0859c8..358985b 100644 --- a/build.py +++ b/build.py @@ -1,7 +1,9 @@ +import click import os import subprocess import sys import shutil +import zipfile from contextlib import contextmanager @@ -25,10 +27,13 @@ def mkdir_p(path): os.makedirs(path) -def build(build_path, generator, options): +def build_lib(build_name, generator, options): + build_path = os.path.join(SCRIPT_PATH, 'builds', build_name) + install_path = os.path.join(SCRIPT_PATH, 'builds', 'install', build_name) mkdir_p(build_path) + mkdir_p(install_path) with cd(build_path): - initial_cmake = ['cmake', SCRIPT_PATH] + initial_cmake = ['cmake', SCRIPT_PATH, '-DCMAKE_INSTALL_PREFIX=%s' % os.path.join('..', 'install', build_name)] if generator: initial_cmake.extend(['-G', generator]) for key in options: @@ -36,25 +41,47 @@ def build(build_path, generator, options): initial_cmake.append('-D%s=%s' %(key, val)) subprocess.check_call(initial_cmake) subprocess.check_call(['cmake', '--build', '.', '--config', 'Debug']) - subprocess.check_call(['cmake', '--build', '.', '--config', 'Release']) + subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'install']) -def main(): +def create_archive(): + archive_file_path = os.path.join(SCRIPT_PATH, 'builds', 'discord-rpc.zip') + archive_file = zipfile.ZipFile(archive_file_path, 'w', zipfile.ZIP_DEFLATED) + archive_src_base_path = os.path.join(SCRIPT_PATH, 'builds', 'install') + archive_dst_base_path = 'discord-rpc' + with cd(archive_src_base_path): + for path, subdirs, filenames in os.walk('.'): + for fname in filenames: + fpath = os.path.join(path, fname) + archive_file.write(fpath, os.path.normpath(os.path.join(archive_dst_base_path, fpath))) + + +@click.command() +@click.option('--clean', is_flag=True) +def main(clean): os.chdir(SCRIPT_PATH) + + if clean: + shutil.rmtree('builds', ignore_errors=True) + if sys.platform.startswith('win'): - generator = 'Visual Studio 14 2015' - build(os.path.join(SCRIPT_PATH, 'builds', 'win32-static'), generator, {}) - build(os.path.join(SCRIPT_PATH, 'builds', 'win32-dynamic'), generator, {'BUILD_DYNAMIC_LIB': True}) - generator = 'Visual Studio 14 2015 Win64' - build(os.path.join(SCRIPT_PATH, 'builds', 'win64-static'), generator, {}) - build(os.path.join(SCRIPT_PATH, 'builds', 'win64-dynamic'), generator, {'BUILD_DYNAMIC_LIB': True}) + generator32 = 'Visual Studio 14 2015' + generator64 = 'Visual Studio 14 2015 Win64' + + build_lib('win32-static', generator32, {}) + build_lib('win32-dynamic', generator32, {'BUILD_DYNAMIC_LIB': True}) + build_lib('win64-static', generator64, {}) + build_lib('win64-dynamic', generator64, {'BUILD_DYNAMIC_LIB': True}) + # todo: this in some better way src_dll = os.path.join(SCRIPT_PATH, 'builds', 'win64-dynamic', 'src', 'Release', 'discord-rpc.dll') - dst_dll = os.path.join(SCRIPT_PATH, 'examples\\button-clicker\\Assets\\Resources\\discord-rpc.dll') + dst_dll = os.path.join(SCRIPT_PATH, 'examples', 'button-clicker', 'Assets', 'Resources', 'discord-rpc.dll') shutil.copy(src_dll, dst_dll) - dst_dll = os.path.join(SCRIPT_PATH, 'examples\\unrealstatus\\Plugins\\discordrpc\\Binaries\\ThirdParty\\discordrpcLibrary\\Win64\\discord-rpc.dll') + dst_dll = os.path.join(SCRIPT_PATH, 'examples', 'unrealstatus', 'Plugins', 'discordrpc', 'Binaries', 'ThirdParty', 'discordrpcLibrary', 'Win64', 'discord-rpc.dll') shutil.copy(src_dll, dst_dll) + create_archive() + if __name__ == '__main__': - sys.exit(main()) + sys.exit(main()) \ No newline at end of file diff --git a/examples/send-presence/CMakeLists.txt b/examples/send-presence/CMakeLists.txt index b13cb2e..68ea181 100644 --- a/examples/send-presence/CMakeLists.txt +++ b/examples/send-presence/CMakeLists.txt @@ -1,3 +1,10 @@ include_directories(${PROJECT_SOURCE_DIR}/include) add_executable(send-presence send-presence.c) target_link_libraries(send-presence discord-rpc) + +install( + TARGETS send-presence + RUNTIME + DESTINATION "bin" + CONFIGURATIONS Release +) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31f95db..f7fc7cb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,10 +3,6 @@ include_directories(${PROJECT_SOURCE_DIR}/include) option(ENABLE_IO_THREAD "Start up a separate I/O thread, otherwise I'd need to call an update function" ON) option(BUILD_DYNAMIC_LIB "Build library as a DLL" OFF) -if (NOT ${ENABLE_IO_THREAD}) - add_definitions(-DDISCORD_DISABLE_IO_THREAD) -endif (NOT ${ENABLE_IO_THREAD}) - set(BASE_RPC_SRC ${PROJECT_SOURCE_DIR}/include/discord-rpc.h discord-rpc.cpp @@ -40,6 +36,10 @@ endif(UNIX) target_include_directories(discord-rpc PRIVATE ${RAPIDJSON}/include) +if (NOT ${ENABLE_IO_THREAD}) + add_definitions(discord-rpc PUBLIC -DDISCORD_DISABLE_IO_THREAD) +endif (NOT ${ENABLE_IO_THREAD}) + if (${BUILD_DYNAMIC_LIB}) target_compile_definitions(discord-rpc PUBLIC -DDISCORD_DYNAMIC_LIB) target_compile_definitions(discord-rpc PRIVATE -DDISCORD_BUILDING_SDK) @@ -52,13 +52,21 @@ add_dependencies(discord-rpc clangformat) install( TARGETS discord-rpc EXPORT "discord-rpc" - LIBRARY DESTINATION "lib" - ARCHIVE DESTINATION "lib" - INCLUDES DESTINATION "include" + RUNTIME + DESTINATION "bin" + CONFIGURATIONS Release + LIBRARY + DESTINATION "lib" + CONFIGURATIONS Release + ARCHIVE + DESTINATION "lib" + CONFIGURATIONS Release + INCLUDES + DESTINATION "include" ) install( FILES "../include/discord-rpc.h" DESTINATION "include" -) +) \ No newline at end of file