Skip to content

Commit

Permalink
cmake: Prefix all user-settable variables
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed Mar 7, 2024
1 parent de48541 commit 51bdd3f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
6 changes: 3 additions & 3 deletions .github/actions/cmake/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ runs:
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DUSE_QT6=${{ inputs.use_qt6 }} \
-DWITH_CLI_EXAMPLES=ON \
-DWITH_GUI_EXAMPLES=ON \
-DWITH_LDAP=ON \
-DLIBSHV_WITH_CLI_EXAMPLES=ON \
-DLIBSHV_WITH_GUI_EXAMPLES=ON \
-DLIBSHV_WITH_LDAP=ON \
${{ env.cmake_extra_args }} \
${{ inputs.additional_cmake_args }}
shell: bash
108 changes: 54 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
cmake_minimum_required(VERSION 3.18.4)

set(USE_QT6 ON CACHE BOOL "Qt6 build")
set(LIBSHV_USE_QT6 ON CACHE BOOL "Qt6 build")
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries instead of static")

set(WITH_CHAINPACK ON CACHE BOOL "Build libshvchainpack (C)")
set(WITH_CHAINPACK_CPP ON CACHE BOOL "Build libshvchainpack (C++)")
set(WITH_CORE ON CACHE BOOL "Build libshvcore")
set(WITH_COREQT ON CACHE BOOL "Build libshvcoreqt")
set(WITH_IOTQT ON CACHE BOOL "Build libshviotqt")
set(WITH_VISU ON CACHE BOOL "Build libshvvisu")
set(WITH_BROKER ON CACHE BOOL "Build libshvbroker")

set(WITH_CLI_EXAMPLES OFF CACHE BOOL "Enable build of CLI examples")
set(WITH_GUI_EXAMPLES OFF CACHE BOOL "Enable build of GUI examples")
set(WITH_LDAP OFF CACHE BOOL "Enable authentization via LDAP")
set(WITH_SANITIZERS OFF CACHE BOOL "Enable ASan/UBsan")
if(WITH_SANITIZERS)
set(LIBSHV_WITH_CHAINPACK ON CACHE BOOL "Build libshvchainpack (C)")
set(LIBSHV_WITH_CHAINPACK_CPP ON CACHE BOOL "Build libshvchainpack (C++)")
set(LIBSHV_WITH_CORE ON CACHE BOOL "Build libshvcore")
set(LIBSHV_WITH_COREQT ON CACHE BOOL "Build libshvcoreqt")
set(LIBSHV_WITH_IOTQT ON CACHE BOOL "Build libshviotqt")
set(LIBSHV_WITH_VISU ON CACHE BOOL "Build libshvvisu")
set(LIBSHV_WITH_BROKER ON CACHE BOOL "Build libshvbroker")

