From 45aa514591c860fee97580fd3648792ef4f30727 Mon Sep 17 00:00:00 2001 From: John Beard Date: Wed, 17 Apr 2019 12:41:15 +0100 Subject: [PATCH] QA: Allow to build tests manually if disabled Add a new CMake target, qa_all, which builds all tests, tools and their deps. Then, when KICAD_BUILD_QA_TESTS is set OFF, remove tests and tools from the ALL target, so `make all` doesn't include these builds. This means even when you turn the KICAD_BUILD_QA_TESTS option off, you still have the option to: * Build individual tests: `make qa_pcbnew` * Build all tests: `make qa_all_tests` * Build all tools: `make qa_all_tools` * Build all QA executables: `make qa_all` This also will provide a place to hang extra logic for test routine wrangling (e.g. by CI tools) Update the "Compiling KiCad" dev docs. Also, CMakeModules .cmake files should not be excluded from git --- .gitignore | 3 + CMakeLists.txt | 4 +- CMakeModules/KiCadQABuildUtils.cmake | 82 +++++++++++++++++++++++ Documentation/development/compiling.md | 14 +++- qa/CMakeLists.txt | 23 +++++++ qa/common/CMakeLists.txt | 14 +--- qa/common_tools/CMakeLists.txt | 4 +- qa/eeschema/CMakeLists.txt | 8 +-- qa/gal/gal_pixel_alignment/CMakeLists.txt | 2 + qa/libs/sexpr/CMakeLists.txt | 4 +- qa/pcbnew/CMakeLists.txt | 4 +- qa/pcbnew_tools/CMakeLists.txt | 2 + qa/utils/kicad2step/CMakeLists.txt | 4 +- 13 files changed, 136 insertions(+), 32 deletions(-) create mode 100644 CMakeModules/KiCadQABuildUtils.cmake diff --git a/.gitignore b/.gitignore index 9b4ba75e74..f690c1e827 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,6 @@ demos/**/fp-info-cache *.gch *.orig *.patch + +# These CMake files are wanted +!CMakeModules/*.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b84c4d92c..dfb4abdb67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -948,9 +948,7 @@ add_subdirectory( plugins ) # 3D plugins must be built before kicad add_subdirectory( kicad ) # should follow pcbnew, eeschema add_subdirectory( tools ) add_subdirectory( utils ) -if( KICAD_BUILD_QA_TESTS ) - add_subdirectory( qa ) -endif() +add_subdirectory( qa ) # Resources if ( KICAD_INSTALL_DEMOS ) diff --git a/CMakeModules/KiCadQABuildUtils.cmake b/CMakeModules/KiCadQABuildUtils.cmake new file mode 100644 index 0000000000..ebf231545f --- /dev/null +++ b/CMakeModules/KiCadQABuildUtils.cmake @@ -0,0 +1,82 @@ +# This program source code file is part of KiCad, a free EDA CAD application. +# +# Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you may find one here: +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# or you may search the http://www.gnu.org website for the version 2 license, +# or you may write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +# +# Utility CMake functions and targets for marshalling the builds of QA +# tests and tools +# + +# This is a "meta" target that is used to collect all tests +add_custom_target( qa_all_tests ) + +# This is a "meta" target used to collect all utility tools +add_custom_target( qa_all_tools ) + +# This "meta" target builds all QA tools, utils, etc +add_custom_target( qa_all + DEPENDS qa_all_tests qa_all_tools +) + +# Add a target as a "QA test" executable: +# * Added as a CTest test with the given name +# * Excluded from ALL when KICAD_BUILD_QA_TESTS not set +# * Is a dependency of qa_all_tests +function( kicad_add_boost_test TEST_EXEC_TARGET TEST_NAME) + +# Add the test to the CTest registry +add_test( NAME ${TEST_NAME} + COMMAND $ +) + +# Make the overall test meta-target depend on this test +add_dependencies( qa_all_tests ${TEST_EXEC_TARGET} ) + +# If tests are not enabled by default, remove from the ALL target +# They can still be built manually, or all together with the qa_all_test target +if( NOT KICAD_BUILD_QA_TESTS ) + + set_target_properties( ${TEST_EXEC_TARGET} + PROPERTIES EXCLUDE_FROM_ALL TRUE + ) + +endif() + +endfunction() + +# Add a target as a "QA tool" executable: +# * Excluded from ALL when KICAD_BUILD_QA_TESTS not set +# * Is a dependency of qa_all_tools +function( kicad_add_utils_executable TARGET) + +# If tests are not enabled by default, remove from the ALL target +# They can still be built manually, or all together with the qa_all_tools +if( NOT KICAD_BUILD_QA_TESTS ) + + set_target_properties( ${TARGET} + PROPERTIES EXCLUDE_FROM_ALL TRUE + ) + +endif() + +# Make the overall test meta-target depend on this test +add_dependencies( qa_all_tools ${TARGET} ) + +endfunction() \ No newline at end of file diff --git a/Documentation/development/compiling.md b/Documentation/development/compiling.md index ba1588ef81..dc09b03325 100644 --- a/Documentation/development/compiling.md +++ b/Documentation/development/compiling.md @@ -205,10 +205,18 @@ The KICAD_SCRIPTING_ACTION_MENU option allows Python scripts to be added directl menu. This option is disabled by default. Please note that this option is highly experimental and can cause Pcbnew to crash if Python scripts create an invalid object state within Pcbnew. -## Quality assurance (qa) unit tests ## {#quality_assurance_tests_opt} +## Quality assurance (QA) unit tests ## {#quality_assurance_tests_opt} -The KICAD_BUILD_QA_TESTS option allows building unit tests binaries for quality assurance. -This option is enabled by default. +The KICAD_BUILD_QA_TESTS option allows building unit tests binaries for quality assurance as part +of the default build. This option is enabled by default. + +If this option is disabled, the QA binaries can still be built by manually specifying the target. +For example, with `make`: + +* Build all QA binaries: `make qa_all` +* Build a specific test: `make qa_pcbnew` +* Build all unit tests: `make qa_all_tests` +* Build all test tool binaries: `make qa_all_tools` ## KiCad Build Version ## {#build_version_opt} diff --git a/qa/CMakeLists.txt b/qa/CMakeLists.txt index 560555ba47..7ebada410a 100644 --- a/qa/CMakeLists.txt +++ b/qa/CMakeLists.txt @@ -1,3 +1,26 @@ +# This program source code file is part of KiCad, a free EDA CAD application. +# +# Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you may find one here: +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# or you may search the http://www.gnu.org website for the version 2 license, +# or you may write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +include(KiCadQABuildUtils) + if( KICAD_SCRIPTING_MODULES ) # Test that runs the QA tests through scripting diff --git a/qa/common/CMakeLists.txt b/qa/common/CMakeLists.txt index 6e811da076..dc9ac1d1c4 100644 --- a/qa/common/CMakeLists.txt +++ b/qa/common/CMakeLists.txt @@ -93,14 +93,6 @@ include_directories( ${INC_AFTER} ) -add_test( NAME common_gerbview - COMMAND qa_common_gerbview -) - -add_test( NAME common_pcbnew - COMMAND qa_common_pcbnew -) - -add_test( NAME common_eeschema - COMMAND qa_common_eeschema -) \ No newline at end of file +kicad_add_boost_test( qa_common_eeschema common_eeschema ) +kicad_add_boost_test( qa_common_pcbnew common_pcbnew ) +kicad_add_boost_test( qa_common_gerbview qa_common_gerbview ) \ No newline at end of file diff --git a/qa/common_tools/CMakeLists.txt b/qa/common_tools/CMakeLists.txt index 8d72dd1c39..0d5425a2d1 100644 --- a/qa/common_tools/CMakeLists.txt +++ b/qa/common_tools/CMakeLists.txt @@ -58,4 +58,6 @@ target_link_libraries( qa_common_tools # we need to pretend to be something to appease the units code target_compile_definitions( qa_common_tools PRIVATE PCBNEW -) \ No newline at end of file +) + +kicad_add_utils_executable( qa_common_tools ) \ No newline at end of file diff --git a/qa/eeschema/CMakeLists.txt b/qa/eeschema/CMakeLists.txt index f1f849207f..0e0a013aa3 100644 --- a/qa/eeschema/CMakeLists.txt +++ b/qa/eeschema/CMakeLists.txt @@ -56,10 +56,6 @@ target_link_libraries( qa_eeschema ${Boost_LIBRARIES} ) -add_test( NAME eeschema - COMMAND qa_eeschema -) - # Eeschema tests, so pretend to be eeschema (for units, etc) target_compile_definitions( qa_eeschema PUBLIC EESCHEMA @@ -68,4 +64,6 @@ target_compile_definitions( qa_eeschema # Pass in the default data location set_source_files_properties( eeschema_test_utils.cpp PROPERTIES COMPILE_DEFINITIONS "QA_EESCHEMA_DATA_LOCATION=(\"${CMAKE_CURRENT_SOURCE_DIR}/data\")" -) \ No newline at end of file +) + +kicad_add_boost_test( qa_eeschema eeschema ) \ No newline at end of file diff --git a/qa/gal/gal_pixel_alignment/CMakeLists.txt b/qa/gal/gal_pixel_alignment/CMakeLists.txt index dcf1d27c85..562ccb1735 100644 --- a/qa/gal/gal_pixel_alignment/CMakeLists.txt +++ b/qa/gal/gal_pixel_alignment/CMakeLists.txt @@ -79,3 +79,5 @@ target_link_libraries( test_gal_pixel_alignment ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${wxWidgets_LIBRARIES} ) + +kicad_add_utils_executable( test_gal_pixel_alignment ) \ No newline at end of file diff --git a/qa/libs/sexpr/CMakeLists.txt b/qa/libs/sexpr/CMakeLists.txt index 4e76d676c7..bee0b8a0a4 100644 --- a/qa/libs/sexpr/CMakeLists.txt +++ b/qa/libs/sexpr/CMakeLists.txt @@ -41,6 +41,4 @@ target_include_directories( qa_sexpr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) -add_test( NAME sexpr - COMMAND qa_sexpr -) \ No newline at end of file +kicad_add_boost_test(qa_sexpr sexpr) \ No newline at end of file diff --git a/qa/pcbnew/CMakeLists.txt b/qa/pcbnew/CMakeLists.txt index 2ef779f1e6..1d18073fea 100644 --- a/qa/pcbnew/CMakeLists.txt +++ b/qa/pcbnew/CMakeLists.txt @@ -76,6 +76,4 @@ target_link_libraries( qa_pcbnew ${PCBNEW_EXTRA_LIBS} # -lrt must follow Boost ) -add_test( NAME pcbnew - COMMAND qa_pcbnew -) +kicad_add_boost_test( qa_pcbnew pcbnew ) \ No newline at end of file diff --git a/qa/pcbnew_tools/CMakeLists.txt b/qa/pcbnew_tools/CMakeLists.txt index 6dfa54f7f9..905ecc4cde 100644 --- a/qa/pcbnew_tools/CMakeLists.txt +++ b/qa/pcbnew_tools/CMakeLists.txt @@ -63,3 +63,5 @@ target_link_libraries( qa_pcbnew_tools ${Boost_LIBRARIES} # must follow GITHUB ${PCBNEW_EXTRA_LIBS} # -lrt must follow Boost ) + +kicad_add_utils_executable( qa_pcbnew_tools ) \ No newline at end of file diff --git a/qa/utils/kicad2step/CMakeLists.txt b/qa/utils/kicad2step/CMakeLists.txt index 9088f868f4..84ee243c90 100644 --- a/qa/utils/kicad2step/CMakeLists.txt +++ b/qa/utils/kicad2step/CMakeLists.txt @@ -39,6 +39,4 @@ target_include_directories( qa_sexpr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) -add_test( NAME kicad2step - COMMAND qa_kicad2step -) \ No newline at end of file +kicad_add_boost_test( qa_kicad2step kicad2step ) \ No newline at end of file