cmake: Build all math-heavy code with optimization.

This commit is contained in:
Ryan Pavlik 2023-05-14 08:28:37 +00:00 committed by Jakob Bornecrantz
parent 75442c43ce
commit 4ffb271c6a
5 changed files with 29 additions and 5 deletions

View file

@ -1,7 +1,13 @@
# Copyright 2018-2023, Collabora, Ltd. # Copyright 2018-2023, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0 # SPDX-License-Identifier: BSL-1.0
if(NOT MSVC)
# Target used for applying more aggressive optimizations to math-heavy code
add_library(xrt-optimized-math INTERFACE)
if(MSVC)
target_compile_options(xrt-optimized-math INTERFACE $<IF:$<CONFIG:Debug>,/O2,/O3>)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Wno-unused-parameter") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Wno-unused-parameter")
set(CMAKE_C_FLAGS set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Werror=incompatible-pointer-types" "${CMAKE_C_FLAGS} -Werror-implicit-function-declaration -Werror=incompatible-pointer-types"
@ -15,6 +21,8 @@ if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse")
endif() endif()
target_compile_options(xrt-optimized-math INTERFACE $<IF:$<CONFIG:Debug>,-O2,-O3>)
endif() endif()
if(NOT WIN32) if(NOT WIN32)

View file

@ -37,5 +37,9 @@ add_library(
m_vec2.h m_vec2.h
m_vec3.h m_vec3.h
) )
target_link_libraries(aux_math PUBLIC aux-includes aux_util) target_link_libraries(
aux_math
PUBLIC aux-includes aux_util
PRIVATE xrt-optimized-math
)
target_include_directories(aux_math SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR}) target_include_directories(aux_math SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})

View file

@ -14,7 +14,12 @@ add_library(
target_link_libraries( target_link_libraries(
aux_tracking aux_tracking
PUBLIC aux-includes xrt-external-cjson PUBLIC aux-includes xrt-external-cjson
PRIVATE aux_math aux_util xrt-external-flexkalman xrt-external-hungarian PRIVATE
aux_math
aux_util
xrt-external-flexkalman
xrt-external-hungarian
xrt-optimized-math
) )
target_include_directories(aux_tracking SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR}) target_include_directories(aux_tracking SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})

View file

@ -1,10 +1,11 @@
# Copyright 2019-2022, Collabora, Ltd. # Copyright 2019-2023, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0 # SPDX-License-Identifier: BSL-1.0
# Mercury hand tracking library! # Mercury hand tracking library!
add_subdirectory(kine_lm) add_subdirectory(kine_lm)
# t_ht_mercury_model
add_library(t_ht_mercury_model STATIC hg_model.cpp) add_library(t_ht_mercury_model STATIC hg_model.cpp)
target_link_libraries(t_ht_mercury_model PRIVATE aux_math aux_tracking aux_os aux_util) target_link_libraries(t_ht_mercury_model PRIVATE aux_math aux_tracking aux_os aux_util)
@ -20,10 +21,12 @@ target_link_libraries(
aux_tracking aux_tracking
aux_os aux_os
aux_util aux_util
xrt-optimized-math
${OpenCV_LIBRARIES} ${OpenCV_LIBRARIES}
ONNXRuntime::ONNXRuntime ONNXRuntime::ONNXRuntime
) )
# t_ht_mercury_distorter
add_library(t_ht_mercury_distorter STATIC hg_image_distorter.cpp) add_library(t_ht_mercury_distorter STATIC hg_image_distorter.cpp)
target_link_libraries(t_ht_mercury_distorter PRIVATE aux_math aux_tracking aux_os aux_util) target_link_libraries(t_ht_mercury_distorter PRIVATE aux_math aux_tracking aux_os aux_util)
@ -39,10 +42,12 @@ target_link_libraries(
aux_tracking aux_tracking
aux_os aux_os
aux_util aux_util
xrt-optimized-math
${OpenCV_LIBRARIES} ${OpenCV_LIBRARIES}
ONNXRuntime::ONNXRuntime # no, wrong ONNXRuntime::ONNXRuntime # no, wrong
) )
# t_ht_mercury
add_library(t_ht_mercury STATIC hg_sync.cpp hg_sync.hpp hg_interface.h kine_common.hpp) add_library(t_ht_mercury STATIC hg_sync.cpp hg_sync.hpp hg_interface.h kine_common.hpp)
target_link_libraries( target_link_libraries(
@ -57,6 +62,7 @@ target_link_libraries(
t_ht_mercury_kine_lm t_ht_mercury_kine_lm
t_ht_mercury_model t_ht_mercury_model
t_ht_mercury_distorter t_ht_mercury_distorter
xrt-optimized-math
${OpenCV_LIBRARIES} ${OpenCV_LIBRARIES}
) )

View file

@ -1,4 +1,4 @@
# Copyright 2022, Collabora, Ltd. # Copyright 2022-2023, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0 # SPDX-License-Identifier: BSL-1.0
add_library( add_library(
@ -14,6 +14,7 @@ target_link_libraries(
aux_os aux_os
aux_util aux_util
xrt-external-tinyceres xrt-external-tinyceres
xrt-optimized-math
) )
target_include_directories(t_ht_mercury_kine_lm SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR}) target_include_directories(t_ht_mercury_kine_lm SYSTEM PRIVATE ${EIGEN3_INCLUDE_DIR})