From e499c284787eb53d6eb47f14a5efdd828281c4c9 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Mon, 10 Apr 2023 11:59:58 -0300 Subject: [PATCH] build: fix scratch targets for file names containing dots in CMake < 3.14 --- scratch/CMakeLists.txt | 12 +++++++++++- utils/tests/test-ns3.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/scratch/CMakeLists.txt b/scratch/CMakeLists.txt index 938497414..093e79d7b 100644 --- a/scratch/CMakeLists.txt +++ b/scratch/CMakeLists.txt @@ -30,7 +30,17 @@ function(create_scratch source_files) string(REPLACE "/" "_" scratch_dirname "${scratch_dirname}") # Get source name - get_filename_component(scratch_name ${scratch_src} NAME_WLE) + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0") + get_filename_component(scratch_name ${scratch_src} NAME_WLE) + else() + get_filename_component(scratch_name ${scratch_src} NAME) + string(FIND "${scratch_name}" "." ext_position REVERSE) + if(${ext_position} EQUAL -1) + message(FATAL_ERROR "Source file has no extension: ${scratch_src}") + else() + string(SUBSTRING "${scratch_name}" 0 ${ext_position} scratch_name) + endif() + endif() set(target_prefix scratch_) if(scratch_dirname) diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index 7c62d8462..7482d498c 100755 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -1254,6 +1254,25 @@ class NS3ConfigureTestCase(NS3BaseTestCase): else: self.assertEqual(return_code, 1) + # Now test them in CMake 3.10 + run_ns3("clean") + with DockerContainerManager(self, "ubuntu:18.04") as container: + container.execute("apt-get update") + container.execute("apt-get install -y python3 cmake g++-8 ninja-build") + try: + container.execute( + "./ns3 configure --enable-modules=core,network,internet -- -DCMAKE_CXX_COMPILER=/usr/bin/g++-8") + except DockerException as e: + self.fail() + for path in test_files: + path = path.replace(".cc", "") + try: + container.execute(f"./ns3 run {path}") + except DockerException as e: + if "main" in path: + self.fail() + run_ns3("clean") + # Delete the test files and reconfigure to clean them up for path in test_files + backup_files: source_absolute_path = os.path.join(ns3_path, path)