set(LIBSHV_WITH_CLI_EXAMPLES OFF CACHE BOOL "Enable build of CLI examples")
set(LIBSHV_WITH_GUI_EXAMPLES OFF CACHE BOOL "Enable build of GUI examples")
set(LIBSHV_WITH_LDAP OFF CACHE BOOL "Enable authentization via LDAP")
set(LIBSHV_WITH_SANITIZERS OFF CACHE BOOL "Enable ASan/UBsan")
if(LIBSHV_WITH_SANITIZERS)
set(CMAKE_C_FLAGS "-fsanitize=address,undefined ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=address,undefined ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address,undefined ${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -50,7 +50,7 @@ function(libshv_set_translations target langs)
set(TS_FILES ${TS_FILES} "${target}.${lang}.ts")
endforeach()

if(USE_QT6)
if(LIBSHV_USE_QT6)
if(DEFINED ENV{LIBSHV_RUN_LUPDATE})
qt_add_lupdate("${target}" TS_FILES ${TS_FILES})
endif()
Expand All @@ -69,30 +69,30 @@ function(libshv_set_translations target langs)
endfunction()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(SHV_WARNING_FLAGS "-Wall -Wextra -pedantic -Wcast-align -Wunused -Wpedantic -Wmisleading-indentation -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough")
set(LIBSHV_WARNING_FLAGS "-Wall -Wextra -pedantic -Wcast-align -Wunused -Wpedantic -Wmisleading-indentation -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough")

# We switched to qsizetype in Qt6, so let's get rid of this warning in Qt5 for now.
# TODO: Remove this after dropping support for Qt5
if(USE_QT6)
set(SHV_WARNING_FLAGS "${SHV_WARNING_FLAGS} -Wconversion")
if(LIBSHV_USE_QT6)
set(LIBSHV_WARNING_FLAGS "${LIBSHV_WARNING_FLAGS} -Wconversion")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(SHV_WARNING_FLAGS_CXX "-Wuseless-cast ${SHV_WARNING_FLAGS_CXX}")
set(LIBSHV_WARNING_FLAGS_CXX "-Wuseless-cast ${LIBSHV_WARNING_FLAGS_CXX}")
endif()
endif()

set(SHV_WARNING_FLAGS "${SHV_WARNING_FLAGS} -Wno-sign-conversion")
set(SHV_WARNING_FLAGS_CXX "-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual")
set(LIBSHV_WARNING_FLAGS "${LIBSHV_WARNING_FLAGS} -Wno-sign-conversion")
set(LIBSHV_WARNING_FLAGS_CXX "-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(SHV_WARNING_FLAGS "-Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wshadow=local ${SHV_WARNING_FLAGS}")
set(LIBSHV_WARNING_FLAGS "-Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wshadow=local ${LIBSHV_WARNING_FLAGS}")
else() # Clang
set(SHV_WARNING_FLAGS "-Wshadow ${SHV_WARNING_FLAGS}")
set(LIBSHV_WARNING_FLAGS "-Wshadow ${LIBSHV_WARNING_FLAGS}")
endif()

set(SHV_WARNING_FLAGS_CXX "${SHV_WARNING_FLAGS} ${SHV_WARNING_FLAGS_CXX}")
set(LIBSHV_WARNING_FLAGS_CXX "${LIBSHV_WARNING_FLAGS} ${LIBSHV_WARNING_FLAGS_CXX}")

set(CMAKE_C_FLAGS "${SHV_WARNING_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${SHV_WARNING_FLAGS_CXX} ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${LIBSHV_WARNING_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${LIBSHV_WARNING_FLAGS_CXX} ${CMAKE_CXX_FLAGS}")
endif()

if(BUILD_TESTING)
Expand Down Expand Up @@ -128,28 +128,28 @@ function(check_shv_dep dependent dependent_var dependency dependency_var)
endif()
endfunction()

check_shv_dep(libshvchainpack-c WITH_CHAINPACK "" ON)
check_shv_dep(libshvchainpack-cpp WITH_CHAINPACK_CPP libshvchainpack-c WITH_CHAINPACK)
check_shv_dep(libshvcore WITH_CORE libshvchainpack-cpp WITH_CHAINPACK_CPP)
check_shv_dep(libshvcoreqt WITH_COREQT libshvcore WITH_CORE)
check_shv_dep(libshviotqt WITH_IOTQT libshvcoreqt WITH_COREQT)
check_shv_dep(libshvvisu WITH_VISU libshviotqt WITH_IOTQT)
check_shv_dep(libshvbroker WITH_BROKER libshviotqt WITH_IOTQT)
check_shv_dep(cli-examples WITH_CLI_EXAMPLES libshvbroker WITH_BROKER)
check_shv_dep(gui-examples WITH_GUI_EXAMPLES libshvvisu WITH_VISU)

if(WITH_CHAINPACK)
check_shv_dep(libshvchainpack-c LIBSHV_WITH_CHAINPACK "" ON)
check_shv_dep(libshvchainpack-cpp LIBSHV_WITH_CHAINPACK_CPP libshvchainpack-c WITH_CHAINPACK)
check_shv_dep(libshvcore LIBSHV_WITH_CORE libshvchainpack-cpp WITH_CHAINPACK_CPP)
check_shv_dep(libshvcoreqt LIBSHV_WITH_COREQT libshvcore WITH_CORE)
check_shv_dep(libshviotqt LIBSHV_WITH_IOTQT libshvcoreqt WITH_COREQT)
check_shv_dep(libshvvisu LIBSHV_WITH_VISU libshviotqt WITH_IOTQT)
check_shv_dep(libshvbroker LIBSHV_WITH_BROKER libshviotqt WITH_IOTQT)
check_shv_dep(cli-examples LIBSHV_WITH_CLI_EXAMPLES libshvbroker WITH_BROKER)
check_shv_dep(gui-examples LIBSHV_WITH_GUI_EXAMPLES libshvvisu WITH_VISU)

if(LIBSHV_WITH_CHAINPACK)
add_subdirectory(libshvchainpack/c)
endif()
if(WITH_CHAINPACK_CPP)
if(LIBSHV_WITH_CHAINPACK_CPP)
add_subdirectory(libshvchainpack)
endif()
if(WITH_CORE)
if(LIBSHV_WITH_CORE)
add_subdirectory(libshvcore)
endif()

if(WITH_COREQT)
if(USE_QT6)
if(LIBSHV_WITH_COREQT)
if(LIBSHV_USE_QT6)
message(STATUS "Enabling Qt6 support")
if(EMSCRIPTEN)
find_package(Qt6 COMPONENTS Core LinguistTools Network OPTIONAL_COMPONENTS WebSockets Widgets)
Expand Down Expand Up @@ -180,46 +180,46 @@ if(WITH_COREQT)
endif()

# We'll error out if the user has explicitly enabled websocket support, but Qt WebSockets aren't available.
if(WITH_SHV_WEBSOCKETS AND NOT QtWebSockets_FOUND)
if(LIBSHV_WITH_WEBSOCKETS AND NOT QtWebSockets_FOUND)
message(FATAL_ERROR "SHV websocket support explicitly enabled, but Qt WebSockets weren't found!")
endif()

# Otherwise enable websocket support based on whether we found Qt6 WebSockets.
if (NOT DEFINED WITH_SHV_WEBSOCKETS)
set(WITH_SHV_WEBSOCKETS ${QtWebSockets_FOUND})
if (NOT DEFINED LIBSHV_WITH_WEBSOCKETS)
set(LIBSHV_WITH_WEBSOCKETS ${QtWebSockets_FOUND})
endif()

if (WITH_SHV_WEBSOCKETS)
if (LIBSHV_WITH_WEBSOCKETS)
message(STATUS "SHV websocket support enabled")
else()
message(STATUS "SHV websocket support disabled")
endif()

if(WITH_CORE)
if(LIBSHV_WITH_CORE)
if(Qt_FOUND)
set(CMAKE_AUTOMOC ON)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_AUTOMOC_MOC_OPTIONS "-b${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt_moc_disable_warnings.h")
endif()

if(WITH_COREQT)
if(LIBSHV_WITH_COREQT)
add_subdirectory(libshvcoreqt)
endif()
if(WITH_IOTQT)
if(LIBSHV_WITH_IOTQT)
add_subdirectory(libshviotqt)
endif()
if(NOT EMSCRIPTEN)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(WITH_LDAP)
if(LIBSHV_WITH_LDAP)
find_package(PkgConfig REQUIRED)
pkg_check_modules(OpenLDAP REQUIRED ldap>=2.5.0)
endif()
if(WITH_BROKER)
if(LIBSHV_WITH_BROKER)
add_subdirectory(libshvbroker)
endif()
endif()

if(WITH_CLI_EXAMPLES)
if(LIBSHV_WITH_CLI_EXAMPLES)
message(STATUS "CLI examples will be built")
add_subdirectory(examples/cli/minimalshvclient)
add_subdirectory(examples/cli/shvdevice)
Expand All @@ -229,10 +229,10 @@ if(WITH_CORE)
if(QtWidgets_FOUND)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(WITH_VISU)
if(LIBSHV_WITH_VISU)
add_subdirectory(libshvvisu)
endif()
if(WITH_GUI_EXAMPLES)
if(LIBSHV_WITH_GUI_EXAMPLES)
message(STATUS "GUI example samplegraph application will be built")
add_subdirectory(examples/gui/samplegraph)
endif()
Expand All @@ -245,7 +245,7 @@ if(WITH_CORE)
endif()

option(BUILD_SHV_UTILS "Whether to build ccp2cp, cp2cp, and cpmerge" ON)
check_shv_dep(shv-utils BUILD_SHV_UTILS libshvcoreqt WITH_CORE)
check_shv_dep(shv-utils BUILD_SHV_UTILS libshvcoreqt LIBSHV_WITH_CORE)

# Utils
if(BUILD_SHV_UTILS)
Expand Down
2 changes: 1 addition & 1 deletion libshvbroker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ qt_add_library(libshvbroker
)
add_library(libshv::libshvbroker ALIAS libshvbroker)

if(WITH_SHV_WEBSOCKETS)
if(LIBSHV_WITH_WEBSOCKETS)
target_sources(libshvbroker PRIVATE
src/rpc/websocketserver.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion libshviotqt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ target_include_directories(libshviotqt PUBLIC
)
target_compile_definitions(libshviotqt PRIVATE SHVIOTQT_BUILD_DLL)

if(WITH_SHV_WEBSOCKETS)
if(LIBSHV_WITH_WEBSOCKETS)
target_sources(libshviotqt PRIVATE
include/shv/iotqt/rpc/websocket.h
src/rpc/websocket.cpp
Expand Down

0 comments on commit 51bdd3f

Please sign in to comment.