Skip to content

Commit

Permalink
Merge pull request #54 from Harold2017/patch-1
Browse files Browse the repository at this point in the history
Update CMakeLists.txt
  • Loading branch information
PetteriAimonen authored Oct 9, 2024
2 parents 591d541 + b825350 commit 0055844
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,44 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(OpenCV REQUIRED)
# find_package(OpenCL CONFIG REQUIRED)

set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
include_directories(${SRC_INCLUDE_DIR})
set(PROJECT_LIB ${PROJECT_NAME}_lib)
set(PROJECT_TEST ${PROJECT_NAME}_test)

file(GLOB_RECURSE PROJECT_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS
option(BUILD_TESTS "build tests" OFF) # set to ON if you want to build tests

file(GLOB_RECURSE PROJECT_LIB_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS
${SRC_DIR}/*.cc ${SRC_DIR}/*.hh ${SRC_DIR}/*cl
)
list(FILTER PROJECT_SOURCES EXCLUDE REGEX .*_tests.cc|.*test.*)
list(FILTER PROJECT_LIB_SOURCES EXCLUDE REGEX .*_tests.cc|.*main.cc)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
target_link_libraries(${PROJECT_NAME}
PRIVATE ${OpenCV_LIBS}
# PRIVATE OpenCL::OpenCL
add_library(${PROJECT_LIB}
STATIC # set to SHARED if you want dll
${PROJECT_LIB_SOURCES}
)
target_link_libraries(${PROJECT_LIB}
PUBLIC ${OpenCV_LIBS}
)
if(MSVC)
target_compile_definitions(${PROJECT_NAME} PRIVATE _USE_MATH_DEFINES)
target_compile_definitions(${PROJECT_LIB} PRIVATE _USE_MATH_DEFINES)
endif()

add_executable(${PROJECT_NAME} ${SRC_DIR}/main.cc)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${PROJECT_LIB}
)

if (BUILD_TESTS)
enable_testing()
find_package(GTest CONFIG REQUIRED)
file(GLOB_RECURSE PROJECT_TEST_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS
${SRC_DIR}/*_tests.cc
)
add_executable(${PROJECT_TEST} ${PROJECT_TEST_SOURCES} ${SRC_DIR}/gtest_main.cc)
target_link_libraries(${PROJECT_TEST}
PRIVATE ${PROJECT_LIB}
PRIVATE GTest::gtest_main
)
add_test(NAME ${PROJECT_TEST} COMMAND ${PROJECT_TEST})
endif()

0 comments on commit 0055844

Please sign in to comment.