From 01a62b850a76916dae66f7f52e1d1e515584e7ce Mon Sep 17 00:00:00 2001
From: open-license-manager <rillf@maildrop.cc>
Date: 摹曛, 07 8月 2014 23:27:40 +0800
Subject: [PATCH] added boost

---
 build/modules/add_boost.cmake        |  297 +++++++++++++++++++++++++++++++++++++
 test/functional/CMakeLists.txt       |    5 
 build/modules/target_arch.cmake      |  134 ++++++++++++++++
 src/bootstrap/win/Main.cpp           |    1 
 src/license-generator/CMakeLists.txt |    2 
 CMakeLists.txt                       |   19 ++
 6 files changed, 454 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4a22b1..6dd24a0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,6 @@
 endif(WIN32)
 
 
-
 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
   SET(HAVE_64BIT_SIZE_T 1)
 else(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -47,16 +46,30 @@
 endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
 set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG)
 
+#TODO: determine target arch.
+SET( TargetArchitecture "X86_64")
+SET(Boost_USE_STATIC_LIBS ON)
+include(add_boost)
+set(Boost_FOUND TRUE)
+include_directories(${Boost_INCLUDE_DIRS})
+link_directories ( ${Boost_LIBRARY_DIRS} )
+
+#get_cmake_property(_variableNames VARIABLES)
+#foreach (_variableName ${_variableNames})
+#    message(STATUS "${_variableName}=${${_variableName}}")
+#endforeach()
+#include_directories(${Boost_INCLUDE_DIRS})
+#link_directories ( ${Boost_LIBRARY_DIRS} )
+
 #find_package(CryptoPP REQUIRED)
 #include_directories(${CRYPTOPP_INCLUDE_DIRS})
 #link_directories ( ${Boost_LIBRARY_DIRS} )
 
 
-SET(Boost_USE_STATIC_LIBS ON)
 # static runtime requires /MT 
 #SET(Boost_USE_MULTITHREADED ON) #SET(Boost_USE_STATIC_RUNTIME OFF)
 #find_package(Boost COMPONENTS thread date_time program_options filesystem system regex unit_test_framework)
-find_package(Boost COMPONENTS date_time program_options filesystem system unit_test_framework)
+#find_package(Boost COMPONENTS date_time program_options filesystem system unit_test_framework)
 #include_directories(${Boost_INCLUDE_DIRS})
 #link_directories ( ${Boost_LIBRARY_DIRS} )
 
