Skip to content

Commit

Permalink
CMake cleanup
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
JohannesLorenz authored and fundamental committed Dec 28, 2024
1 parent c33ad42 commit b212d2a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand All @@ -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'
Expand All @@ -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"
}
Expand Down
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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)


Expand Down Expand Up @@ -239,23 +244,23 @@ 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 "")
set(RTOSC_TEST_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions example/complex/Fl_Osc_Tree.H
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ 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);
*pound = 0;
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);
}
Expand Down
8 changes: 4 additions & 4 deletions example/complex/Fl_Osc_View.H
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion example/complex/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct Fl_Center_Knob : public Fl_Osc_Dial
template<typename T>
struct Fl_Square : public Fl_Osc_Group
{
Fl_Square<T>(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));
Expand Down

0 comments on commit b212d2a

Please sign in to comment.