From b212d2a21f6c5de7b67c03718cdf22ccd9845977 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 14 Dec 2024 22:15:50 +0100 Subject: [PATCH] CMake cleanup * Change option `WERROR` to `RTOSC_WERROR` (for use in other projects) * Fix using the current source/binary paths when compiling rtosc inside of other projects * Fix warnings about VLAs (that occur with Clang) * Fix warnings in code (that occur with GCC new Arch Linux) --- .github/workflows/ccpp.yml | 8 ++++---- CMakeLists.txt | 27 ++++++++++++++++----------- example/complex/Fl_Osc_Tree.H | 4 ++-- example/complex/Fl_Osc_View.H | 8 ++++---- example/complex/window.cpp | 2 +- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index df7eefa..de9243c 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -17,7 +17,7 @@ jobs: config: "cmake -B build -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake - -DWERROR=1 + -DRTOSC_WERROR=1 -DCMAKE_BUILD_TYPE=Debug ", build: "cmake --build build --config Debug", @@ -30,7 +30,7 @@ jobs: enabled: 1, os: ubuntu-latest, deps: "sudo apt-get install liblo-dev", - config: "cd build && cmake -DWERROR=1 ..", + config: "cd build && cmake -DRTOSC_WERROR=1 ..", build: "cd build && make", test: "cd build && ctest --output-on-failure" } @@ -41,7 +41,7 @@ jobs: deps: "sudo apt-get install liblo-dev", config: "cd build && cmake - -DWERROR=1 + -DRTOSC_WERROR=1 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_SHARED_LINKER_FLAGS='-fuse-ld=lld' @@ -55,7 +55,7 @@ jobs: enabled: 1, os: macos-latest, deps: "brew install liblo", - config: "cd build && cmake -DWERROR=1 ..", + config: "cd build && cmake -DRTOSC_WERROR=1 ..", build: "cd build && make", test: "cd build && ctest --output-on-failure" } diff --git a/CMakeLists.txt b/CMakeLists.txt index b36d9ad..8f85623 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ if(NOT CMAKE_BUILD_TYPE) endif() option(RTOSC_INCLUDE_WHAT_YOU_USE "Check for useless includes" OFF) mark_as_advanced(FORCE RTOSC_INCLUDE_WHAT_YOU_USE) -option(WERROR "Compile with warnings being treated as errors" OFF) +option(RTOSC_WERROR "Compile with warnings being treated as errors" OFF) set(BUILD_RTOSC_EXAMPLES FALSE CACHE BOOL "Build RTOSC Example Programs") @@ -70,7 +70,7 @@ set(MSVC_CNV_WARN "/wd4244 /wd4267 /wd4305") #Ignore the whole non-portable string*_s function recommendations set(MSVC_SAFE_WARN "/wd4996") -if(WERROR) +if(RTOSC_WERROR) if(MSVC) set(WERROR_FLAG "/WX") else() @@ -82,8 +82,13 @@ if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSVC_CNV_WARN} ${MSVC_SAFE_WARN} ${WERROR_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_CNV_WARN} ${MSVC_SAFE_WARN} ${WERROR_FLAG}") else() + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-Wno-vla-cxx-extension HAVE_W_NO_VLA_CXX_EXTENSION) + if(HAVE_W_NO_VLA_CXX_EXTENSION) + set(VLA_DISABLE -Wno-vla-cxx-extension) + endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra ${WERROR_FLAG}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ${WERROR_FLAG}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ${VLA_DISABLE} ${WERROR_FLAG}") endif(MSVC) @@ -239,7 +244,7 @@ maketestcpp(test-automation) if(LIBLO_FOUND) add_library(lo-server test/liblo-server.cpp) target_include_directories(lo-server PRIVATE ${LIBLO_INCLUDE_DIRS}) - target_include_directories(lo-server PRIVATE ${CMAKE_SOURCE_DIR}/include) + target_include_directories(lo-server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(lo-server PRIVATE ${RTOSC_LIBLO_LIBRARIES}) target_link_directories(performance PRIVATE ${LIBLO_LIBRARY_DIRS}) set(RTOSC_TEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test CACHE INTERNAL "") @@ -247,15 +252,15 @@ if(LIBLO_FOUND) endif() if(LIBLO_FOUND AND RUBY_FOUND) add_executable(port-checker test/port-checker-main.cpp) - target_include_directories(port-checker PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include) + target_include_directories(port-checker PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(port-checker PRIVATE lo-server rtosc-cpp rtosc ${RTOSC_LIBLO_LIBRARIES}) target_link_directories(port-checker PRIVATE ${LIBLO_LIBRARY_DIRS}) add_executable(port-checker-tester test/port-checker-tester.cpp) - target_include_directories(port-checker-tester PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include) + target_include_directories(port-checker-tester PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(port-checker-tester PRIVATE lo-server rtosc-cpp rtosc ${RTOSC_LIBLO_LIBRARIES}) target_link_directories(port-checker-tester PRIVATE ${LIBLO_LIBRARY_DIRS}) add_executable(port-checker-testapp test/port-checker-testapp.cpp) - target_include_directories(port-checker-testapp PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include) + target_include_directories(port-checker-testapp PRIVATE ${LIBLO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(port-checker-testapp PRIVATE rtosc-cpp rtosc ${RTOSC_LIBLO_LIBRARIES}) target_link_directories(port-checker-testapp PRIVATE ${LIBLO_LIBRARY_DIRS}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/test-port-checker.rb @@ -282,12 +287,12 @@ endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT DEFINED RTOSC_NO_INSTALL) if(PKG_CONFIG_FOUND) configure_file(librtosc.pc.cmake - ${CMAKE_BINARY_DIR}/librtosc.pc @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/librtosc.pc + ${CMAKE_CURRENT_BINARY_DIR}/librtosc.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librtosc.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") configure_file(librtosc-cpp.pc.cmake - ${CMAKE_BINARY_DIR}/librtosc-cpp.pc @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/librtosc-cpp.pc + ${CMAKE_CURRENT_BINARY_DIR}/librtosc-cpp.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librtosc-cpp.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") endif() install(FILES include/rtosc/rtosc.h diff --git a/example/complex/Fl_Osc_Tree.H b/example/complex/Fl_Osc_Tree.H index 4e09a04..cef03da 100644 --- a/example/complex/Fl_Osc_Tree.H +++ b/example/complex/Fl_Osc_Tree.H @@ -71,7 +71,7 @@ class Fl_Osc_Tree:Fl_Tree t->sprout(path); } else { char tmpa[1024]; - char tmpb[1024]; + char tmpb[1040]; strncpy(tmpa, path.c_str(), 1024-1); char *pound = strchr(tmpa, '#'); int N = atoi(pound+1); @@ -79,7 +79,7 @@ class Fl_Osc_Tree:Fl_Tree char terminal = subnodes ? '/' : '\0'; for(int i = 0; i < N; ++i) { - snprintf(tmpb, 1024, "%s%d%c", + snprintf(tmpb, sizeof(tmpb), "%s%d%c", tmpa, i, terminal); t->sprout(tmpb); } diff --git a/example/complex/Fl_Osc_View.H b/example/complex/Fl_Osc_View.H index 7fb5d3a..b15cf76 100644 --- a/example/complex/Fl_Osc_View.H +++ b/example/complex/Fl_Osc_View.H @@ -174,10 +174,10 @@ class Fl_Osc_View: public Fl_Double_Window rtosc::walk_ports(p, buffer, sizeof(buffer), table, [](const rtosc::Port *p, const char *name, - const char *_, - const rtosc::Ports &__, + const char *, + const rtosc::Ports &, void*t, - void*runtime) { + void*) { PortTable *table = (PortTable*)t; port_view tmp = {name, *p, -1, -1}; @@ -212,7 +212,7 @@ class Fl_Osc_View: public Fl_Double_Window Fl_Osc_Interface *osc; }; -static void Delete_CB(Fl_Widget *w, void *v_) +static void Delete_CB(Fl_Widget *, void *v_) { Fl_Osc_View &v = *(Fl_Osc_View*)v_; int row_top, col_left, row_bot, col_right; diff --git a/example/complex/window.cpp b/example/complex/window.cpp index 2210eb1..ca14f5e 100644 --- a/example/complex/window.cpp +++ b/example/complex/window.cpp @@ -87,7 +87,7 @@ struct Fl_Center_Knob : public Fl_Osc_Dial template struct Fl_Square : public Fl_Osc_Group { - Fl_Square(int x, int y, int w, int h, int _pad, const Port *port) + Fl_Square(int x, int y, int w, int h, int _pad, const Port *port) :Fl_Osc_Group(x,y,w,h,NULL), pad(_pad) { const int l = min(max(w-2*pad,0),max(h-2*pad,0));