-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Update CMakeLists.txt #3109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Update CMakeLists.txt #3109
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,40 @@ | ||
|
|
||
| CMAKE_MINIMUM_REQUIRED(VERSION 3.10.0) | ||
|
|
||
| if (WIN32 AND NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio") | ||
| message(FATAL_ERROR "\n" | ||
| "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" | ||
| "You must use Visual Studio to build a python extension on windows. If you " | ||
| "are getting this error it means you have not installed Visual C++. Note that " | ||
| "there are many flavors of Visual Studio, like Visual Studio for C\# development. " | ||
| "You need to install Visual Studio for C++. \n" | ||
| "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") | ||
| endif() | ||
|
|
||
| project(dlib_python_bindings) | ||
|
|
||
| # Pybind11's cmake scripts enable link time optimization by default. However, | ||
| # it makes linking take a really long time and doesn't seem to substantively | ||
| # improve runtime performance. So we disable LTO here to make building dlib | ||
| # faster. | ||
| set(PYBIND11_LTO_CXX_FLAGS "") | ||
| # Detect if building for Android | ||
| if(CMAKE_SYSTEM_NAME STREQUAL "Android") | ||
| message(STATUS "Building dlib Python bindings for Android") | ||
|
|
||
| # Paths to Python include and library (from environment) | ||
| if(NOT DEFINED ENV{PYTHON_INCLUDE_DIR}) | ||
| message(FATAL_ERROR "PYTHON_INCLUDE_DIR environment variable not set") | ||
| endif() | ||
| if(NOT DEFINED ENV{PYTHON_LIBRARY}) | ||
| message(FATAL_ERROR "PYTHON_LIBRARY environment variable not set") | ||
| endif() | ||
|
|
||
| # Avoid cmake warnings about changes in behavior of some Mac OS X path | ||
| # variable we don't care about. | ||
| if (POLICY CMP0042) | ||
| cmake_policy(SET CMP0042 NEW) | ||
| endif() | ||
| set(PYTHON_INCLUDE_DIR $ENV{PYTHON_INCLUDE_DIR}) | ||
| set(PYTHON_LIBRARY $ENV{PYTHON_LIBRARY}) | ||
|
|
||
| # Paths to pybind11 include | ||
| if(NOT DEFINED ENV{PYBIND11_INCLUDE_DIR}) | ||
| message(FATAL_ERROR "PYBIND11_INCLUDE_DIR environment variable not set") | ||
| endif() | ||
| set(PYBIND11_INCLUDE_DIR $ENV{PYBIND11_INCLUDE_DIR}) | ||
|
|
||
| include_directories(${PYTHON_INCLUDE_DIR} ${PYBIND11_INCLUDE_DIR}) | ||
| else() | ||
| # Desktop build: include pybind11 normally | ||
| add_subdirectory(../../dlib/external/pybind11 pybind11_build) | ||
| #include_directories(${PYBIND11_INCLUDE_DIR}) | ||
| endif() | ||
|
|
||
| add_subdirectory(../../dlib/external/pybind11 pybind11_build) | ||
| # Add dlib core | ||
| add_subdirectory(../../dlib dlib_build) | ||
|
|
||
| add_definitions(-DDLIB_VERSION=${DLIB_VERSION}) | ||
|
|
||
| # Tell cmake to compile all these cpp files into a dlib python module. | ||
| # Source files | ||
| set(python_srcs | ||
| src/dlib.cpp | ||
| src/matrix.cpp | ||
|
|
@@ -62,17 +63,22 @@ set(python_srcs | |
| src/line.cpp | ||
| ) | ||
|
|
||
| # Only add the GUI module if requested | ||
| if(NOT ${DLIB_NO_GUI_SUPPORT}) | ||
| list(APPEND python_srcs src/gui.cpp) | ||
| endif() | ||
|
|
||
| pybind11_add_module(_dlib_pybind11 ${python_srcs}) | ||
| target_link_libraries(_dlib_pybind11 PRIVATE dlib::dlib) | ||
| # --- Module target --- | ||
| if(CMAKE_SYSTEM_NAME STREQUAL "Android") | ||
| # Android: build shared library manually | ||
| add_library(_dlib_pybind11 SHARED ${python_srcs}) | ||
| target_link_libraries(_dlib_pybind11 PRIVATE dlib::dlib ${PYTHON_LIBRARY}) | ||
| else() | ||
| # Desktop: use pybind11 helper | ||
| pybind11_add_module(_dlib_pybind11 ${python_srcs}) | ||
| target_link_libraries(_dlib_pybind11 PRIVATE dlib::dlib) | ||
| endif() | ||
|
|
||
| # When invoked from setup.py CMAKE_LIBRARY_OUTPUT_DIRECTORY will be set. But when you are just building via say | ||
| # `cd dlib/tools/python; mkdir build; cd build; cmake ..` it won't be set. It only matters for building the actual | ||
| # distribution. So skip this for people building directly with cmake (which they might do when testing stuff). | ||
| # Copy __init__.py for Python package | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't remove comments. |
||
| if (CMAKE_LIBRARY_OUTPUT_DIRECTORY) | ||
| configure_file(${PROJECT_SOURCE_DIR}/dlib/__init__.py.in ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/dlib/__init__.py) | ||
| endif() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very much needed for windows users.