Skip to content

Commit

Permalink
CMake; Spaces to tabs; Fix build with Qt 6; Default to x86_64 but det…
Browse files Browse the repository at this point in the history
…ect arm64 (drop 32bit support)
  • Loading branch information
TinoDidriksen committed Dec 28, 2023
1 parent 5ea713b commit dd90379
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 364 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IndentWidth: 4
TabWidth: 4
UseTab: ForIndentation
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# http://editorconfig.org/
root = yes
# https://editorconfig.org/
root = true

[*]
charset = utf-8
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2015 Tino Didriksen <mail@tinodidriksen.com>
2015-2023 Tino Didriksen <mail@tinodidriksen.com>
70 changes: 70 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
project(apertium-simpleton
VERSION 0.2.0
LANGUAGES CXX
)

# Release or Debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MACOSX_RPATH ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

include(GNUInstallDirs)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /std:c++latest /Zc:__cplusplus /permissive- /W4 /MP")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-deprecated")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")

include(CheckCXXCompilerFlag)

# Require latest possible C++ standard
foreach(flag "-std=c++23" "-std=c++2b" "-std=c++20" "-std=c++2a" "-std=c++17")
string(REGEX REPLACE "[^a-z0-9]" "-" _flag ${flag})
CHECK_CXX_COMPILER_FLAG(${flag} COMPILER_SUPPORTS_${_flag})
if(COMPILER_SUPPORTS_${_flag})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
set(_ENABLED_CXX ${flag})
break()
endif()
endforeach()
if(NOT _ENABLED_CXX)
message(FATAL_ERROR "Could not enable at least C++17 - upgrade your compiler")
endif()
endif()

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
set(QT_LIBS Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)

if(QT_VERSION_MAJOR GREATER_EQUAL 6)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core5Compat)
set(QT_LIBS ${QT_LIBS} Qt${QT_VERSION_MAJOR}::Core5Compat)
endif()

add_definitions(-DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x051100)

if(WIN32)
add_definitions(-DUNICODE -D_UNICODE -D_SECURE_SCL=0 -D_ITERATOR_DEBUG_LEVEL=0 -D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN -DVC_EXTRALEAN -DNOMINMAX)
else()
add_definitions(-D_POSIX_C_SOURCE=200112)
endif()

add_subdirectory(src)
19 changes: 0 additions & 19 deletions apertium-simpleton.pro

This file was deleted.

14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(apertium-simpleton
common.hpp
installer.cpp
installer.hpp
installer.ui
main.cpp
simpleton.cpp
simpleton.hpp
simpleton.ui
)

target_link_libraries(apertium-simpleton ${QT_LIBS})

install(TARGETS apertium-simpleton RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
20 changes: 17 additions & 3 deletions src/common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Tino Didriksen <mail@tinodidriksen.com>
* Copyright (C) 2015-2023, Tino Didriksen <mail@tinodidriksen.com>
*
* This file is part of apertium-simpleton
*
Expand All @@ -22,11 +22,25 @@
#define COMMON_HPP_fc74fd919e58451d89f5d0bba814925a

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtCore5Compat/QTextCodec>
#endif

#if QT_VERSION >= 0x050400
#define DATALOCATION QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
#define DATALOCATION QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
#else
#define DATALOCATION QStandardPaths::writableLocation(QStandardPaths::DataLocation)
#define DATALOCATION QStandardPaths::writableLocation(QStandardPaths::DataLocation)
#endif

#ifdef _MSC_VER
// warning C4512: assignment operator could not be generated
#pragma warning (disable: 4512)
// warning C4456: declaration hides previous local declaration
#pragma warning (disable: 4456)
// warning C4458: declaration hides class member
#pragma warning (disable: 4458)
// warning C4312: 'operation' : conversion from 'type1' to 'type2' of greater size
#pragma warning (disable: 4312)
#endif

#endif
Loading

0 comments on commit dd90379

Please sign in to comment.