Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Doing so will make some things run faster.

Finally, Visual Studio users should usually do everything in 64bit mode. By default Visual Studio is 32bit, both in its outputs and its own execution, so you have to explicitly tell it to use 64bits. Since it's not the 1990s anymore you probably want to use 64bits. Do that with a cmake invocation like this:
```bash
cmake .. -G "Visual Studio 14 2015 Win64" -T host=x64
cmake .. -G "Visual Studio 14 2015 Win64" -T host=x64
```

## Compiling your own C++ programs that use dlib
Expand All @@ -48,6 +48,10 @@ cd dlib
pip install .
```

It's possible to change build settings by passing parameters to `setup.py` or `DLIB_*` environment variables.
For example, setting the environment variable `DLIB_NO_GUI_SUPPORT` to `ON` will add the cmake option
`-DDLIB_NO_GUI_SUPPORT=ON`.


## Running the unit test suite

Expand All @@ -69,4 +73,3 @@ This library is licensed under the Boost Software License, which can be found in
## dlib sponsors

This research is based in part upon work supported by the Office of the Director of National Intelligence (ODNI), Intelligence Advanced Research Projects Activity (IARPA) under contract number 2014-14071600010. The views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of ODNI, IARPA, or the U.S. Government.

44 changes: 24 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
To build and install:
python setup.py install
To upload the source distribution to PyPi
python setup.py sdist
python setup.py sdist
twine upload dist/dlib-*.tar.gz
To exclude certain options in the cmake config use --no:
for example:
Expand All @@ -25,21 +25,21 @@
--set: set arbitrary cmake options e.g. --set CUDA_HOST_COMPILER=/usr/bin/gcc-6.4.0
passes -DCUDA_HOST_COMPILER=/usr/bin/gcc-6.4.0 to CMake.
"""
import errno
import logging
import multiprocessing
import os
import platform
import re
import sys
import errno
import stat
import shutil
import platform
import stat
import subprocess
import multiprocessing
import sys
from math import floor

from packaging.version import Version, parse as parse_version
from setuptools import find_packages, setup, Extension
from setuptools.command.build_ext import build_ext
import logging

logging.basicConfig(level=logging.INFO)
log = logging.getLogger("setup")
Expand Down Expand Up @@ -89,8 +89,6 @@ def get_extra_cmake_options():

return _cmake_extra_options, _clean_build_folder

cmake_extra_options,clean_build_folder = get_extra_cmake_options()


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Expand Down Expand Up @@ -143,7 +141,7 @@ def get_cmake_version(self):
packager delete it and install an official cmake.

More generally, cmake is not installed if when you open a terminal window
and type
and type
cmake --version
you get an error. So you can use that as a very basic test to see if you
have cmake installed. That is, if cmake --version doesn't run from the
Expand All @@ -157,7 +155,7 @@ def get_cmake_version(self):
================================================================================
================================================================================
================================================================================
""")
""")
sys.exit(1)
return re.search(r'version\s*([\d.]+)', out.decode()).group(1)

Expand All @@ -172,13 +170,19 @@ def run(self):
self.build_extension(ext)

def build_extension(self, ext):
# Build CMake args based on default settings, environment variables and CLI parameters
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))

cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DDLIB_USE_FFMPEG=OFF',]

cmake_args += cmake_extra_options
cmake_extra_options, clean_build_folder = get_extra_cmake_options()
cmake_args_dict = {
'CMAKE_LIBRARY_OUTPUT_DIRECTORY': extdir,
'DLIB_USE_FFMPEG': 'OFF',
'PYTHON_EXECUTABLE': sys.executable,
}
for key, value in os.environ.items():
if key.startswith("DLIB_"):
cmake_args_dict[key] = value
cmake_args = ['-D' + key + '=' + str(value) for key, value in cmake_args_dict.items()]
cmake_args += cmake_extra_options

cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
Expand All @@ -188,7 +192,7 @@ def build_extension(self, ext):
if sys.maxsize > 2**32:
cmake_args += ['-A', 'x64']
# Do a parallel build
build_args += ['--', '/m']
build_args += ['--', '/m']
else:
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
# Do a parallel build
Expand Down Expand Up @@ -220,9 +224,9 @@ def num_available_cpu_cores(ram_per_build_process_in_gb):
elif 'CMAKE_BUILD_PARALLEL_LEVEL' in os.environ and os.environ['CMAKE_BUILD_PARALLEL_LEVEL'].isnumeric():
return int(os.environ['CMAKE_BUILD_PARALLEL_LEVEL'])
try:
mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
mem_gib = mem_bytes/(1024.**3)
num_cores = multiprocessing.cpu_count()
num_cores = multiprocessing.cpu_count()
# make sure we have enough ram for each build process.
mem_cores = int(floor(mem_gib/float(ram_per_build_process_in_gb)+0.5));
# We are limited either by RAM or CPU cores. So pick the limiting amount
Expand Down
Loading