diff --git a/build/modules/add_boost.cmake b/build/modules/add_boost.cmake
new file mode 100644
index 0000000..2de087d
--- /dev/null
+++ b/build/modules/add_boost.cmake
@@ -0,0 +1,297 @@
+
+
+function(ms_underscores_to_camel_case VarIn VarOut)
+  string(REPLACE "_" ";" Pieces ${VarIn})
+  foreach(Part ${Pieces})
+    string(SUBSTRING ${Part} 0 1 Initial)
+    string(SUBSTRING ${Part} 1 -1 Part)
+    string(TOUPPER ${Initial} Initial)
+    set(CamelCase ${CamelCase}${Initial}${Part})
+  endforeach()
+  set(${VarOut} ${CamelCase} PARENT_SCOPE)
+endfunction()
+
+set(BoostVersion 1.55.0)
+set(BoostSHA1 cef9a0cc7084b1d639e06cd3bc34e4251524c840)
+
+
+
+# Create build folder name derived from version
+string(REGEX REPLACE "beta\\.([0-9])$" "beta\\1" BoostFolderName ${BoostVersion})
+string(REPLACE "." "_" BoostFolderName ${BoostFolderName})
+set(BoostFolderName boost_${BoostFolderName})
+
+# If user wants to use a cache copy of Boost, get the path to this location.
+if(USE_BOOST_CACHE)
+  if(BOOST_CACHE_DIR)
+    file(TO_CMAKE_PATH "${BOOST_CACHE_DIR}" BoostCacheDir)
+  elseif(WIN32)
+    ms_get_temp_dir()
+    set(BoostCacheDir "${TempDir}")
+  elseif(APPLE)
+    set(BoostCacheDir "$ENV{HOME}/Library/Caches")
+  else()
+    set(BoostCacheDir "$ENV{HOME}/.cache")
+  endif()
+endif()
+
+# If the cache directory doesn't exist, fall back to use the build root.
+if(NOT IS_DIRECTORY "${BoostCacheDir}")
+  if(BOOST_CACHE_DIR)
+    set(Message "\nThe directory \"${BOOST_CACHE_DIR}\" provided in BOOST_CACHE_DIR doesn't exist.")
+    set(Message "${Message}  Falling back to default path at \"${CMAKE_BINARY_DIR}/license++\"\n")
+    message(WARNING "${Message}")
+  endif()
+  set(BoostCacheDir ${CMAKE_BINARY_DIR})
+else()
+  if(NOT USE_BOOST_CACHE AND NOT BOOST_CACHE_DIR)
+    set(BoostCacheDir "${BoostCacheDir}/license++")
+  endif()
+  file(MAKE_DIRECTORY "${BoostCacheDir}")
+endif()
+
+# Set up the full path to the source directory
+set(BoostSourceDir "${BoostFolderName}_${CMAKE_CXX_COMPILER_ID}_${CMAKE_CXX_COMPILER_VERSION}")
+if(HAVE_LIBC++)
+  set(BoostSourceDir "${BoostSourceDir}_LibCXX")
+endif()
+if(HAVE_LIBC++ABI)
+  set(BoostSourceDir "${BoostSourceDir}_LibCXXABI")
+endif()
+if(CMAKE_CL_64)
+  set(BoostSourceDir "${BoostSourceDir}_Win64")
+endif()
+string(REPLACE "." "_" BoostSourceDir ${BoostSourceDir})
+set(BoostSourceDir "${BoostCacheDir}/${BoostSourceDir}")
+
+# Check the full path to the source directory is not too long for Windows.  File paths must be less
+# than MAX_PATH which is 260.  The current longest relative path Boost tries to create is:
+# Build\boost\bin.v2\libs\program_options\build\fd41f4c7d882e24faa6837508d6e5384\libboost_program_options-vc120-mt-gd-1_55.lib.rsp
+# which along with a leading separator is 129 chars in length.  This gives a maximum path available
+# for 'BoostSourceDir' as 130 chars.
+if(WIN32)
+  get_filename_component(BoostSourceDirName "${BoostSourceDir}" NAME)
+  string(LENGTH "/${BoostSourceDirName}" BoostSourceDirNameLengthWithSeparator)
+  math(EXPR AvailableLength 130-${BoostSourceDirNameLengthWithSeparator})
+  string(LENGTH "${BoostSourceDir}" BoostSourceDirLength)
+  if(${BoostSourceDirLength} GREATER 130)
+    set(Msg "\n\nThe path to boost's source is too long to handle all the files which will ")
+    set(Msg "${Msg}be created when boost is built.  To avoid this, set the CMake variable ")
+    set(Msg "${Msg}USE_BOOST_CACHE to ON and set the variable BOOST_CACHE_DIR to a path ")
+    set(Msg "${Msg}which is at most ${AvailableLength} characters long.  For example:\n")
+    set(Msg "${Msg}  mkdir C:\\license_boost\n")
+    set(Msg "${Msg}  cmake . -DUSE_BOOST_CACHE=ON -DBOOST_CACHE_DIR=C:\\license_boost\n\n")
+    message(FATAL_ERROR "${Msg}")
+  endif()
+endif()
+
+# Download boost if required
+set(ZipFilePath "${BoostCacheDir}/${BoostFolderName}.tar.bz2")
+if(NOT EXISTS ${ZipFilePath})
+  message(STATUS "Downloading boost ${BoostVersion} to ${BoostCacheDir}")
+endif()
+file(DOWNLOAD http://sourceforge.net/projects/boost/files/boost/${BoostVersion}/${BoostFolderName}.tar.bz2/download
+     ${ZipFilePath}
+     STATUS Status
+     SHOW_PROGRESS
+     EXPECTED_HASH SHA1=${BoostSHA1}
+     )
+
+# Extract boost if required
+string(FIND "${Status}" "returning early" Found)
+if(Found LESS 0 OR NOT IS_DIRECTORY "${BoostSourceDir}")
+  set(BoostExtractFolder "${BoostCacheDir}/boost_unzip")
+  file(REMOVE_RECURSE ${BoostExtractFolder})
+  file(MAKE_DIRECTORY ${BoostExtractFolder})
+  file(COPY ${ZipFilePath} DESTINATION ${BoostExtractFolder})
+  message(STATUS "Extracting boost ${BoostVersion} to ${BoostExtractFolder}")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${BoostFolderName}.tar.bz2
+                  WORKING_DIRECTORY ${BoostExtractFolder}
+                  RESULT_VARIABLE Result
+                  )
+  if(NOT Result EQUAL 0)
+    message(FATAL_ERROR "Failed extracting boost ${BoostVersion} to ${BoostExtractFolder}")
+  endif()
+  file(REMOVE ${BoostExtractFolder}/${BoostFolderName}.tar.bz2)
+
+  # Get the path to the extracted folder
+  file(GLOB ExtractedDir "${BoostExtractFolder}/*")
+  list(LENGTH ExtractedDir n)
+  if(NOT n EQUAL 1 OR NOT IS_DIRECTORY ${ExtractedDir})
+    message(FATAL_ERROR "Failed extracting boost ${BoostVersion} to ${BoostExtractFolder}")
+  endif()
+  file(RENAME ${ExtractedDir} ${BoostSourceDir})
+  file(REMOVE_RECURSE ${BoostExtractFolder})
+endif()
+
+
+# Build b2 (bjam) if required
+unset(b2Path CACHE)
+find_program(b2Path NAMES b2 PATHS ${BoostSourceDir} NO_DEFAULT_PATH)
+if(NOT b2Path)
+  message(STATUS "Building b2 (bjam)")
+  if(MSVC)
+    set(b2Bootstrap "bootstrap.bat")
+  else()
+    set(b2Bootstrap "./bootstrap.sh")
+    if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+      list(APPEND b2Bootstrap --with-toolset=clang)
+    elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+      list(APPEND b2Bootstrap --with-toolset=gcc)
+    endif()
+  endif()
+  execute_process(COMMAND ${b2Bootstrap} WORKING_DIRECTORY ${BoostSourceDir}
+                  RESULT_VARIABLE Result OUTPUT_VARIABLE Output ERROR_VARIABLE Error)
+  if(NOT Result EQUAL 0)
+    message(FATAL_ERROR "Failed running ${b2Bootstrap}:\n${Output}\n${Error}\n")
+  endif()
+endif()
+execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BoostSourceDir}/Build)
+
+
+# Expose BoostSourceDir to parent scope
+set(BoostSourceDir ${BoostSourceDir} ) #PARENT_SCOPE
+
+# Set up general b2 (bjam) command line arguments
+set(b2Args <SOURCE_DIR>/b2
+           link=static
+           threading=multi
+           runtime-link=shared
+           --build-dir=Build
+           stage
+           -d+2
+           --hash
+           )
+if("${CMAKE_BUILD_TYPE}" STREQUAL "ReleaseNoInline")
+  list(APPEND b2Args cxxflags="${RELEASENOINLINE_FLAGS}")
+endif()
+if("${CMAKE_BUILD_TYPE}" STREQUAL "DebugLibStdcxx")
+  list(APPEND b2Args define=_GLIBCXX_DEBUG)
+endif()
+
+# Set up platform-specific b2 (bjam) command line arguments
+if(MSVC)
+  if(MSVC11)
+    list(APPEND b2Args toolset=msvc-11.0)
+  elseif(MSVC12)
+    list(APPEND b2Args toolset=msvc-12.0)
+  endif()
+  list(APPEND b2Args
+              define=_BIND_TO_CURRENT_MFC_VERSION=1
+              define=_BIND_TO_CURRENT_CRT_VERSION=1
+              --layout=versioned
+              )
+  if("${TargetArchitecture}" STREQUAL "x86_64")
+    list(APPEND b2Args address-model=64)
+  endif()
+elseif(APPLE)
+  list(APPEND b2Args variant=release toolset=clang cxxflags=-fPIC cxxflags=-std=c++11 cxxflags=-stdlib=libc++
+                     linkflags=-stdlib=libc++ architecture=combined address-model=32_64 --layout=tagged)
+elseif(UNIX)
+  list(APPEND b2Args variant=release cxxflags=-fPIC cxxflags=-std=c++11 -sNO_BZIP2=1 --layout=tagged)
+  # Need to configure the toolset based on whatever version CMAKE_CXX_COMPILER is
+  string(REGEX MATCH "[0-9]+\\.[0-9]+" ToolsetVer "${CMAKE_CXX_COMPILER_VERSION}")
+  if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+    list(APPEND b2Args toolset=clang-${ToolsetVer})
+    if(HAVE_LIBC++)
+      list(APPEND b2Args cxxflags=-stdlib=libc++ linkflags=-stdlib=libc++)
+    endif()
+  elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+    list(APPEND b2Args toolset=gcc-${ToolsetVer})
+  endif()
+endif()
+
+# Get list of components
+execute_process(COMMAND ./b2 --show-libraries WORKING_DIRECTORY ${BoostSourceDir}
+                ERROR_QUIET OUTPUT_VARIABLE Output)
+string(REGEX REPLACE "(^[^:]+:|[- ])" "" BoostComponents "${Output}")
+string(REGEX REPLACE "\n" ";" BoostComponents "${BoostComponents}")
+
+# Build each required component
+include(ExternalProject)
+foreach(Component ${BoostComponents})
+  ExternalProject_Add(
+      boost_${Component}
+      PREFIX ${CMAKE_BINARY_DIR}/${BoostFolderName}
+      SOURCE_DIR ${BoostSourceDir}
+      BINARY_DIR ${BoostSourceDir}
+      CONFIGURE_COMMAND ""
+      BUILD_COMMAND "${b2Args}" --with-${Component}
+      INSTALL_COMMAND ""
+      LOG_BUILD ON
+      )
+  ms_underscores_to_camel_case(${Component} CamelCaseComponent)
+  add_library(Boost${CamelCaseComponent} STATIC IMPORTED GLOBAL)
+  if(MSVC)
+    if(MSVC11)
+      set(CompilerName vc110)
+    elseif(MSVC12)
+      set(CompilerName vc120)
+    endif()
+    string(REGEX MATCH "[0-9]_[0-9][0-9]" Version "${BoostFolderName}")
+    set_target_properties(Boost${CamelCaseComponent} PROPERTIES
+                          IMPORTED_LOCATION_DEBUG ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-gd-${Version}.lib
+                          IMPORTED_LOCATION_MINSIZEREL ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib
+                          IMPORTED_LOCATION_RELEASE ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib
+                          IMPORTED_LOCATION_RELWITHDEBINFO ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib
+                          IMPORTED_LOCATION_RELEASENOINLINE ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib
+                          LINKER_LANGUAGE CXX)
+  else()
+    set_target_properties(Boost${CamelCaseComponent} PROPERTIES
+                          IMPORTED_LOCATION ${BoostSourceDir}/stage/lib/libboost_${Component}-mt.a
+                          LINKER_LANGUAGE CXX)
+  endif()
+  set_target_properties(boost_${Component} Boost${CamelCaseComponent} PROPERTIES
+                        LABELS Boost FOLDER "Third Party/Boost" EXCLUDE_FROM_ALL TRUE)
+  add_dependencies(Boost${CamelCaseComponent} boost_${Component})
+  set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent})
+  if("${Component}" STREQUAL "locale")
+    if(APPLE)
+      find_library(IconvLib iconv)
+      if(NOT IconvLib)
+        message(FATAL_ERROR "libiconv.dylib must be installed to a standard location.")
+      endif()
+      set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent} ${IconvLib})
+    elseif(UNIX)
+      if(BSD)
+        find_library(IconvLib libiconv.a)
+        if(NOT IconvLib)
+          set(Msg "libiconv.a must be installed to a standard location.")
+          set(Msg "  For ${Msg} on FreeBSD 10 or later, run\n  pkg install libiconv")
+          message(FATAL_ERROR "${Msg}")
+        endif()
+        set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent} ${IconvLib})
+      else()
+        find_library(Icui18nLib libicui18n.a)
+        find_library(IcuucLib libicuuc.a)
+        find_library(IcudataLib libicudata.a)
+        if(NOT Icui18nLib OR NOT IcuucLib OR NOT IcudataLib)
+          set(Msg "libicui18n.a, libicuuc.a & licudata.a must be installed to a standard location.")
+          set(Msg "  For ${Msg} on Ubuntu/Debian, run\n  sudo apt-get install libicu-dev")
+          message(FATAL_ERROR "${Msg}")
+        endif()
+        set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent} ${Icui18nLib} ${IcuucLib} ${IcudataLib})
+      endif()
+    else()
+      set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent})
+    endif()
+  endif()
+  set(Boost${CamelCaseComponent}Libs ${Boost${CamelCaseComponent}Libs}) # PARENT_SCOPE
+  list(APPEND AllBoostLibs Boost${CamelCaseComponent})
+endforeach()
+set(AllBoostLibs ${AllBoostLibs}) # PARENT_SCOPE
+add_dependencies(boost_chrono boost_system)
+add_dependencies(boost_coroutine boost_context boost_system)
+add_dependencies(boost_filesystem boost_system)
+add_dependencies(boost_graph boost_regex)
+add_dependencies(boost_locale boost_system)
+add_dependencies(boost_log boost_chrono boost_date_time boost_filesystem boost_thread)
+add_dependencies(boost_thread boost_chrono)
+add_dependencies(boost_timer boost_chrono)
+add_dependencies(boost_wave boost_chrono boost_date_time boost_filesystem boost_thread)
+
+set(Boost_INCLUDE_DIRS ${BoostSourceDir})
+set(Boost_LIBRARY_DIRS ${BoostSourceDir}/stage)
+
+
+
diff --git a/build/modules/target_arch.cmake b/build/modules/target_arch.cmake
new file mode 100644
index 0000000..f730063
--- /dev/null
+++ b/build/modules/target_arch.cmake
@@ -0,0 +1,134 @@
+# Based on the Qt 5 processor detection code, so should be very accurate
+# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
+# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
+
+# Regarding POWER/PowerPC, just as is noted in the Qt source,
+# "There are many more known variants/revisions that we do not handle/detect."
+
+set(archdetect_c_code "
+#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
+    #if defined(__ARM_ARCH_7__) \\
+        || defined(__ARM_ARCH_7A__) \\
+        || defined(__ARM_ARCH_7R__) \\
+        || defined(__ARM_ARCH_7M__) \\
+        || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
+        #error cmake_ARCH armv7
+    #elif defined(__ARM_ARCH_6__) \\
+        || defined(__ARM_ARCH_6J__) \\
+        || defined(__ARM_ARCH_6T2__) \\
+        || defined(__ARM_ARCH_6Z__) \\
+        || defined(__ARM_ARCH_6K__) \\
+        || defined(__ARM_ARCH_6ZK__) \\
+        || defined(__ARM_ARCH_6M__) \\
+        || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
+        #error cmake_ARCH armv6
+    #elif defined(__ARM_ARCH_5TEJ__) \\
+        || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
+        #error cmake_ARCH armv5
+    #else
+        #error cmake_ARCH arm
+    #endif
+#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
+    #error cmake_ARCH i386
+#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
+    #error cmake_ARCH x86_64
+#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
+    #error cmake_ARCH ia64
+#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
+      || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC)  \\
+      || defined(_M_MPPC) || defined(_M_PPC)
+    #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
+        #error cmake_ARCH ppc64
+    #else
+        #error cmake_ARCH ppc
+    #endif
+#endif
+
+#error cmake_ARCH unknown
+")
+
+# Set ppc_support to TRUE before including this file or ppc and ppc64
+# will be treated as invalid architectures since they are no longer supported by Apple
+
+function(target_architecture output_var)
+    if(APPLE AND CMAKE_OSX_ARCHITECTURES)
+        # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
+        # First let's normalize the order of the values
+
+        # Note that it's not possible to compile PowerPC applications if you are using
+        # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
+        # disable it by default
+        # See this page for more information:
+        # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
+
+        # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
+        # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
+
+        foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
+            if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
+                set(osx_arch_ppc TRUE)
+            elseif("${osx_arch}" STREQUAL "i386")
+                set(osx_arch_i386 TRUE)
+            elseif("${osx_arch}" STREQUAL "x86_64")
+                set(osx_arch_x86_64 TRUE)
+            elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
+                set(osx_arch_ppc64 TRUE)
+            else()
+                message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
+            endif()
+        endforeach()
+
+        # Now add all the architectures in our normalized order
+        if(osx_arch_ppc)
+            list(APPEND ARCH ppc)
+        endif()
+
+        if(osx_arch_i386)
+            list(APPEND ARCH i386)
+        endif()
+
+        if(osx_arch_x86_64)
+            list(APPEND ARCH x86_64)
+        endif()
+
+        if(osx_arch_ppc64)
+            list(APPEND ARCH ppc64)
+        endif()
+    else()
+        file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
+
+        enable_language(C)
+
+        # Detect the architecture in a rather creative way...
+        # This compiles a small C program which is a series of ifdefs that selects a
+        # particular #error preprocessor directive whose message string contains the
+        # target architecture. The program will always fail to compile (both because
+        # file is not a valid C program, and obviously because of the presence of the
+        # #error preprocessor directives... but by exploiting the preprocessor in this
+        # way, we can detect the correct target architecture even when cross-compiling,
+        # since the program itself never needs to be run (only the compiler/preprocessor)
+        try_run(
+            run_result_unused
+            compile_result_unused
+            "${CMAKE_BINARY_DIR}"
+            "${CMAKE_BINARY_DIR}/arch.c"
+            COMPILE_OUTPUT_VARIABLE ARCH
+            CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
+        )
+
+        # Parse the architecture name from the compiler output
+        string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
+
+        # Get rid of the value marker leaving just the architecture name
+        string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
+
+        # If we are compiling with an unknown architecture this variable should
+        # already be set to "unknown" but in the case that it's empty (i.e. due
+        # to a typo in the code), then set it to unknown
+        if (NOT ARCH)
+            set(ARCH unknown)
+        endif()
+    endif()
+
+    set(${output_var} "${ARCH}" PARENT_SCOPE)
+endfunction()
\ No newline at end of file
diff --git a/src/bootstrap/win/Main.cpp b/src/bootstrap/win/Main.cpp
index 5db6b52..c910a2f 100644
--- a/src/bootstrap/win/Main.cpp
+++ b/src/bootstrap/win/Main.cpp
@@ -42,6 +42,7 @@
 		fprintf(fp, "%d", privateKey[i]);
 	}
 	fprintf(fp, "\n};\n\n");
