Skip to content

Commit

Permalink
Update Build to be in line with Cyclus (#423)
Browse files Browse the repository at this point in the history
Discovered the issue. Going to merge this in.
  • Loading branch information
scopatz authored and FlanFlanagan committed Aug 25, 2016
1 parent 25c4c7b commit 9d07b84
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 37 deletions.
46 changes: 35 additions & 11 deletions cmake/FindCyclus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,46 @@ IF(DEFINED ENV{CYCLUS_ROOT_DIR})
MESSAGE(STATUS "\t\tThe environment variable CYCLUS_ROOT_DIR: $ENV{CYCLUS_ROOT_DIR}")
ENDIF(NOT DEFINED CYCLUS_ROOT_DIR)
ELSE(DEFINED ENV{CYCLUS_ROOT_DIR})
IF(NOT DEFINED CYCLUS_ROOT_DIR)
FIND_PROGRAM(CYCLUS_BIN cyclus)
IF(CYCLUS_BIN)
EXECUTE_PROCESS(COMMAND cyclus --install-path
OUTPUT_VARIABLE CYCLUS_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
ELSE(CYCLUS_BIN)
SET(CYCLUS_ROOT_DIR "$ENV{HOME}/.local")
ENDIF(CYCLUS_BIN)
ENDIF(NOT DEFINED CYCLUS_ROOT_DIR)
FIND_PROGRAM(CYCLUS_BIN cyclus)
IF(CYCLUS_BIN)
EXECUTE_PROCESS(COMMAND cyclus --install-path
OUTPUT_VARIABLE CYCLUS_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
ELSE(CYCLUS_BIN)
SET(CYCLUS_ROOT_DIR "$ENV{HOME}/.local")
ENDIF(CYCLUS_BIN)
ENDIF(DEFINED ENV{CYCLUS_ROOT_DIR})

# Let the user know if we're using a hint
MESSAGE(STATUS "Using ${CYCLUS_ROOT_DIR} as CYCLUS_ROOT_DIR.")

# Use $DEPS_ROOT_DIR if available
if (${DEPS_ROOT_DIR})
SET(DEPS_CYCLUS "${DEPS_ROOT_DIR}"
"${DEPS_ROOT_DIR}/cyclus")
SET(DEPS_LIB_CYCLUS "${DEPS_ROOT_DIR}"
"${DEPS_ROOT_DIR}/cyclus"
"${DEPS_ROOT_DIR}/lib")
SET(DEPS_SHARE_CYCLUS "${DEPS_ROOT_DIR}/share"
"${DEPS_ROOT_DIR}/share/cyclus")
SET(DEPS_INCLUDE_CYCLUS "${DEPS_ROOT_DIR}/include"
"${DEPS_ROOT_DIR}/include/cyclus")
else (${DEPS_ROOT_DIR})
SET(DEPS_INCLUDE_CYCLUS)
endif (${DEPS_ROOT_DIR})
MESSAGE("-- Dependency Cyclus (DEPS_CYCLUS): ${DEPS_CYCLUS}")
MESSAGE("-- Dependency Library Cyclus (DEPS_LIB_CYCLUS): ${DEPS_LIB_CYCLUS}")
MESSAGE("-- Dependency Share Cyclus (DEPS_SHARE_CYCLUS): ${DEPS_SHARE_CYCLUS}")
MESSAGE("-- Dependency Include Cyclus (DEPS_INCLUDE_CYCLUS): ${DEPS_INCLUDE_CYCLUS}")


# Set the include dir, this will be the future basis for other
# defined dirs
FIND_PATH(CYCLUS_CORE_INCLUDE_DIR cyclus.h
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
"${CYCLUS_ROOT_DIR}/include"
"${CYCLUS_ROOT_DIR}/include/cyclus"
${DEPS_INCLUDE_CYCLUS}
/usr/local/cyclus /opt/local/cyclus
PATH_SUFFIXES cyclus/include include include/cyclus)

Expand All @@ -46,6 +65,7 @@ FIND_PATH(CYCLUS_CORE_TEST_INCLUDE_DIR agent_tests.h
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus/tests"
"${CYCLUS_ROOT_DIR}/include"
"${CYCLUS_ROOT_DIR}/include/cyclus/tests"
${DEPS_INCLUDE_CYCLUS}
/usr/local/cyclus /opt/local/cyclus
PATH_SUFFIXES cyclus/include include include/cyclus include/cyclus/tests cyclus/include/tests)

Expand All @@ -56,19 +76,22 @@ SET(CYCLUS_ROOT_DIR "${CYCLUS_CORE_INCLUDE_DIR}/../..")
FIND_PATH(CYCLUS_CORE_SHARE_DIR cyclus.rng.in
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
"${CYCLUS_ROOT_DIR}/share" "${CYCLUS_ROOT_DIR}/share/cyclus"
${DEPS_SHARE_CYCLUS}
/usr/local/cyclus /opt/local/cyclus
PATH_SUFFIXES cyclus/share share)

# Look for the library
FIND_LIBRARY(CYCLUS_CORE_LIBRARY NAMES cyclus
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
${DEPS_CYCLUS}
/usr/local/cyclus/lib /usr/local/cyclus
/opt/local /opt/local/cyclus
PATH_SUFFIXES cyclus/lib lib)

# Look for the library
FIND_LIBRARY(CYCLUS_AGENT_TEST_LIBRARY NAMES baseagentunittests
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
${DEPS_CYCLUS}
/usr/local/cyclus/lib /usr/local/cyclus
/opt/local /opt/local/cyclus
PATH_SUFFIXES cyclus/lib lib lib/cyclus)
Expand All @@ -77,7 +100,8 @@ FIND_LIBRARY(CYCLUS_AGENT_TEST_LIBRARY NAMES baseagentunittests
FIND_LIBRARY(CYCLUS_GTEST_LIBRARY NAMES gtest
HINTS "${CYCLUS_ROOT_DIR}/lib/cyclus"
"${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
"${CYCLUS_ROOT_DIR}/lib" "${CYCLUS_CORE_SHARE_DIR}/../lib"
"${CYCLUS_ROOT_DIR}/lib" "${CYCLUS_CORE_SHARE_DIR}/../lib"
${DEPS_LIB_CYCLUS}
/usr/local/cyclus/lib /usr/local/cyclus
/opt/local/lib /opt/local/cyclus/lib
PATH_SUFFIXES cyclus/lib lib)
Expand Down
114 changes: 88 additions & 26 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#! /usr/bin/env python
from __future__ import print_function, unicode_literals
import os
import sys
import tarfile
import platform
import subprocess
import shutil
import io
if sys.version_info[0] < 3:
from urllib import urlopen
else:
from urllib.request import urlopen

try:
import argparse as ap
Expand All @@ -11,6 +19,7 @@

absexpanduser = lambda x: os.path.abspath(os.path.expanduser(x))


def check_windows_cmake(cmake_cmd):
if os.name == 'nt':
files_on_path = set()
Expand All @@ -25,44 +34,71 @@ def check_windows_cmake(cmake_cmd):
cmake_cmd += ['-G "MinGW Makefiles"']
cmake_cmd = ' '.join(cmake_cmd)

def install_cycamore(args):
def update_describe():
root_dir = os.path.split(__file__)[0]
fname = os.path.join(root_dir, 'src', 'version.cc.in')
cmd = 'touch {0}'.format(fname)
subprocess.check_call(cmd.split(), shell=(os.name == 'nt'))

def install_cyclus(args):
if not os.path.exists(args.build_dir):
os.mkdir(args.build_dir)
elif args.clean_build:
shutil.rmtree(args.build_dir)
os.mkdir(args.build_dir)

root_dir = os.path.split(__file__)[0]
src_dir = os.path.join(root_dir, 'src')
makefile = os.path.join(args.build_dir, 'Makefile')
on_darwin = platform.system() == 'Darwin'
libext = '.dylib' if on_darwin else '.so'

if not os.path.exists(makefile):
cmake_cmd = ['cmake', absexpanduser(root_dir)]
rtn = subprocess.call(['which', 'cmake'], shell=(os.name == 'nt'))
if rtn != 0:
sys.exit("CMake could not be found, "
"please install CMake before developing Cyclus.")
cmake_cmd = ['cmake', os.path.abspath(root_dir)]
if args.prefix:
cmake_cmd += ['-DCMAKE_INSTALL_PREFIX=' + absexpanduser(args.prefix)]
cmake_cmd += ['-DCMAKE_INSTALL_PREFIX=' +
absexpanduser(args.prefix)]
if args.cmake_prefix_path:
cmake_cmd += ['-DCMAKE_PREFIX_PATH=' + absexpanduser(args.cmake_prefix_path)]
cmake_cmd += ['-DCMAKE_PREFIX_PATH=' +
absexpanduser(args.cmake_prefix_path)]
cmake_cmd += ['-DDEFAULT_ALLOW_MILPS=' +
('TRUE' if args.allow_milps else 'FALSE')]
if args.deps_root:
cmake_cmd += ['-DDEPS_ROOT_DIR=' + absexpanduser(args.deps_root)]
if args.coin_root:
cmake_cmd += ['-DCOIN_ROOT_DIR=' + absexpanduser(args.coin_root)]
if args.boost_root:
cmake_cmd += ['-DBOOST_ROOT=' + absexpanduser(args.boost_root)]
if args.cyclus_root:
cmake_cmd += ['-DCYCLUS_ROOT_DIR='+absexpanduser(args.cyclus_root)]
if args.hdf5_root:
h5root = absexpanduser(args.hdf5_root)
cmake_cmd += ['-DHDF5_ROOT=' + h5root,
'-DHDF5_LIBRARIES={0}/lib/libhdf5{1};{0}/lib/libhdf5_hl{1}'.format(h5root, libext),
'-DHDF5_LIBRARY_DIRS=' + h5root + '/lib',
'-DHDF5_INCLUDE_DIRS=' + h5root + '/include',
]
if args.build_type:
cmake_cmd += ['-DCMAKE_BUILD_TYPE=' + args.build_type]
if args.D is not None:
cmake_cmd += ['-D' + x for x in args.D]
check_windows_cmake(cmake_cmd)
rtn = subprocess.check_call(cmake_cmd, cwd=absexpanduser(args.build_dir),
shell=(os.name=='nt'))
rtn = subprocess.check_call(cmake_cmd, cwd=args.build_dir,
shell=(os.name == 'nt'))

if args.config_only:
return

if args.update:
update_describe()

make_cmd = ['make']
if args.threads:
make_cmd += ['-j' + str(args.threads)]
rtn = subprocess.call(make_cmd, cwd=args.build_dir,
rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
shell=(os.name == 'nt'))

if args.test:
Expand All @@ -73,19 +109,19 @@ def install_cycamore(args):
rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
shell=(os.name == 'nt'))

def uninstall_cycamore(args):
def uninstall_cyclus(args):
makefile = os.path.join(args.build_dir, 'Makefile')
if not os.path.exists(args.build_dir) or not os.path.exists(makefile):
sys.exit("May not uninstall cycamore since it has not yet been built.")
sys.exist("May not uninstall Cyclus since it has not yet been built.")
rtn = subprocess.check_call(['make', 'uninstall'], cwd=args.build_dir,
shell=(os.name == 'nt'))


def main():
localdir = absexpanduser('~/.local')

description = "A Cycamore installation helper script. "+\
description = "A Cyclus installation helper script. " +\
"For more information, please see cyclus.github.com."

parser = ap.ArgumentParser(description=description)

build_dir = 'where to place the build directory'
Expand All @@ -94,48 +130,74 @@ def main():
uninst = 'uninstall'
parser.add_argument('--uninstall', action='store_true', help=uninst, default=False)

clean = 'remove the build directory before building'
noupdate = 'do not update the hash in version.cc'
parser.add_argument('--no-update', dest='update', action='store_false',
help=noupdate, default=True)

clean = 'attempt to remove the build directory before building'
parser.add_argument('--clean-build', action='store_true', help=clean)

threads = "the number of threads to use in the make step"
parser.add_argument('-j', '--threads', type=int, help=threads)

install = "the relative path to the installation directory"
parser.add_argument('--prefix', help=install, default=localdir)

test = 'run tests after building'
parser.add_argument('--test', action='store_true', help=test)
prefix = "the relative path to the installation directory"
parser.add_argument('--prefix', help=prefix, default=localdir)

config_only = 'only configure the package, do not build or install'
parser.add_argument('--config-only', action='store_true', help=config_only)

build_only = 'only build the package, do not install'
parser.add_argument('--build-only', action='store_true', help=build_only)

coin = "the relative path to the Coin-OR libraries directory"
parser.add_argument('--coin_root', help=coin)
test = 'run tests after building'
parser.add_argument('--test', action='store_true', help=test)

cyclus = "the relative path to Cyclus installation directory"
parser.add_argument('--cyclus_root',help=cyclus, default=localdir)
parser.add_argument('--allow-milps', action='store_true',
dest='allow_milps', default=True,
help='Allows mixed integer linear programs by default')
parser.add_argument('--dont-allow-milps', action='store_false',
dest='allow_milps',
help="Don't Allows mixed integer linear programs "
"by default")

deps = "the path to the directory containing all dependencies"
parser.add_argument('--deps-root', '--deps_root', help=deps,
default=None, dest='deps_root')

coin = "the relative path to the Coin-OR libraries directory"
parser.add_argument('--coin-root', '--coin_root', help=coin)

boost = "the relative path to the Boost libraries directory"
parser.add_argument('--boost_root', help=boost)

hdf5 = "the path to the HDF5 libraries directory"
parser.add_argument('--hdf5_root', help=hdf5)

cyclus = "the relative path to Cyclus installation directory"
parser.add_argument('--cyclus-root', '--cyclus_root', help=cyclus)

cmake_prefix_path = "the cmake prefix path for use with FIND_PACKAGE, " + \
"FIND_PATH, FIND_PROGRAM, or FIND_LIBRARY macros"
parser.add_argument('--cmake_prefix_path', help=cmake_prefix_path)

build_type = "the CMAKE_BUILD_TYPE"
parser.add_argument('--build_type', help=build_type)
parser.add_argument('--build-type', '--build_type', help=build_type)

parser.add_argument('-D', metavar='VAR', action='append',
help='Set enviornment variable(s).')
help='Set enviornment variable(s).')

args = parser.parse_args()
# modify roots as needed
if args.deps_root is not None:
roots = ['coin_root', 'boost_root', 'hdf5_root', 'cyclus_root']
for name in roots:
if not getattr(args, name, None):
setattr(args, name, args.deps_root)
# run code
if args.uninstall:
uninstall_cycamore(args)
uninstall_cyclus(args)
else:
install_cycamore(args)
install_cyclus(args)

if __name__ == "__main__":
main()

0 comments on commit 9d07b84

Please sign in to comment.