changeset 663:65a54b126c08

CMake: do not use TESTS_BINARY_DIR in libirccd-test The variable is not defined on initial CMake because the add_subdirectory(tests) appears after libirccd-test creation. Use a dedicated CMAKE_BINARY_DIR/tmp directory to store temporary files needed for CLI tests.
author David Demelier <markand@malikania.fr>
date Thu, 29 Mar 2018 19:39:20 +0200
parents e9153b85b9bd
children ce2748ffcf36
files cmake/function/IrccdDefineLibrary.cmake libcommon/irccd/config.hpp libirccd-test/CMakeLists.txt libirccd-test/irccd/test/cli_test.cpp tests/CMakeLists.txt tests/data/irccd-plugins.conf tests/data/irccdctl.conf
diffstat 7 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cmake/function/IrccdDefineLibrary.cmake	Thu Mar 29 09:13:51 2018 +0200
+++ b/cmake/function/IrccdDefineLibrary.cmake	Thu Mar 29 19:39:20 2018 +0200
@@ -54,7 +54,14 @@
 
     add_library(${LIB_TARGET} ${type} ${LIB_SOURCES})
     target_include_directories(${LIB_TARGET} PRIVATE ${LIB_LOCAL_INCLUDES} PUBLIC ${LIB_PUBLIC_INCLUDES})
-    target_compile_definitions(${LIB_TARGET} PUBLIC ${LIB_FLAGS})
+    target_compile_definitions(
+        ${LIB_TARGET}
+        PRIVATE
+            CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"
+            CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
+        PUBLIC
+            ${LIB_FLAGS}
+    )
     target_link_libraries(${LIB_TARGET} ${LIB_LIBRARIES})
     set_target_properties(
         ${LIB_TARGET}
--- a/libcommon/irccd/config.hpp	Thu Mar 29 09:13:51 2018 +0200
+++ b/libcommon/irccd/config.hpp	Thu Mar 29 19:39:20 2018 +0200
@@ -53,6 +53,7 @@
      */
     inline config(std::string path = "")
         : document(path.empty() ? ini::document() : ini::read_file(path))
+        , path_(std::move(path))
     {
     }
 
--- a/libirccd-test/CMakeLists.txt	Thu Mar 29 09:13:51 2018 +0200
+++ b/libirccd-test/CMakeLists.txt	Thu Mar 29 19:39:20 2018 +0200
@@ -40,5 +40,4 @@
     FLAGS
         IRCCD_EXECUTABLE="$<TARGET_FILE:irccd>"
         IRCCDCTL_EXECUTABLE="$<TARGET_FILE:irccdctl>"
-        TESTS_BINARY_DIR="${tests_BINARY_DIR}"
 )
--- a/libirccd-test/irccd/test/cli_test.cpp	Thu Mar 29 09:13:51 2018 +0200
+++ b/libirccd-test/irccd/test/cli_test.cpp	Thu Mar 29 19:39:20 2018 +0200
@@ -36,7 +36,8 @@
 {
     std::ostringstream oss;
 
-    oss << IRCCD_EXECUTABLE << " -fc " << TESTS_BINARY_DIR << "/" << config;
+    oss << IRCCD_EXECUTABLE << " -fc ";
+    oss << CMAKE_BINARY_DIR "/tmp/" << config;
 
     irccd_ = proc::child(oss.str());
 
@@ -50,8 +51,9 @@
     std::future<std::string> out;
     std::future<std::string> err;
 
-    oss << IRCCDCTL_EXECUTABLE << " -c " << TESTS_BINARY_DIR << "/irccdctl.conf "
-        << string_util::join(args, " ");
+    oss << IRCCDCTL_EXECUTABLE << " -c ";
+    oss << CMAKE_BINARY_DIR << "/tmp/irccdctl.conf ";
+    oss << string_util::join(args, " ");
 
     boost::asio::io_service io;
     proc::child irccdctl(
--- a/tests/CMakeLists.txt	Thu Mar 29 09:13:51 2018 +0200
+++ b/tests/CMakeLists.txt	Thu Mar 29 19:39:20 2018 +0200
@@ -29,7 +29,7 @@
 foreach (c ${CONFIGS})
     configure_file(
         ${tests_SOURCE_DIR}/data/${c}
-        ${tests_BINARY_DIR}/${c}
+        ${CMAKE_BINARY_DIR}/tmp/${c}
         @ONLY
     )
 endforeach ()
--- a/tests/data/irccd-plugins.conf	Thu Mar 29 09:13:51 2018 +0200
+++ b/tests/data/irccd-plugins.conf	Thu Mar 29 19:39:20 2018 +0200
@@ -1,6 +1,6 @@
 [transport]
 type = "unix"
-path = "@tests_BINARY_DIR@/irccd.sock"
+path = "@CMAKE_BINARY_DIR@/tmp/irccd.sock"
 
 [plugins]
 foo = "@tests_SOURCE_DIR@/data/foo.js"
--- a/tests/data/irccdctl.conf	Thu Mar 29 09:13:51 2018 +0200
+++ b/tests/data/irccdctl.conf	Thu Mar 29 19:39:20 2018 +0200
@@ -1,3 +1,3 @@
 [connect]
 type = "unix"
-path = "@tests_BINARY_DIR@/irccd.sock"
+path = "@CMAKE_BINARY_DIR@/tmp/irccd.sock"