@@ -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
@@ -93,8 +105,8 @@ endif()
93105
94106if (DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT)
95107 # If output is specified set both input and output to same the path
96- set (docstring_input_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
97- set (docstring_output_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
108+ set (docstring_input_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
109+ set (docstring_output_path ${DEPTHAI_PYTHON_DOCSTRINGS_OUTPUT} )
98110else ()
99111 # If input docstrings explicitly specified, use those and disable building
100112 if (DEPTHAI_PYTHON_DOCSTRINGS_INPUT)
@@ -103,11 +115,11 @@ else()
103115 set (DEPTHAI_PYTHON_BUILD_DOCSTRINGS OFF CACHE BOOL "Generate docstrings from header files if module 'pybind11_mkdoc' available" FORCE )
104116 else ()
105117 # Otherwise set default location as input
106- set (docstring_input_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
118+ set (docstring_input_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
107119 endif ()
108120
109121 # Set default output location
110- set (docstring_output_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
122+ set (docstring_output_path ${DEFAULT_DOCSTRINGS_OUTPUT} )
111123endif ()
112124
113125if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
@@ -119,11 +131,14 @@ configure_file(cmake/docstring.hpp.in ${DOCSTRINGS_INCLUDE_PLACEHOLDER_PATH})
119131# Add target to generate docstrings
120132if (DEPTHAI_PYTHON_BUILD_DOCSTRINGS)
121133 include (pybind11-mkdoc )
122-
134+
123135 # Check if pybind11_mkdoc available and create target
124136 target_pybind11_mkdoc_setup (${docstring_output_path} depthai::core ${DEPTHAI_PYTHON_FORCE_DOCSTRINGS} )
125-
126- if (NOT TARGET pybind11_mkdoc)
137+
138+ if (TARGET pybind11_mkdoc)
139+ # Add dependency to mkdoc target (makes sure that mkdoc is executed, and docstrings available)
140+ add_dependencies (${TARGET_NAME} pybind11_mkdoc )
141+ else ()
127142 # Generate default docstrings to OUTPUT path
128143 configure_file (cmake/default_docstring.hpp.in ${docstring_output_path} COPYONLY )
129144 endif ()
@@ -136,17 +151,39 @@ endif()
136151target_include_directories (${TARGET_NAME} PRIVATE src ${DOCSTRINGS_INCLUDE_PLACEHOLDER_DIR} )
137152
138153# Link with libraries
139- target_link_libraries (${TARGET_NAME}
140- PUBLIC
154+ target_link_libraries (${TARGET_NAME}
155+ PUBLIC
141156 # pybind11
142157 pybind11::pybind11
143158 depthai::core # Use non-opencv target as we use opencv-python in bindings
144159 hedley
145160)
146161
147- # Add default commit hash ('dev') if not build by CI
148- if (NOT DEFINED ENV{CI} AND NOT DEPTHAI_PYTHON_COMMIT_HASH)
149- set (DEPTHAI_PYTHON_COMMIT_HASH "dev" )
162+ # Find Git
163+ find_package (Git )
164+
165+ # Add build information (commit, date)
166+ set (BUILD_COMMIT "dev" )
167+ if (GIT_FOUND)
168+ execute_process (
169+ COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
170+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
171+ OUTPUT_VARIABLE BUILD_COMMIT
172+ ERROR_QUIET
173+ OUTPUT_STRIP_TRAILING_WHITESPACE
174+ )
175+ execute_process (
176+ COMMAND ${GIT_EXECUTABLE} show -s --format=%ci ${BUILD_COMMIT}
177+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
178+ OUTPUT_VARIABLE BUILD_COMMIT_DATETIME
179+ ERROR_QUIET
180+ OUTPUT_STRIP_TRAILING_WHITESPACE
181+ )
182+ endif ()
183+
184+ # Add local commit hash (or 'dev' if unable to retrieve) if not build by CI
185+ if (NOT DEFINED ENV{CI} AND NOT DEPTHAI_PYTHON_COMMIT_HASH)
186+ set (DEPTHAI_PYTHON_COMMIT_HASH ${BUILD_COMMIT} )
150187endif ()
151188
152189# Get version to use
@@ -160,8 +197,15 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} "-c" "${version_command}"
160197 WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
161198)
162199
163- # Add version definition
164- target_compile_definitions (${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_VERSION= "${DEPTHAI_PYTHON_VERSION} " )
200+
201+ string (TIMESTAMP BUILD_DATETIME "%Y-%m-%d %H:%M:%S +0000" UTC )
202+ target_compile_definitions (${TARGET_NAME}
203+ PRIVATE
204+ DEPTHAI_PYTHON_VERSION= "${DEPTHAI_PYTHON_VERSION} "
205+ DEPTHAI_PYTHON_COMMIT_HASH= "${BUILD_COMMIT} "
206+ DEPTHAI_PYTHON_COMMIT_DATETIME= "${BUILD_COMMIT_DATETIME} "
207+ DEPTHAI_PYTHON_BUILD_DATETIME= "${BUILD_DATETIME} "
208+ )
165209
166210# Set compiler features (c++14), and disables extensions
167211set_property (TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 14 )
0 commit comments