From 210926d23d0f40277b549ca490f876f93c3ffb6d Mon Sep 17 00:00:00 2001
From: Diogo Pereira <sir.suriv@gmail.com>
Date: Wed, 24 Jan 2018 16:44:03 +0000
Subject: [PATCH 1/3] CMake: simplify GCC version check

---
 CMakeLists.txt | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 392db54..78a71c0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,21 +2,9 @@ cmake_minimum_required(VERSION 2.8)
 
 project(j4-dmenu)
 
-exec_program(
-  ${CMAKE_CXX_COMPILER}
-  ARGS --version
-  OUTPUT_VARIABLE _compiler_output
-  )
-string(REGEX REPLACE "(\n.*$)" "" cxx_compiler_version "${_compiler_output}")
-string(REGEX REPLACE "([^0-9.])|([0-9.][^0-9.])" "" cxx_compiler_version "${cxx_compiler_version}")
-
-if(CMAKE_COMPILER_IS_GNUCXX)
-  if(${cxx_compiler_version} VERSION_LESS "4.7.0")
-    set(CXX_OPT "-std=c++0x")
-  else()
-    set(CXX_OPT "-std=c++11")
-  endif()
-elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
+  set(CXX_OPT "-std=c++0x")
+else()
   set(CXX_OPT "-std=c++11")
 endif()
 

From e6e05d0170554246118c2dffe5395a982e1af250 Mon Sep 17 00:00:00 2001
From: Diogo Pereira <sir.suriv@gmail.com>
Date: Wed, 24 Jan 2018 16:53:39 +0000
Subject: [PATCH 2/3] CMake: clean up and reorder CMAKE_CXX_FLAGS

---
 CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 78a71c0..1b3f2b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ else()
   set(CXX_OPT "-std=c++11")
 endif()
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_OPT} ${CXX_OPT} -Wall -pedantic -Wextra -O2")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_OPT} -Wall -Wextra -pedantic -O2")
 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
 
 if(NOT DEFINED NO_TESTS)

From 7be5116d0d6d80522517a58bb6e45ca1cdcd9612 Mon Sep 17 00:00:00 2001
From: Diogo Pereira <sir.suriv@gmail.com>
Date: Wed, 24 Jan 2018 17:51:28 +0000
Subject: [PATCH 3/3] CMake: add option to disable downloading Catch

---
 CMakeLists.txt | 90 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 47 insertions(+), 43 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b3f2b0..17605e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 2.8)
 
 project(j4-dmenu)
 
+option(WITH_TESTS "Build and run tests" ON)
+option(WITH_GIT_CATCH "Use a Git checkout of Catch to build the tests" ON)
+
 if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
   set(CXX_OPT "-std=c++0x")
 else()
@@ -11,53 +14,54 @@ endif()
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_OPT} -Wall -Wextra -pedantic -O2")
 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
 
-if(NOT DEFINED NO_TESTS)
-  include(ExternalProject)
-
-  ExternalProject_Add(
-    catch
-    PREFIX ${CMAKE_BINARY_DIR}/catch
-    GIT_TAG Catch1.x
-    GIT_REPOSITORY https://github.com/catchorg/Catch2
-    TIMEOUT 10
-    UPDATE_COMMAND git pull
-    CONFIGURE_COMMAND ""
-    BUILD_COMMAND ""
-    INSTALL_COMMAND ""
-    LOG_DOWNLOAD ON
-    )
-
-  # Expose required variable (CATCH_INCLUDE_DIR) to parent scope
-  ExternalProject_Get_Property(catch source_dir)
-  set(CATCH_INCLUDE_DIR ${source_dir}/include CACHE INTERNAL "Path to include folder for Catch")
-
-  # Includes Catch in the project:
-  #add_subdirectory(${EXT_PROJECTS_DIR}/catch)
-  include_directories(${CATCH_INCLUDE_DIR} ${COMMON_INCLUDES})
-
-  add_definitions(-DTEST_FILES="${CMAKE_CURRENT_SOURCE_DIR}/test_files/")
-
+if(WITH_TESTS)
   enable_testing(true)
-
   add_test(
-    NAME j4-dmenu-tests
-    COMMAND j4-dmenu-tests
-    )
-
+          NAME j4-dmenu-tests
+          COMMAND j4-dmenu-tests
+  )
   add_executable(
-    j4-dmenu-tests
-    src/Test.cc
-    src/TestApplication.cc
-    src/TestApplicationRunner.cc
-    src/TestSearchPath.cc
-    src/TestLocaleSuffixes.cc
-    src/TestFileFinder.cc
-    src/TestFormatters.cc
-    )
-
-  add_dependencies(j4-dmenu-tests catch)
-endif(NOT DEFINED NO_TESTS)
+          j4-dmenu-tests
+          src/Test.cc
+          src/TestApplication.cc
+          src/TestApplicationRunner.cc
+          src/TestSearchPath.cc
+          src/TestLocaleSuffixes.cc
+          src/TestFileFinder.cc
+          src/TestFormatters.cc
+  )
+  add_definitions(-DTEST_FILES="${CMAKE_CURRENT_SOURCE_DIR}/test_files/")
 
+  if(WITH_GIT_CATCH)
+    include(ExternalProject)
+    ExternalProject_Add(
+      catch
+      PREFIX ${CMAKE_BINARY_DIR}/catch
+      GIT_TAG Catch1.x
+      GIT_REPOSITORY https://github.com/catchorg/Catch2
+      TIMEOUT 10
+      UPDATE_COMMAND git pull
+      CONFIGURE_COMMAND ""
+      BUILD_COMMAND ""
+      INSTALL_COMMAND ""
+      LOG_DOWNLOAD ON
+    )
+    add_dependencies(j4-dmenu-tests catch)
+
+    # Expose required variable (CATCH_INCLUDE_DIR) to parent scope
+    ExternalProject_Get_Property(catch source_dir)
+    set(CATCH_INCLUDE_DIR ${source_dir}/include CACHE INTERNAL "Path to include folder for Catch")
+  else()
+    # Use system-installed version of Catch
+    find_path(CATCH_INCLUDE_DIR catch.hpp PATH_SUFFIXES catch)
+    if(NOT CATCH_INCLUDE_DIR)
+      message(FATAL_ERROR "Catch include directory not found")
+    endif()
+  endif(WITH_GIT_CATCH)
+
+  # Include Catch in the project
+  include_directories(${CATCH_INCLUDE_DIR} ${COMMON_INCLUDES})
+endif(WITH_TESTS)
 
 add_executable(
     j4-dmenu-desktop
