diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ada0d0dc5f7b179e7f9a4309e5f6a0504b9717a..7a22b6bde094133a50668e978ec6c4aa978f4a9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,22 +20,11 @@ INCLUDE(GNUInstallDirs) INCLUDE(CMakePackageConfigHelpers) INCLUDE(GenerateExportHeader) -string(SUBSTRING ${CMAKE_GENERATOR} 0 14 CMAKE_GENERATOR_SHORT) -if(CMAKE_GENERATOR_SHORT MATCHES "Visual Studio ") - message(STATUS "Generating VS project") - set(CMAKE_CXX_COMPILER_ID "MSVC") - set(ENABLE_TEST false) - set(ENABLE_STATIC true) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /W0") -endif() - -if (NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) - ADD_DEFINITIONS( - ${QT_DEFINITIONS} - -fexceptions - -O2 - ) -endif() +ADD_DEFINITIONS( + ${QT_DEFINITIONS} + -fexceptions + -O2 +) # Options set(CHK_FREEABLE_BEFORE_ERASE_ACCOUNT_DESCRIPTION @@ -94,41 +83,39 @@ IF((${ENABLE_TEST} MATCHES true)) SET(ENABLE_LIBWRAP true) # because mocks use the same interface present in src/qtwrapper ENDIF() -if (NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) # Enable some useful warnings - ADD_DEFINITIONS( - -Wall - -Wextra - -Wmissing-declarations - -Wmissing-noreturn - -Wpointer-arith - -Wcast-align - -Wwrite-strings - -Wformat-nonliteral - -Wformat-security - -Wswitch-enum - -Winit-self - -Wmissing-include-dirs - -Wundef - -Wmissing-format-attribute - -Wno-reorder - -Wunused - -Wuninitialized - -Woverloaded-virtual - -Wunused-value - -pedantic - -Wnonnull - -Wsequence-point - #-Wsystem-headers - -Wsizeof-pointer-memaccess - #-Wuseless-cast - -Wvarargs - - #See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578 - -Wno-unused-function - -Wno-attributes - ) -endif() +ADD_DEFINITIONS( + -Wall + -Wextra + -Wmissing-declarations + -Wmissing-noreturn + -Wpointer-arith + -Wcast-align + -Wwrite-strings + -Wformat-nonliteral + -Wformat-security + -Wswitch-enum + -Winit-self + -Wmissing-include-dirs + -Wundef + -Wmissing-format-attribute + -Wno-reorder + -Wunused + -Wuninitialized + -Woverloaded-virtual + -Wunused-value + -pedantic + -Wnonnull + -Wsequence-point + #-Wsystem-headers + -Wsizeof-pointer-memaccess + #-Wuseless-cast + -Wvarargs + + #See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578 + -Wno-unused-function + -Wno-attributes +) #Add more warnings for compilers that support it. I used this command: #curl https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Warning-Options.html | \ @@ -211,9 +198,7 @@ IF(${ENABLE_LIBWRAP} MATCHES true) ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/src/qtwrapper) ADD_DEFINITIONS(-DENABLE_LIBWRAP=true) # Use native calls (no dbus) - if (NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) - ADD_DEFINITIONS(-Wno-unknown-pragmas) - endif() + ADD_DEFINITIONS(-Wno-unknown-pragmas) SET(ENABLE_QT5 true) # Use Qt5 MESSAGE(STATUS "Compiling with qtwrapper enabled, Qt5 enabled.") @@ -250,19 +235,17 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_BINARY_DIR}) -IF(NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")) - # Build dbus api - IF(DEFINED RING_XML_INTERFACES_DIR) - SET (dbus_xml_introspecs_path ${RING_XML_INTERFACES_DIR}) - ELSEIF(EXISTS "${RING_BUILD_DIR}/../bin/dbus") - SET (dbus_xml_introspecs_path ${RING_BUILD_DIR}/../bin/dbus) - ELSE() - SET (dbus_xml_introspecs_path ${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces) - ENDIF() - - MESSAGE(STATUS "Using Ring DBus-XML interfaces in ${dbus_xml_introspecs_path}") +# Build dbus api +IF(DEFINED RING_XML_INTERFACES_DIR) + SET (dbus_xml_introspecs_path ${RING_XML_INTERFACES_DIR}) +ELSEIF(EXISTS "${RING_BUILD_DIR}/../bin/dbus") + SET (dbus_xml_introspecs_path ${RING_BUILD_DIR}/../bin/dbus) +ELSE() + SET (dbus_xml_introspecs_path ${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces) ENDIF() +MESSAGE(STATUS "Using Ring DBus-XML interfaces in ${dbus_xml_introspecs_path}") + #File to compile SET( libringclient_LIB_SRCS #Data objects @@ -710,53 +693,45 @@ ENDIF() IF(NOT ${ENABLE_TEST} MATCHES true) QT5_WRAP_CPP(LIB_HEADER_MOC ${libringclient_PRIVATE_HDRS}) ENDIF() +ADD_LIBRARY( ringclient SHARED ${libringclient_LIB_SRCS} ${LIB_HEADER_MOC} ) IF(NOT ${ENABLE_STATIC} MATCHES false) - message(STATUS "Configuring as static lib") - add_library( ringclient_static STATIC ${libringclient_LIB_SRCS} ${LIB_HEADER_MOC} ) - target_link_libraries(ringclient_static Qt5::Core) - target_link_libraries( ringclient_static - -lpthread - ${QT_QTDBUS_LIBRARY} - ${QT_QTCORE_LIBRARY} - Qt5::Sql - ) - SET_TARGET_PROPERTIES( ringclient_static - PROPERTIES VERSION ${GENERIC_LIB_VERSION} - ) -ELSE() - message(STATUS "Configuring as shared lib") - add_library( ringclient SHARED ${libringclient_LIB_SRCS} ${LIB_HEADER_MOC} ) - target_link_libraries(ringclient Qt5::Core) + ADD_LIBRARY( ringclient_static STATIC ${libringclient_LIB_SRCS} ${LIB_HEADER_MOC} ) + target_link_libraries(ringclient_static Qt5::Core) + TARGET_LINK_LIBRARIES( ringclient_static + -lpthread + ${QT_QTDBUS_LIBRARY} + ${QT_QTCORE_LIBRARY} + Qt5::Sql + ) + SET_TARGET_PROPERTIES( ringclient_static + PROPERTIES VERSION ${GENERIC_LIB_VERSION} + ) ENDIF() +target_link_libraries(ringclient Qt5::Core) + IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") target_link_libraries(ringclient Qt5::DBus) - IF(${ENABLE_STATIC} MATCHES true) + IF(NOT ${ENABLE_STATIC} MATCHES false) target_link_libraries(ringclient_static Qt5::DBus) ENDIF() ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - FIND_PACKAGE(Qt5Concurrent) + FIND_PACKAGE(Qt5Concurrent) - #For some reason, QSemaphore wont compile on Windows without QtConcurrent - IF(${ENABLE_STATIC} MATCHES true) - target_link_libraries(ringclient_static Qt5::Concurrent) - ELSE() - target_link_libraries(ringclient Qt5::Concurrent) - ENDIF() + #For some reason, QSemaphore wont compile on Windows without QtConcurrent + target_link_libraries(ringclient Qt5::Concurrent) ENDIF() -IF (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - TARGET_LINK_LIBRARIES( ringclient - -lpthread - ${QT_QTCORE_LIBRARY} - Qt5::Sql - ) -ENDIF() +TARGET_LINK_LIBRARIES( ringclient + -lpthread + ${QT_QTCORE_LIBRARY} + Qt5::Sql +) IF(${ENABLE_LIBWRAP} MATCHES true) - IF((NOT ${ring_BIN} MATCHES "ring_BIN-NOTFOUND") AND (${ENABLE_STATIC} MATCHES false)) + IF(NOT ${ring_BIN} MATCHES "ring_BIN-NOTFOUND") TARGET_LINK_LIBRARIES( ringclient qtwrapper ${ring_BIN} @@ -764,7 +739,7 @@ IF(${ENABLE_LIBWRAP} MATCHES true) ELSE() # Allow building with undefined symbols when only the daemon headers are provided # It speeds up our CI builds - IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") SET_TARGET_PROPERTIES( ringclient PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" ) ENDIF() ENDIF() @@ -774,7 +749,6 @@ IF(${ENABLE_LIBWRAP} MATCHES true) ${ring_BIN} ) ENDIF() - ELSE() TARGET_LINK_LIBRARIES( ringclient ${QT_QTDBUS_LIBRARY} @@ -793,11 +767,9 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") ENDIF() ENDIF() -if(${ENABLE_STATIC} MATCHES false) - SET_TARGET_PROPERTIES( ringclient - PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_VERSION} - ) -endif() +SET_TARGET_PROPERTIES( ringclient + PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_VERSION} +) SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include) @@ -842,21 +814,22 @@ INSTALL( FILES ${libringclient_api_LIB_HDRS} #higher priority than the prefixed one. STRING(REPLACE "${CMAKE_LIBRARY_ARCHITECTURE}" "" SANE_LIBRARY_PATH "${CMAKE_INSTALL_FULL_LIBDIR}" ) +INSTALL( TARGETS ringclient + ARCHIVE DESTINATION ${SANE_LIBRARY_PATH} + RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin + LIBRARY DESTINATION ${SANE_LIBRARY_PATH} + DESTINATION ${SANE_LIBRARY_PATH} +) + IF(NOT ${ENABLE_STATIC} MATCHES false) - INSTALL( TARGETS ringclient_static - ARCHIVE DESTINATION ${SANE_LIBRARY_PATH} - LIBRARY DESTINATION ${SANE_LIBRARY_PATH} - DESTINATION ${SANE_LIBRARY_PATH} - ) -ELSE() - INSTALL( TARGETS ringclient - ARCHIVE DESTINATION ${SANE_LIBRARY_PATH} - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin - LIBRARY DESTINATION ${SANE_LIBRARY_PATH} - DESTINATION ${SANE_LIBRARY_PATH} - ) + INSTALL( TARGETS ringclient_static + ARCHIVE DESTINATION ${SANE_LIBRARY_PATH} + LIBRARY DESTINATION ${SANE_LIBRARY_PATH} + DESTINATION ${SANE_LIBRARY_PATH} + ) ENDIF() + SET(LIB_INSTALL_DIR ${SANE_LIBRARY_PATH}) # Create a CMake config file diff --git a/make-lrc.bat b/make-lrc.bat deleted file mode 100644 index 333aba3fca73c470dff4e62e7b09e9b3ab63feee..0000000000000000000000000000000000000000 --- a/make-lrc.bat +++ /dev/null @@ -1,141 +0,0 @@ -:: Ring - native Windows LRC project generator - -@echo off -setlocal - -if "%1" == "/?" goto Usage -if "%~1" == "" goto Usage - -set doGen=N -set doBuild=N - -set SCRIPTNAME=%~nx0 - -if "%1"=="gen" ( - set doGen=Y -) else if "%1"=="build" ( - set doBuild=Y -) else ( - goto Usage -) - -set arch=N - -shift -:ParseArgs -if "%1" == "" goto FinishedArgs -if /I "%1"=="x86" ( - set arch=x86 -) else if /I "%1"=="x64" ( - set arch=x64 -) else ( - goto Usage -) -shift -goto ParseArgs - -:FinishedArgs -if "%arch%"=="x86" ( - set MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=Release /p:Platform=Win32 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS% -) else if "%arch%"=="x64" ( - set MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=Release /p:Platform=x64 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS% -) - -@setlocal - -set VSInstallerFolder="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer" -if %PROCESSOR_ARCHITECTURE%==x86 set VSInstallerFolder="%ProgramFiles%\Microsoft Visual Studio\Installer" - -pushd %VSInstallerFolder% -for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( - set VSLATESTDIR=%%i -) -popd - -echo VS Installation folder: %VSLATESTDIR% - -if not exist "%VSLATESTDIR%\VC\Auxiliary\Build\vcvarsall.bat" ( - echo: - echo VSInstallDir not found or not installed correctly. - goto cleanup -) - -if %PROCESSOR_ARCHITECTURE%==x86 ( - set Comp_x86=x86 10.0.15063.0 - set Comp_x64=x86_amd64 10.0.15063.0 -) else ( - set Comp_x86=amd64_x86 10.0.15063.0 - set Comp_x64=amd64 10.0.15063.0 -) - -set path=%path:"=% -if "%arch%"=="x86" ( - call "%VSLATESTDIR%"\\VC\\Auxiliary\\Build\\vcvarsall.bat %Comp_x86% -) else if "%arch%"=="x64" ( - call "%VSLATESTDIR%"\\VC\\Auxiliary\\Build\\vcvarsall.bat %Comp_x64% -) - -if "%arch%" neq "N" ( - if "%doGen%" neq "N" ( - goto genLRC - ) else if "%doBuild%" neq "N" ( - goto buildLRC - ) - goto :eof -) -goto Usage - -:genLRC -setlocal EnableDelayedExpansion -set DaemonDir=%cd%\\..\\daemon -mkdir msvc -cd msvc -set PATH=C:\\Program Files\\CMake\\bin\\;%PATH% -if "echo QtDir is: %QtDir%"=="" ( - echo Error: QtDir not specified - goto cleanup -) -set CMAKE_GENERATOR_STRING="" -set CMAKE_OPTIONS="" -if "%arch%"=="x86" ( - set CMAKE_GENERATOR_STRING="Visual Studio 15 2017 Win32" - set QtCmakeDir=%QtDir%\\msvc2017\\lib\\cmake - set CMAKE_OPTIONS=-DQt5Core_DIR=!QtCmakeDir!\\Qt5Core -DQt5Sql_DIR=!QtCmakeDir!\\Qt5Sql -DQt5LinguistTools_DIR=!QtCmakeDir!\\Qt5LinguistTools -DQt5Concurrent_DIR=!QtCmakeDir!\\Qt5Concurrent -Dring_BIN=!DaemonDir!\MSVC\x86\ReleaseLib_win32\bin\dring.lib -DRING_INCLUDE_DIR=!DaemonDir!\src\dring -) else if "%arch%"=="x64" ( - set CMAKE_GENERATOR_STRING="Visual Studio 15 2017 Win64" - set QtCmakeDir=%QtDir%\\msvc2017_64\\lib\\cmake - set CMAKE_OPTIONS=-DQt5Core_DIR=!QtCmakeDir!\\Qt5Core -DQt5Sql_DIR=!QtCmakeDir!\\Qt5Sql -DQt5LinguistTools_DIR=!QtCmakeDir!\\Qt5LinguistTools -DQt5Concurrent_DIR=!QtCmakeDir!\\Qt5Concurrent -Dring_BIN=!DaemonDir!\MSVC\x64\ReleaseLib_win32\bin\dring.lib -DRING_INCLUDE_DIR=!DaemonDir!\src\dring -) -cmake .. -G !CMAKE_GENERATOR_STRING! !CMAKE_OPTIONS! -endlocal -goto cleanup - -:buildLRC -:: build qtwrapper -msbuild msvc\src\qtwrapper\qtwrapper.vcxproj %MSBUILD_ARGS% -:: build lrc -msbuild msvc\ringclient_static.vcxproj %MSBUILD_ARGS% -goto cleanup - -@endlocal - -:Usage -echo: -echo The correct usage is: -echo: -echo %0 [action] [architecture] -echo: -echo where -echo: -echo [action] is: gen ^| build -echo [architecture] is: x86 ^| x64 -echo: -echo For example: -echo %SCRIPTNAME% gen x86 - gen x86 static lib vs projects for qtwrapper/lrc -echo %SCRIPTNAME% build x64 - build x64 qtwrapper/lrc static libs -echo: -goto :eof - -:cleanup -endlocal -exit /B %ERRORLEVEL% \ No newline at end of file