Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake - QT 6 / QT 5 / gcc-10.1 quadmath macOS Big Sur 11.1 #209

Closed
camots opened this issue Jan 19, 2021 · 20 comments
Closed

cmake - QT 6 / QT 5 / gcc-10.1 quadmath macOS Big Sur 11.1 #209

camots opened this issue Jan 19, 2021 · 20 comments

Comments

@camots
Copy link

camots commented Jan 19, 2021

Hi,

I'm running XaoS on macOS Big Sur 11.1
I do not know if this already exists, but I have created a CMakeLists.txt for XaoS to be able to use the cmake build engine.

Works great for clang for QT 5.x and QT 6.0 with some minor adjustments in the code like this:

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
filename->setMinimumWidth(metric.width(filename->text()) * 1.1);
#else
filename->setMinimumWidth(metric.horizontalAdvance(filename->text()) * 1.1);
#endif

However, by using clang on macOS, you have no quadmath support, i.e. you cannot use the USE_FLOAT128 flag. In order to enjoy much deeper zooming, you have to switch to gcc-10.1.
Compiles fine with QT5.12 or QT5.15, but for QT 6.0 I had to made some more adjustments to the code because the QT 6.0 distribution for macOS is not fully compatible with gcc.

The QT 6 header file qopenglcontext_platform.h located in QtGui caused gcc-10.1 to fail.
However, this file is not really needed by XaoS. It is included by "QtWidgets".
The solution was to not replace QtWidgets by a series of QtXXXX includes which are required for the XaoS code. To my understanding, QtWidgets is just for convenience, but it includes far too much than actually is needed.

So for me, I have everything together and it is working great.

What I would like to see in the official distribution of XaoS:
Support for cmake.
Quad precision support for macOS?

I've attached my CMakeLists.txt below. It has to be placed in the src directory.
For clang compilation, just comment out the two lines
set(CMAKE_C_COMPILER gcc-10.1)
set(CMAKE_CXX_COMPILER g++-10.1)
and remove -DUSE_FLOAT128

Best regards and thank you very much for this great program

# because of CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS
cmake_minimum_required(VERSION 3.14.0)

project(XaoS)

# use gcc because Apple clang lacks quadmath support
set(CMAKE_C_COMPILER gcc-10.1)
set(CMAKE_CXX_COMPILER g++-10.1)

# add definitions
add_definitions(-DUSE_FLOAT128 -DUSE_SFFE -DSFFE_CMPLX_GSL)

# resolve symbolic links
set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE)

if(NOT CMAKE_BUILD_TYPE)
   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
endif(NOT CMAKE_BUILD_TYPE)

# set the project directory
get_filename_component(PROJECT_DIR ${CMAKE_SOURCE_DIR} PATH)

# set the install prefix
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
   set(CMAKE_INSTALL_PREFIX ${PROJECT_DIR} CACHE PATH "Install prefix" FORCE )
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

# set-up some QT stuff
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# turn on additional options
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# look for QT5 or QT6
find_package(QT NAMES Qt5 Qt6 COMPONENTS Widgets PrintSupport REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)

# OS specific stuff
# on macOS the QT libraries are usually not installed into the system library folders 
IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   list(APPEND CMAKE_INSTALL_RPATH ${Qt${QT_VERSION_MAJOR}_DIR}/../..)
ENDIF()

# set c++ flags
set(CMAKE_CXX_STANDARD 17)

# the include and link paths
include_directories(
   engine
   include
   ui
   ui-hlp
   ${CMAKE_PREFIX_PATH}/include
)

link_directories(${CMAKE_PREFIX_PATH}/lib)

