From 1ae5de2f59799a5d02e64cfa36bd1d3b36827f43 Mon Sep 17 00:00:00 2001
From: open-license-manager <rillf@maildrop.cc>
Date: 周三, 13 8月 2014 16:21:41 +0800
Subject: [PATCH] build linux

---
 build/modules/add_boost.cmake |  133 ++++++++++++++++++++++++++-----------------
 1 files changed, 80 insertions(+), 53 deletions(-)

diff --git a/build/modules/add_boost.cmake b/build/modules/add_boost.cmake
index fa87ee6..c3aa699 100644
--- a/build/modules/add_boost.cmake
+++ b/build/modules/add_boost.cmake
@@ -1,4 +1,10 @@
 
+#   Boost_INCLUDE_DIRS     - Boost include directories
+#   Boost_LIBRARY_DIRS     - Link directories for Boost libraries
+#   Boost_LIBRARIES        - Boost component libraries to be linked
+#FIXME: for boost find compatibility C must be upper case
+#   Boost_<C>_LIBRARY      - Libraries to link for component <C> (c is lower-case,may include
+#                            target_link_libraries debug/optimized keywords)
 
 function(ms_underscores_to_camel_case VarIn VarOut)
   string(REPLACE "_" ";" Pieces ${VarIn})
@@ -148,14 +154,27 @@
 
 
 # Expose BoostSourceDir to parent scope
-set(BoostSourceDir ${BoostSourceDir} ) #PARENT_SCOPE
+#set(BoostSourceDir ${BoostSourceDir} ) #PARENT_SCOPE
+if(Boost_USE_STATIC_RUNTIME)
+    set(RUNTIME_LINK "static")
+    set(BOOST_LIB_SUFFIX "-s")
+else()
+    set(RUNTIME_LINK "shared")
+    set(BOOST_LIB_SUFFIX "")
+endif()
+if(Boost_USE_STATIC_LIBS)
+    set(BOOST_LINK "static")
+    set(BOOST_LIB_EXTENSION "a")
+else()
+    set(BOOST_LINK "shared")
+    set(BOOST_LIB_EXTENSION "so")
+endif()
 
 # Set up general b2 (bjam) command line arguments
-set(b2Args <SOURCE_DIR>/b2
-           link=static
+set(b2Args ./b2
+           link=${BOOST_LINK}
            threading=multi
-#careful if changing this to static add "-s" to output files under Linux
-           runtime-link=dynamic 
+           runtime-link=${RUNTIME_LINK}
            --build-dir=Build
            stage
            -d+2
@@ -200,68 +219,76 @@
   endif()
 endif()
 
-#Get list of components
+# 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}")
 
-string(REGEX REPLACE "python;" "" BoostComponents "${BoostComponents}")
-string(REGEX REPLACE "graph_parallel;" "" BoostComponents "${BoostComponents}")
-string(REGEX REPLACE "graph;" "" BoostComponents "${BoostComponents}")
-
 # Build each required component
 include(ExternalProject)
 foreach(Component ${BoostComponents})
   ms_underscores_to_camel_case(${Component} CamelCaseComponent)
-  add_library(Boost${CamelCaseComponent} STATIC IMPORTED GLOBAL)
-
-  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
-      )
+  if(${Boost_USE_STATIC_LIBS})
+      add_library(boost_${Component} STATIC IMPORTED GLOBAL)
+  else(${Boost_USE_STATIC_LIBS})
+      add_library(boost_${Component} SHARED IMPORTED GLOBAL)
+  endif(${Boost_USE_STATIC_LIBS})
+  if(${Component} STREQUAL "test")
+      set(LibName "unit_test_framework")
+  else()
+      set(LibName ${Component})  
+  endif()
   if(MSVC)
     if(MSVC11)
       set(CompilerName vc110)
     elseif(MSVC12)
       set(CompilerName vc120)
     endif()
+    ExternalProject_Add(
+          Boost${CamelCaseComponent}
+          PREFIX ${CMAKE_BINARY_DIR}/${BoostFolderName}
+          SOURCE_DIR ${BoostSourceDir}
+          BINARY_DIR ${BoostSourceDir}
+          CONFIGURE_COMMAND ""
+          BUILD_COMMAND "${b2Args}" --with-${Component}
+          INSTALL_COMMAND ""
+          LOG_BUILD ON )
+    
     string(REGEX MATCH "[0-9]_[0-9][0-9]" Version "${BoostFolderName}")
-    set_target_properties(Boost${CamelCaseComponent} PROPERTIES
+    set_target_properties(boost_${Component} 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)
-
-    #message ( STATUS boost_${Component} ${BoostSourceDir}/stage/lib/libboost_${ComponentLib}-mt.a)
-  endif()
-  
+  else(MSVC)
+        set(OUTPUT_FILE ${BoostSourceDir}/stage/lib/libboost_${LibName}-mt${BOOST_LIB_SUFFIX}.${BOOST_LIB_EXTENSION})
+        add_custom_command(OUTPUT ${OUTPUT_FILE}
+                   COMMAND ${b2Args} --with-${Component}
+                   WORKING_DIRECTORY ${BoostSourceDir}
+                   )
+        add_custom_target(Boost${CamelCaseComponent} 
+            DEPENDS ${OUTPUT_FILE} 
+            WORKING_DIRECTORY ${BoostSourceDir})      
+        set_target_properties(boost_${Component} PROPERTIES
+                          IMPORTED_LOCATION ${OUTPUT_FILE}
+                          #LINK_SEARCH_START_STATIC OFF
+                          LINKER_LANGUAGE CXX
+                          )
+  endif(MSVC)
   set_target_properties(boost_${Component} Boost${CamelCaseComponent} PROPERTIES
-                        LABELS Boost 
-                        FOLDER "/home/devel/prj/license-manager-cpp/build/linux" 
-                        EXCLUDE_FROM_ALL TRUE)
-  add_dependencies(Boost${CamelCaseComponent} boost_${Component})
-  set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent})
+                        LABELS Boost FOLDER "Boost" EXCLUDE_FROM_ALL TRUE)
+  add_dependencies(boost_${Component} Boost${CamelCaseComponent})
+  set(Boost_${Component}_LIBRARY boost_${Component})
   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})