+	fprintf(fp, "#endif\n");
 	fclose(fp);
 }
 
diff --git a/src/license-generator/CMakeLists.txt b/src/license-generator/CMakeLists.txt
index a79d82d..1397d11 100644
--- a/src/license-generator/CMakeLists.txt
+++ b/src/license-generator/CMakeLists.txt
@@ -6,7 +6,7 @@
 )
 
 link_directories ( ${Boost_LIBRARY_DIRS} )
-add_dependencies( license_generator_lib private_key )
+add_dependencies( license_generator_lib boost_filesystem private_key )
 
 target_link_libraries(
      license_generator_lib
diff --git a/test/functional/CMakeLists.txt b/test/functional/CMakeLists.txt
index 18207bb..926af63 100644
--- a/test/functional/CMakeLists.txt
+++ b/test/functional/CMakeLists.txt
@@ -17,22 +17,26 @@
  license_generator_snippet
 )
 SET_TARGET_PROPERTIES(standard_license_test PROPERTIES LINK_SEARCH_START_STATIC ON)
+add_dependencies( standard_license_test boost_test boost_filesystem )
 
 add_executable(
  date_test
  date_test.cpp
 )
+
 target_link_libraries(
  date_test
  license++_static
  license_generator_snippet
 )
 SET_TARGET_PROPERTIES(date_test PROPERTIES LINK_SEARCH_START_STATIC ON)
+add_dependencies( date_test boost_test boost_filesystem )
 
 add_executable(
  volid_test
  volid_test.cpp
 )
+
 target_link_libraries(
  volid_test
  license++_static
@@ -40,6 +44,7 @@
 )
 
 SET_TARGET_PROPERTIES(volid_test PROPERTIES LINK_SEARCH_START_STATIC ON)
+add_dependencies( volid_test boost_test boost_filesystem )
 
 ADD_TEST(standard_license_test ${EXECUTABLE_OUTPUT_PATH}/standard_license_test)
 ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/date_test)

--
Gitblit v1.9.1