From f0c200186e3d70bd79953d04cd51b48c71e54f06 Mon Sep 17 00:00:00 2001 From: Betsy McPhail Date: Thu, 14 Nov 2024 14:56:45 -0500 Subject: [PATCH] Simplify the drake_cmake_external example Updates to the CMakeLists include: * Use the modern method of finding Python. * Remove unnecessary subdirectory --- drake_cmake_external/CMakeLists.txt | 2 -- .../drake_external_examples/CMakeLists.txt | 33 +++++++++++-------- .../apps/CMakeLists.txt | 14 -------- .../{apps => }/import_all_test.py | 0 .../simple_continuous_time_system.cc | 0 drake_cmake_installed_apt/CMakeLists.txt | 16 ++------- 6 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 drake_cmake_external/drake_external_examples/apps/CMakeLists.txt rename drake_cmake_external/drake_external_examples/{apps => }/import_all_test.py (100%) rename drake_cmake_external/drake_external_examples/{apps => }/simple_continuous_time_system.cc (100%) diff --git a/drake_cmake_external/CMakeLists.txt b/drake_cmake_external/CMakeLists.txt index b74794ba..2244f821 100644 --- a/drake_cmake_external/CMakeLists.txt +++ b/drake_cmake_external/CMakeLists.txt @@ -24,8 +24,6 @@ endif() list(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}") -find_package(Python3 REQUIRED COMPONENTS Interpreter Development) - include(ExternalProject) # This shows how to fetch Eigen from source as part of Drake's CMake build. diff --git a/drake_cmake_external/drake_external_examples/CMakeLists.txt b/drake_cmake_external/drake_external_examples/CMakeLists.txt index 50aefc9a..681a961d 100644 --- a/drake_cmake_external/drake_external_examples/CMakeLists.txt +++ b/drake_cmake_external/drake_external_examples/CMakeLists.txt @@ -1,22 +1,29 @@ # SPDX-License-Identifier: MIT-0 -cmake_minimum_required(VERSION 3.10.2) +cmake_minimum_required(VERSION 3.16) project(drake_external_examples) -include(CTest) - -if(APPLE) - set(FIND_PYTHON_INTERP_VERSION 3.12) -else() - set(FIND_PYTHON_INTERP_VERSION 3.6) -endif() -find_package(PythonInterp ${FIND_PYTHON_INTERP_VERSION} MODULE REQUIRED) - find_package(drake CONFIG REQUIRED) -get_filename_component(PYTHONPATH - "${drake_DIR}/../../python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages" +find_package(Python3 ${drake_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) + +get_filename_component(DRAKE_PYTHONPATH + "${drake_DIR}/../../python${drake_PYTHON_VERSION}/site-packages" REALPATH ) -add_subdirectory(apps) +add_executable(simple_continuous_time_system simple_continuous_time_system.cc) +target_link_libraries(simple_continuous_time_system drake::drake) + +include(CTest) + +add_test(NAME simple_continuous_time_system + COMMAND simple_continuous_time_system +) +add_test(NAME import_all_test COMMAND + "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/import_all_test.py" +) +set_tests_properties(import_all_test PROPERTIES + ENVIRONMENT "PYTHONPATH=${DRAKE_PYTHONPATH}" +) + diff --git a/drake_cmake_external/drake_external_examples/apps/CMakeLists.txt b/drake_cmake_external/drake_external_examples/apps/CMakeLists.txt deleted file mode 100644 index 053a60b6..00000000 --- a/drake_cmake_external/drake_external_examples/apps/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: MIT-0 - -add_executable(simple_continuous_time_system simple_continuous_time_system.cc) -target_link_libraries(simple_continuous_time_system drake::drake) -add_test(NAME simple_continuous_time_system - COMMAND simple_continuous_time_system -) - -add_test(NAME import_all_test COMMAND - "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/import_all_test.py" -) -set_tests_properties(import_all_test PROPERTIES - ENVIRONMENT "PYTHONPATH=${PYTHONPATH}" -) diff --git a/drake_cmake_external/drake_external_examples/apps/import_all_test.py b/drake_cmake_external/drake_external_examples/import_all_test.py similarity index 100% rename from drake_cmake_external/drake_external_examples/apps/import_all_test.py rename to drake_cmake_external/drake_external_examples/import_all_test.py diff --git a/drake_cmake_external/drake_external_examples/apps/simple_continuous_time_system.cc b/drake_cmake_external/drake_external_examples/simple_continuous_time_system.cc similarity index 100% rename from drake_cmake_external/drake_external_examples/apps/simple_continuous_time_system.cc rename to drake_cmake_external/drake_external_examples/simple_continuous_time_system.cc diff --git a/drake_cmake_installed_apt/CMakeLists.txt b/drake_cmake_installed_apt/CMakeLists.txt index 77906c94..7661e4d8 100644 --- a/drake_cmake_installed_apt/CMakeLists.txt +++ b/drake_cmake_installed_apt/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: MIT-0 -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(drake_cmake_installed_apt) include(CTest) @@ -21,23 +21,13 @@ target_include_directories(gtest PUBLIC ) target_link_libraries(gtest Threads::Threads) -if(CMAKE_VERSION VERSION_LESS 3.12) - list(INSERT CMAKE_MODULE_PATH 0 - "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cmake/3.12/Modules" - ) -endif() - -find_package(Python 3.6 MODULE REQUIRED) -set(PYTHON_VERSION_MAJOR_MINOR - "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}" -) - find_package(drake CONFIG REQUIRED PATHS /opt/drake) +find_package(Python3 ${drake_PYTHON_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) get_filename_component(DRAKE_PYTHONPATH "${drake_DIR}" DIRECTORY) get_filename_component(DRAKE_PYTHONPATH "${DRAKE_PYTHONPATH}" DIRECTORY) set(DRAKE_PYTHONPATH - "${DRAKE_PYTHONPATH}/python${PYTHON_VERSION_MAJOR_MINOR}/site-packages" + "${DRAKE_PYTHONPATH}/python${drake_PYTHON_VERSION}/site-packages" ) add_subdirectory(src)