-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
116 lines (91 loc) · 3.82 KB
/
Copy pathCMakeLists.txt
File metadata and controls
116 lines (91 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
cmake_minimum_required(VERSION 3.10)
project(CppRectangleRecognition)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Force Release mode for fastest execution
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native -mtune=native -flto -ffast-math -s")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
# Set output directories for all binaries
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Output)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/Output)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/Output)
# Find OpenMP for parallelization
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
message(STATUS "OpenMP found - enabling parallel processing")
else()
message(WARNING "OpenMP not found - performance may be reduced")
endif()
include_directories(Include)
file(GLOB_RECURSE SOURCES "Source/*.cpp")
file(GLOB_RECURSE HEADERS "Include/*.h" "Include/*.hpp")
# Remove VisualTest.cpp from main executable sources
list(REMOVE_ITEM SOURCES "${CMAKE_SOURCE_DIR}/Source/VisualTest.cpp")
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# Link OpenMP if found
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME} OpenMP::OpenMP_CXX)
endif()
# GTest configuration
if(EXISTS "${CMAKE_SOURCE_DIR}/Test")
enable_testing()
# Find GTest
find_package(GTest QUIET)
if(NOT GTest_FOUND)
# Download and build GTest
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50f33f9142a332f1e5e4bd3d71e787.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
# Create test executable
file(GLOB_RECURSE TEST_SOURCES "Test/*.cpp")
# Exclude TestPerformance.cpp from the test suite as it has its own main
list(REMOVE_ITEM TEST_SOURCES "${CMAKE_SOURCE_DIR}/Test/TestPerformance.cpp")
if(TEST_SOURCES)
# Remove main.cpp from library sources for tests
set(LIB_SOURCES ${SOURCES})
list(REMOVE_ITEM LIB_SOURCES "${CMAKE_SOURCE_DIR}/Source/Main.cpp")
add_executable(tests ${TEST_SOURCES} ${LIB_SOURCES})
if(GTest_FOUND)
target_link_libraries(tests GTest::gtest GTest::gtest_main)
else()
target_link_libraries(tests gtest gtest_main)
endif()
# Link OpenMP to tests if found
if(OpenMP_CXX_FOUND)
target_link_libraries(tests OpenMP::OpenMP_CXX)
endif()
include(GoogleTest)
gtest_discover_tests(tests)
endif()
endif()
# Performance test executable
if(EXISTS "${CMAKE_SOURCE_DIR}/Test/TestPerformance.cpp")
set(PERF_SOURCES ${SOURCES})
list(REMOVE_ITEM PERF_SOURCES "${CMAKE_SOURCE_DIR}/Source/Main.cpp")
add_executable(TestPerformance Test/TestPerformance.cpp ${PERF_SOURCES})
# Link OpenMP if found
if(OpenMP_CXX_FOUND)
target_link_libraries(TestPerformance OpenMP::OpenMP_CXX)
endif()
endif()
# Visual test executable
if(EXISTS "${CMAKE_SOURCE_DIR}/Source/VisualTest.cpp")
# Get all sources except Main.cpp and VisualTest.cpp
file(GLOB_RECURSE ALL_SOURCES "Source/*.cpp")
list(REMOVE_ITEM ALL_SOURCES "${CMAKE_SOURCE_DIR}/Source/Main.cpp")
list(REMOVE_ITEM ALL_SOURCES "${CMAKE_SOURCE_DIR}/Source/VisualTest.cpp")
add_executable(VisualTest Source/VisualTest.cpp ${ALL_SOURCES})
# Link OpenMP if found
if(OpenMP_CXX_FOUND)
target_link_libraries(VisualTest OpenMP::OpenMP_CXX)
endif()
endif()