From 4b0fefd11c554bc0cbd55ec0ed64b7e925b294e3 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Wed, 14 Aug 2024 11:52:36 +0200 Subject: [PATCH] change compile flag propagation, tighten up compile flags --- .github/workflows/build.yml | 2 + CMakeLists.txt | 42 +++++++++--------- cmake/actsvg-functions.cmake | 69 ++++++++++++++++-------------- core/include/actsvg/core/views.hpp | 2 +- extern/googletest/CMakeLists.txt | 9 ++-- 5 files changed, 63 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c0c15f..aaa1688 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,6 +44,8 @@ jobs: run: | cmake $GITHUB_WORKSPACE \ -DACTSVG_BUILD_TESTING=ON \ + -DACTSVG_BUILD_META=ON \ + -DACTSVG_BUILD_WEB=ON \ -DACTSVG_BUILD_EXAMPLES=ON - name: Build diff --git a/CMakeLists.txt b/CMakeLists.txt index 35898ed..234498e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,15 +6,13 @@ project (actsvg VERSION 0.4.41 LANGUAGES CXX ) set( CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard to use" ) set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "Disable C++ extensions" ) -set(ACTSVG_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wshadow") -# This adds some useful conversion checks like float-to-bool, float-to-int, etc. -# However, at the moment this is only added to clang builds, since GCC's -Wfloat-conversion -# is much more aggressive and also triggers on e.g., double-to-float -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang") - set(ACTSVG_CXX_FLAGS "${ACTSVG_CXX_FLAGS} -Wfloat-conversion") -endif() +set(ACTSVG_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wshadow -Wzero-as-null-pointer-constant -Wold-style-cast -Wnull-dereference -Wfloat-conversion") + -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ACTSVG_CXX_FLAGS}") +# Controls behavior of DOWNLOAD_EXTRACT_TIMESTAMP +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() # CMake include(s). include( CMakeDependentOption ) @@ -45,19 +43,19 @@ add_subdirectory(core) option(ACTSVG_BUILD_META "Build the meta level interface of ACTSVG" ON ) if ( ACTSVG_BUILD_META ) - add_subdirectory(meta) + add_subdirectory(meta) endif() option(ACTSVG_BUILD_WEB "Build the webpage builder interface of ACTSVG" ON ) if ( ACTSVG_BUILD_WEB ) - add_subdirectory(web) + add_subdirectory(web) endif() option(ACTSVG_BUILD_TESTING "Build the (unit) tests of ACTSVG" OFF ) if (ACTSVG_BUILD_TESTING OR ACTSVG_BUILD_EXAMPLES) - add_subdirectory(data) + add_subdirectory(data) endif() # Set up the test(s). @@ -67,26 +65,26 @@ if( ACTSVG_BUILD_TESTING ) endif() if (ACTSVG_BUILD_TESTING OR ACTSVG_BUILD_EXAMPLES) - # Set up GoogleTest. - option( ACTSVG_SETUP_GOOGLETEST + # Set up GoogleTest. + option( ACTSVG_SETUP_GOOGLETEST "Set up the GoogleTest target(s) explicitly" TRUE ) - option( ACTSVG_USE_SYSTEM_GOOGLETEST + option( ACTSVG_USE_SYSTEM_GOOGLETEST "Pick up an existing installation of GoogleTest from the build environment" ${ACTSVG_USE_SYSTEM_LIBS} ) - if( ACTSVG_SETUP_GOOGLETEST ) - if( ACTSVG_USE_SYSTEM_GOOGLETEST ) - find_package( GTest REQUIRED ) - else() - add_subdirectory( extern/googletest ) - endif() - endif() + if( ACTSVG_SETUP_GOOGLETEST ) + if( ACTSVG_USE_SYSTEM_GOOGLETEST ) + find_package( GTest REQUIRED ) + else() + add_subdirectory( extern/googletest ) + endif() + endif() endif() option(ACTSVG_BUILD_PYTHON_BINDINGS "Build the python bindings of ACTSVG" OFF) if(ACTSVG_BUILD_PYTHON_BINDINGS) find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development) option(ACTSVG_USE_SYSTEM_PYBIND11 "Pick up an existing installation of pybind11") - if(ACTSVG_USE_SYSTEM_PYBIND11) + if(ACTSVG_USE_SYSTEM_PYBIND11) find_package(pybind11 CONFIG REQUIRED) else() add_subdirectory(extern/pybind11) diff --git a/cmake/actsvg-functions.cmake b/cmake/actsvg-functions.cmake index 32f99d2..daa3d27 100644 --- a/cmake/actsvg-functions.cmake +++ b/cmake/actsvg-functions.cmake @@ -6,28 +6,33 @@ include( CMakeParseArguments ) # Usage: actsvg_add_library( actsvg_core core "header1.cpp"... ) # function( actsvg_add_library fullname basename ) - cmake_parse_arguments( ARG "" "" "" ${ARGN} ) + cmake_parse_arguments( ARG "" "" "" ${ARGN} ) - # Create the library. - add_library( ${fullname} SHARED ${ARG_UNPARSED_ARGUMENTS} ) + # Create the library. + add_library( ${fullname} SHARED ${ARG_UNPARSED_ARGUMENTS} ) - # Set up how clients should find its headers. - target_include_directories( ${fullname} PUBLIC + # Set up how clients should find its headers. + target_include_directories( ${fullname} PUBLIC $ $ ) - # Make sure that the library is available as "actsvg::${basename}" in every - # situation. - set_target_properties( ${fullname} PROPERTIES EXPORT_NAME ${basename} ) - add_library( actsvg::${basename} ALIAS ${fullname} ) + set_target_properties(${fullname} + PROPERTIES + COMPILE_FLAGS ${ACTSVG_CXX_FLAGS}) - # Set up the installation of the library and its headers. - install( TARGETS ${fullname} + # Make sure that the library is available as "actsvg::${basename}" in every + # situation. + set_target_properties( ${fullname} PROPERTIES EXPORT_NAME ${basename} ) + add_library( actsvg::${basename} ALIAS ${fullname} ) + + + # Set up the installation of the library and its headers. + install( TARGETS ${fullname} EXPORT actsvg-exports LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) - install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" + install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" OPTIONAL ) endfunction( actsvg_add_library ) @@ -44,15 +49,15 @@ endfunction( actsvg_add_library ) # function( actsvg_add_executable name ) - # Parse the function's options. - cmake_parse_arguments( ARG "" "" "LINK_LIBRARIES" ${ARGN} ) + # Parse the function's options. + cmake_parse_arguments( ARG "" "" "LINK_LIBRARIES" ${ARGN} ) - # Create the executable. - set( exe_name "actsvg_${name}" ) - add_executable( ${exe_name} ${ARG_UNPARSED_ARGUMENTS} ) - if( ARG_LINK_LIBRARIES ) - target_link_libraries( ${exe_name} PRIVATE ${ARG_LINK_LIBRARIES} ) - endif() + # Create the executable. + set( exe_name "actsvg_${name}" ) + add_executable( ${exe_name} ${ARG_UNPARSED_ARGUMENTS} ) + if( ARG_LINK_LIBRARIES ) + target_link_libraries( ${exe_name} PRIVATE ${ARG_LINK_LIBRARIES} ) + endif() endfunction( actsvg_add_executable ) @@ -64,22 +69,22 @@ endfunction( actsvg_add_executable ) # function( actsvg_add_test name ) - # Parse the function's options. - cmake_parse_arguments( ARG "" "" "LINK_LIBRARIES" ${ARGN} ) + # Parse the function's options. + cmake_parse_arguments( ARG "" "" "LINK_LIBRARIES" ${ARGN} ) - # Create the test executable. - set( test_exe_name "actsvg_test_${name}" ) - add_executable( ${test_exe_name} ${ARG_UNPARSED_ARGUMENTS} ) - if( ARG_LINK_LIBRARIES ) - target_link_libraries( ${test_exe_name} PRIVATE ${ARG_LINK_LIBRARIES} ) - endif() + # Create the test executable. + set( test_exe_name "actsvg_test_${name}" ) + add_executable( ${test_exe_name} ${ARG_UNPARSED_ARGUMENTS} ) + if( ARG_LINK_LIBRARIES ) + target_link_libraries( ${test_exe_name} PRIVATE ${ARG_LINK_LIBRARIES} ) + endif() - # Run the executable as the test. - add_test( NAME ${test_exe_name} + # Run the executable as the test. + add_test( NAME ${test_exe_name} COMMAND ${test_exe_name} ) - # Set all properties for the test. - set_tests_properties( ${test_exe_name} PROPERTIES + # Set all properties for the test. + set_tests_properties( ${test_exe_name} PROPERTIES ENVIRONMENT actsvg_TEST_DATA_DIR=${PROJECT_SOURCE_DIR}/data/ ) endfunction( actsvg_add_test ) diff --git a/core/include/actsvg/core/views.hpp b/core/include/actsvg/core/views.hpp index 0e5ca14..795a126 100644 --- a/core/include/actsvg/core/views.hpp +++ b/core/include/actsvg/core/views.hpp @@ -276,7 +276,7 @@ struct z_rphi { r = std::sqrt(point_[0] * point_[0] + point_[1] * point_[1]); } scalar phi = std::atan2(point_[1], point_[0]); - return point2{point_[2], r * phi}; + return point2{static_cast(point_[2]), r * phi}; } /** A z-rphi view operator diff --git a/extern/googletest/CMakeLists.txt b/extern/googletest/CMakeLists.txt index 68b5d95..cc13aaf 100644 --- a/extern/googletest/CMakeLists.txt +++ b/extern/googletest/CMakeLists.txt @@ -1,4 +1,3 @@ -cmake_minimum_required( VERSION 3.11 ) include( FetchContent ) # Tell the user what's happening. @@ -9,13 +8,13 @@ set( ACTSVG_GOOGLETEST_SOURCE "URL;https://github.com/google/googletest/archive/release-1.11.0.tar.gz;URL_MD5;e8a8df240b6938bb6384155d4c37d937" CACHE STRING "Source for GoogleTest, when built as part of this project" ) mark_as_advanced( ACTSVG_GOOGLETEST_SOURCE ) -FetchContent_Declare( GoogleTest ${ACTSVG_GOOGLETEST_SOURCE} ) +FetchContent_Declare( GoogleTest "${ACTSVG_GOOGLETEST_SOURCE};EXCLUDE_FROM_ALL" ) # Options used in the build of GoogleTest. set( BUILD_GMOCK TRUE CACHE BOOL "Turn off the build of GMock" ) set( INSTALL_GTEST FALSE CACHE BOOL "Turn off the installation of GoogleTest" ) if( WIN32 ) - set( gtest_force_shared_crt TRUE CACHE BOOL + set( gtest_force_shared_crt TRUE CACHE BOOL "Use shared (DLL) run-time library, even with static libraries" ) endif() @@ -23,9 +22,7 @@ endif() set( CMAKE_MACOSX_RPATH TRUE ) # Get it into the current directory. -FetchContent_Populate( GoogleTest ) -add_subdirectory( "${googletest_SOURCE_DIR}" "${googletest_BINARY_DIR}" - EXCLUDE_FROM_ALL ) +FetchContent_MakeAvailable( GoogleTest ) # Set up aliases for the GTest targets with the same name that they have # when we find GTest pre-installed.