# set the Application icon, the first line is the property added to Info.plist
set(MACOSX_BUNDLE_ICON_FILE XaoS.icns)
set(XaoS_ICON ${CMAKE_CURRENT_SOURCE_DIR}/ui/XaoS.icns)
set_source_files_properties(${XaoS_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")

# Multilingual support: *.ts -> build/*.qm
FIND_PACKAGE(Qt${QT_VERSION_MAJOR}LinguistTools)
file(GLOB TRANSLATION_FILES ${PROJECT_DIR}/i18n/*.ts)

# qt_add_translation is universal for 5.15 and newer
IF (${QT_VERSION} VERSION_LESS 5.15.0)
   qt5_add_translation(QM_FILES ${TRANSLATION_FILES})
ELSE()
   qt_add_translation(QM_FILES ${TRANSLATION_FILES})
ENDIF()

# grab all sources for executable
file(GLOB CXX_FILES ui/*.cpp ui-hlp/*.cpp util/*.cpp engine/*.cpp sffe/*.cpp)
file(GLOB C_FILES sffe/*.c)
add_executable(XaoS MACOSX_BUNDLE 
   ${CXX_FILES} 
   ${C_FILES} 
   ${QM_FILES} 
   ${XaoS_ICON} 
   ui/XaoS.qrc
)

# Link
target_link_libraries(XaoS Qt${QT_VERSION_MAJOR}::Widgets quadmath)

# install bundle
install(TARGETS XaoS DESTINATION bin)

# install translations
install(FILES ${QM_FILES} DESTINATION bin/XaoS.app/Contents/Resources/translations)

# install catalogs and tutorial
install(DIRECTORY ../catalogs ../tutorial DESTINATION bin/XaoS.app/Contents/Resources)

# install example files
file(GLOB EXAMPLE_FILES ${PROJECT_DIR}/examples/*/*.xpf)
install(FILES ${EXAMPLE_FILES} DESTINATION bin/XaoS.app/Contents/Resources/examples)
@kovzol
Copy link
Contributor

kovzol commented Jan 19, 2021

Great, thanks for this thorough contribution! I will check your ideas step by step, as soon as possible.
I am a bit confused with your ideas with cmake. Is qmake planned to be obsolete in the new Qt versions? Is there any benefit if we add cmake support? Is it eventually useful to drop qmake support at the same time (for future versions)? Thanks for any clarification in advance.

@camots
Copy link
Author

camots commented Jan 20, 2021 via email

@kovzol
Copy link
Contributor

kovzol commented Jan 22, 2021

OK, I think it is good idea to have a cmake based build system as well. You can either fork XaoS, patch it and create a pull request, or simply create a tarball and send it to me directly. Thanks in advance!

@jblang
Copy link
Member

jblang commented Jan 30, 2021

qmake works fine for the project and I don't really see what cmake gives us other than added complexity and another dependency that developers have to install. We finally got away from autoconf and I am not sold on changing the build system again. If there is a specific problem you can't solve in qmake, please explain. "It's an industry standard" is not a good enough reason to switch.

@kovzol
Copy link
Contributor

kovzol commented Jan 30, 2021

I agree with J.B. Adding a cmake based build system increases complexity and we want to avoid that right now. ;-)

@kovzol kovzol closed this as completed Jan 30, 2021
@kanurag94
Copy link
Member

setMinimumWidth(metric.width(filename->text()) * 1.1);
Is deprecated since Qt5, I'd make a commit soon to replace it.

@kovzol kovzol reopened this Jan 30, 2021
@camots
Copy link
Author

camots commented Jan 31, 2021

@jblang
Maybe there is a fundamental misunderstanding here: My intention was not to replace qmake by cmake, but to offer it as an alternative. You get cmake support by just adding the CMakeLists.txt. There is no interference with qmake in any way and there is virtually ZERO effort to maintain it. It is an add-on and NOT intended to replace anything!

@kanurag94 :
Actually you have to make more adjustments in order to make the code QT 6 compatible.

@jblang
Copy link
Member

jblang commented Jan 31, 2021

Offering too many alternatives has costs too. How do new developers know which build system they should use? Will you be committed to maintaining the cmake build file indefinitely? If you lose interest, do we have to now maintain two build systems? If we don't maintain the cmake build file and test it on every platform for every release, will we have to deal with people who had problems trying to use it?

Again, if there is some specific problem with the current build system that can't be solved with qmake, I'm open to hearing about it. But if it's just because you like cmake better, that's not a good enough reason for us to take on the additional maintenance burden. I undertook a major effort last year to remove a lot of old code and the autoconf build system, both of which made XaoS harder to understand and to maintain, so I hope you can understand where I'm coming from.

@camots
Copy link
Author

camots commented Feb 1, 2021

@jblang
https://www.qt.io/blog/qt-6-build-system
I guess qmake will likely to be dropped in the future. Just my two cents. Future will show.
I'm fine with any build system. Thank you!

@kovzol
Copy link
Contributor

kovzol commented Feb 1, 2021

@camots I've just read (most of) this thread: https://www.qt.io/blog/2018/10/29/deprecation-of-qbs. It is not clear for me what Qt people want to do with qmake, but I guess it will remain for a while.

@camots
Copy link
Author

camots commented Feb 1, 2021

@kovzol
This blog is from 2018. Let's see what happens...

@jblang
Copy link
Member

jblang commented Feb 1, 2021

Well, I would expect it to be around at least until Qt 7. If the time between Qt 5 and Qt 6 is anything to go by, that'll be another 8 years. But the Qt company is making a lot of decisions I don't like lately, so who knows? Their commitment to open source is now in serious question and there is talk of forking Qt 5.14 because they've just closed the repository and are offering bugfixes to paying customers only. I've also read a lot of people saying that Qt 6 is really not ready for general use, although I haven't tried it myself. Part of me wonders if we made a mistake going all in on Qt. Unfortunately there aren't a lot of cross-platform alternatives with the same level of polish. GTK is great on Linux, OK on Windows, and severely lacking on Mac.

Anyway, we can put your CMakeLists.txt in a contrib folder with a README to say it's not officially supported and that qmake is the recommended build system. That way we can dust if off if we ever need it.

@camots
Copy link
Author

camots commented Feb 1, 2021

I'm working on 2 projects using QT and it was relatively easy to get these running with QT 6.0.
There was also no major problem to get XaoS running with QT 6.0 on macOS Big Sur 11.1.
As far as I know, they will release QT 6.1 in April and a LTS version towards the end of the year
Of course qmake will be around for a couple years more years. There is no hurry to change anything in the build system.

@kovzol
Copy link
Contributor

kovzol commented Oct 16, 2023

@camots We are seriously thinking about changing to cmake. Could you please suggest a CMakeLists.txt for the current version? We use Qt 6, and also WebAssembly should be supported. Thanks for your effort in advance!

@camots
Copy link
Author

camots commented Oct 20, 2023 via email

@kovzol
Copy link
Contributor

kovzol commented Oct 20, 2023

Thanks so much! I am afraid that the zip file is missing from your message, please could you check? Thanks in advance!

@camots
Copy link
Author

camots commented Oct 20, 2023 via email

@kovzol
Copy link
Contributor

kovzol commented Oct 20, 2023 via email

@kovzol
Copy link
Contributor

kovzol commented Jan 20, 2024

Thanks again, @camots, for your wonderful work, and sorry for the very long delay. Now I included your cmake configuration (with some minor updates) in the root folder:
https://github.com/xaos-project/XaoS/blob/master/CMakeLists.txt
Hopefully this new version still works on Mac.

@kovzol
Copy link
Contributor

kovzol commented Jan 20, 2024

I close this issue and continue discussion at #242.

@kovzol kovzol closed this as completed Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants