@@ -31,6 +31,18 @@ endif()
3131set (TARGET_NAME depthai)
3232project (depthai VERSION "0" ) # revision of bindings [depthai-core].[rev]
3333
34+ # Set default build type depending on context
35+ set (default_build_type "Release" )
36+ if (EXISTS "${CMAKE_SOURCE_DIR} /.git" AND NOT DEFINED ENV{CI})
37+ set (default_build_type "Debug" )
38+ endif ()
39+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
40+ message (STATUS "Setting build type to '${default_build_type} ' as none was specified." )
41+ set (CMAKE_BUILD_TYPE "${default_build_type} " CACHE STRING "Choose the type of build." FORCE )
42+ # Set the possible values of build type for cmake-gui
43+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
44+ endif ()
45+
3446# Add module paths
3547list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake/" )
3648list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /depthai-core/cmake" )
@@ -63,13 +75,13 @@ endif()
6375hunter_add_package (pybind11 )
6476
6577# Disable LTO if MINGW compiler
66- if (MINGW)
78+ if (MINGW)
6779 set (PYBIND11_LTO_CXX_FLAGS "" CACHE STRING "" FORCE )
6880endif ()
6981find_package (pybind11 CONFIG REQUIRED )
7082
7183# Add files for python module
72- pybind11_add_module (${TARGET_NAME}
84+ pybind11_add_module (${TARGET_NAME}
7385 src/py_bindings.cpp
7486 src/XLinkConnectionBindings.cpp
7587 src/DeviceBindings.cpp
@@ -92,8 +104,8 @@ endif()
92104
93105if (DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT)
94106 # If output is specified set both input and output to same the path
95- set (docstring_input_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
96- set (docstring_output_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
107+ set (docstring_input_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
108+ set (docstring_output_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
97109else ()
98110 # If input docstrings explicitly specified, use those and disable building
99111 if (DEPTHAI_PYTHON_DOCSTRINGS_INPUT)
@@ -102,11 +114,11 @@ else()
102114 set (DEPTHAI_PYTHON_BUILD_DOCSTRINGS OFF CACHE BOOL "Generate docstrings from header files if module 'pybind11_mkdoc' available" FORCE )
103115 else ()
104116 # Otherwise set default location as input
105- set (docstring_input_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
117+ set (docstring_input_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
106118 endif ()
107119
108120 # Set default output location
109- set (docstring_output_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
121+ set (docstring_output_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
110122endif ()
111123
112124if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
@@ -118,11 +130,14 @@ configure_file(cmake/docstring.hpp.in ${DOCSTRINGS_INCLUDE_PLACEHOLDER_PATH})
118130# Add target to generate docstrings
119131if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
120132 include (pybind11-mkdoc )
121-
133+
122134 # Check if pybind11_mkdoc available and create target
123135 target_pybind11_mkdoc_setup (${docstring_output_path} depthai::core ${DEPTHAI_PYTHON_FORCE_DOCSTRINGS} )
124-
125- if (NOT TARGET pybind11_mkdoc)
136+
137+ if (TARGET pybind11_mkdoc)
138+ # Add dependency to mkdoc target (makes sure that mkdoc is executed, and docstrings available)
139+ add_dependencies (${TARGET_NAME} pybind11_mkdoc )
140+ else ()
126141 # Generate default docstrings to OUTPUT path
127142 configure_file (cmake/default_docstring.hpp.in ${docstring_output_path} COPYONLY )
128143 endif ()
@@ -135,17 +150,39 @@ endif()
135150target_include_directories (${TARGET_NAME} PRIVATE src ${DOCSTRINGS_INCLUDE_PLACEHOLDER_DIR} )
136151
137152# Link with libraries
138- target_link_libraries (${TARGET_NAME}
139- PUBLIC
153+ target_link_libraries (${TARGET_NAME}
154+ PUBLIC
140155 # pybind11
141156 pybind11::pybind11
142157 depthai::core # Use non-opencv target as we use opencv-python in bindings
143158 hedley
144159)
145160
146- # Add default commit hash ('dev') if not build by CI
147- if (NOT DEFINED ENV{CI} AND NOT DEPTHAI_PYTHON_COMMIT_HASH)
148- set (DEPTHAI_PYTHON_COMMIT_HASH "dev" )
161+ # Find Git
162+ find_package (Git )
163+
164+ # Add build information (commit, date)
165+ set (BUILD_COMMIT "dev" )
166+ if (GIT_FOUND)
167+ execute_process (
168+ COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
169+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
170+ OUTPUT_VARIABLE BUILD_COMMIT
171+ ERROR_QUIET
172+ OUTPUT_STRIP_TRAILING_WHITESPACE
173+ )
174+ execute_process (
175+ COMMAND ${GIT_EXECUTABLE} show -s --format=%ci ${BUILD_COMMIT}
176+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
177+ OUTPUT_VARIABLE BUILD_COMMIT_DATETIME
178+ ERROR_QUIET
179+ OUTPUT_STRIP_TRAILING_WHITESPACE
180+ )
181+ endif ()
182+
183+ # Add local commit hash (or 'dev' if unable to retrieve) if not build by CI
184+ if (NOT DEFINED ENV{CI} AND NOT DEPTHAI_PYTHON_COMMIT_HASH)
185+ set (DEPTHAI_PYTHON_COMMIT_HASH ${BUILD_COMMIT} )
149186endif ()
150187
151188# Get version to use
@@ -159,8 +196,15 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} "-c" "${version_command}"
159196 WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
160197)
161198
162- # Add version definition
163- target_compile_definitions (${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_VERSION= "${DEPTHAI_PYTHON_VERSION} " )
199+
200+ string (TIMESTAMP BUILD_DATETIME "%Y-%m-%d %H:%M:%S +0000" UTC )
201+ target_compile_definitions (${TARGET_NAME}
202+ PRIVATE
203+ DEPTHAI_PYTHON_VERSION= "${DEPTHAI_PYTHON_VERSION} "
204+ DEPTHAI_PYTHON_COMMIT_HASH= "${BUILD_COMMIT} "
205+ DEPTHAI_PYTHON_COMMIT_DATETIME= "${BUILD_COMMIT_DATETIME} "
206+ DEPTHAI_PYTHON_BUILD_DATETIME= "${BUILD_DATETIME} "
207+ )
164208
165209# Set compiler features (c++14), and disables extensions
166210set_property (TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 14 )
0 commit comments