cmake.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Yujin Robot, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Yujin Robot nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 ##############################################################################
00034 # Imports
00035 ##############################################################################
00036 
00037 import sys
00038 import os
00039 import subprocess
00040 import shutil
00041 import cmake_var
00042 import glob
00043 
00044 ##############################################################################
00045 # Public Functions
00046 ##############################################################################
00047 
00048 def execute_cmake(src_path, build_path):
00049     if not os.path.isdir(build_path):
00050         os.mkdir(build_path)
00051     ws_path = os.path.join(parent_directory(build_path))
00052     override_cmake_str =  '-DCMAKE_USER_MAKE_RULES_OVERRIDE:STRING="' + override_filename() + '" '
00053     cache_cmake_str =  '-C "' + os.path.join(ws_path, 'config.cmake') + '" '
00054     devel_prefix = '-DCATKIN_DEVEL_PREFIX=' + os.path.join(ws_path, 'devel') + ' '
00055     cmake_command = 'cmake -G "NMake Makefiles" ' + cache_cmake_str + override_cmake_str + devel_prefix + src_path
00056     print("\nExecuting cmake on the workspace source directory:\n")
00057     print("  %s\n" % cmake_command)
00058     os.chdir(build_path) 
00059     proc = subprocess.Popen(cmake_command, shell=True)
00060     proc.wait()
00061 
00062 def execute_nmake(build_path):
00063     if not os.path.isdir(build_path):
00064         execute_cmake(src_path, build_path)
00065     if not os.path.isfile(os.path.join(build_path, 'CMakeCache.txt')):
00066         execute_cmake(src_path, build_path)
00067     os.chdir(build_path) 
00068     print("\nExecuting nmake in the root build directory\n")
00069     proc = subprocess.Popen('nmake', shell=True)
00070     proc.wait()
00071 
00072 def execute_nmake_install(build_path):
00073     if not os.path.isdir(build_path):
00074         execute_cmake(src_path, build_path)
00075     if not os.path.isfile(os.path.join(build_path, 'CMakeCache.txt')):
00076         execute_cmake(src_path, build_path)
00077     os.chdir(build_path) 
00078     print("\nExecuting nmake in the root build directory and install\n")
00079     proc = subprocess.Popen('nmake install', shell=True)
00080     returncode = proc.wait()
00081     if returncode == 0:
00082         copy_debuginfo(build_path)
00083     
00084 def override_filename():
00085     return os.path.join(os.path.dirname(__file__), 'cmake', 'MsvcOverrides.cmake')
00086 
00087 def parent_directory(path):
00088     return os.path.abspath(os.path.join(path, os.pardir))
00089 
00090 def copy_debuginfo(build_path):
00091     ws_path = os.path.join(parent_directory(build_path))
00092     pdb_path = os.path.join(ws_path, 'devel', 'bin', '*.pdb')
00093     install_root = cmake_var.get_value(os.path.join(ws_path, 'config.cmake'), 'INSTALL_ROOT')
00094     install_path = os.path.join(install_root, 'bin')
00095     pdb_files = glob.glob(pdb_path)
00096     print("Install the debug info files...")
00097     for i in pdb_files:
00098         dst_name = os.path.join(install_path, os.path.basename(i))
00099         if os.path.isfile(dst_name) == True:
00100             print("-- Up-to-date: " + dst_name)
00101         else:
00102             print("-- Installing: " + dst_name)
00103         shutil.copy(i, dst_name)
00104     


win_python_build_tools
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:09:59