summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt37
1 files changed, 32 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 12953dd..6a7d5f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 3.1)
+cmake_minimum_required (VERSION 3.10)
project (specgram VERSION 1.0.0 LANGUAGES CXX)
@@ -11,12 +11,19 @@ set (VERSION_PATCH 1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
+# Options
+option (TESTING "Build test targets" OFF)
+
# Dependencies
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads REQUIRED)
find_package (SFML 2.5 COMPONENTS window graphics REQUIRED)
find_library (FFTW3 fftw3)
+if (TESTING)
+ find_package(GTest)
+endif()
+
# Compiler setup
add_compile_options (-Wall -Wextra -pedantic)
@@ -48,7 +55,6 @@ configure_file (
# Source setup
set (SPECGRAM_SOURCES
- "${SRC_DIR}/specgram.cpp"
"${SRC_DIR}/configuration.cpp"
"${SRC_DIR}/input-parser.cpp"
"${SRC_DIR}/input-reader.cpp"
@@ -62,9 +68,12 @@ set (SPECGRAM_SOURCES
"${SRC_DIR}/share-tech-mono.cpp"
)
+# Static lib (we build this once for the executable and the unit tests)
+add_library (${PROJECT_NAME}_static STATIC ${SPECGRAM_SOURCES})
+
# Executable target
-add_executable (${PROJECT_NAME} ${SPECGRAM_SOURCES})
-target_link_libraries (${PROJECT_NAME} Threads::Threads sfml-window sfml-graphics ${FFTW3})
+add_executable (${PROJECT_NAME} ${SRC_DIR}/specgram.cpp)
+target_link_libraries (${PROJECT_NAME} ${PROJECT_NAME}_static Threads::Threads sfml-window sfml-graphics ${FFTW3})
# HTML manpage target
add_custom_target(manpage
@@ -81,4 +90,22 @@ install (FILES "${PROJECT_SOURCE_DIR}/LICENSE" DESTINATION "share/licenses/specg
install (FILES "${PROJECT_SOURCE_DIR}/share/applications/specgram.desktop"
DESTINATION "share/applications/")
install (DIRECTORY "${PROJECT_SOURCE_DIR}/share/icons/hicolor"
- DESTINATION "share/icons") \ No newline at end of file
+ DESTINATION "share/icons")
+
+if (TESTING)
+ set (UNIT_TEST_SOURCES
+ test/test.cpp
+ test/test-fft.cpp
+ test/test-input-reader.cpp
+ test/test-input-parser.cpp
+ test/test-color-map.cpp
+ test/test-value-map.cpp
+ test/test-window-function.cpp
+ )
+
+ # Unit tests
+ enable_testing ()
+ add_executable(unittest ${UNIT_TEST_SOURCES})
+ target_link_libraries (unittest GTest::GTest ${PROJECT_NAME}_static Threads::Threads sfml-graphics ${FFTW3})
+ gtest_discover_tests (unittest)
+endif()