+      set(Boost_${Component}_LIBRARY boost_${Component} ${IconvLib})
     elseif(UNIX)
       if(BSD)
         find_library(IconvLib libiconv.a)
@@ -270,7 +297,7 @@
           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})
+        set(Boost_${Component}_LIBRARY boost_${Component} ${IconvLib})
       else()
         find_library(Icui18nLib libicui18n.a)
         find_library(IcuucLib libicuuc.a)
@@ -280,28 +307,28 @@
           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})
+        set(Boost_${Component}_LIBRARY boost_${Component} ${Icui18nLib} ${IcuucLib} ${IcudataLib})
       endif()
     else()
-      set(Boost${CamelCaseComponent}Libs Boost${CamelCaseComponent})
+      set(Boost_${Component}_LIBRARY boost_${Component})
     endif()
   endif()
-  set(Boost${CamelCaseComponent}Libs ${Boost${CamelCaseComponent}Libs}) # PARENT_SCOPE
-  list(APPEND AllBoostLibs Boost${CamelCaseComponent})
+  #set(Boost${CamelCaseComponent}Libs ${Boost${CamelCaseComponent}Libs}) # PARENT_SCOPE
+  list(APPEND Boost_LIBRARIES Boost_${Component}_LIBRARY)
 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)
+add_dependencies(BoostChrono BoostSystem)
+add_dependencies(BoostCoroutine BoostContext BoostSystem)
+add_dependencies(BoostFilesystem BoostSystem)
+add_dependencies(BoostGraph BoostRegex)
+add_dependencies(BoostLocale BoostSystem)
+add_dependencies(BoostLog BoostChrono BoostDateTime BoostFilesystem BoostThread)
+add_dependencies(BoostThread BoostChrono)
+add_dependencies(BoostTimer BoostChrono)
+add_dependencies(BoostWave BoostChrono BoostDateTime BoostFilesystem BoostThread)
 
 set(Boost_INCLUDE_DIRS ${BoostSourceDir})
-set(Boost_LIBRARY_DIRS ${BoostSourceDir}/stage)
+set(Boost_LIBRARY_DIRS ${BoostSourceDir}/stage/lib)
 
 
 

--
Gitblit v1.9.1