Any interest in cleaning up CMakeLists.txt?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
ezzieyguywuf
Posts: 528
Joined: Tue May 19, 2015 1:11 am

Any interest in cleaning up CMakeLists.txt?

Postby ezzieyguywuf » Tue Aug 20, 2019 3:41 am

I know that for me, personally, I get rather lost in our top-level CMakeLists.txt

I can do the work of "cleaning it up", I'd just like to know (before putting in the effort) how palatable such a change is.

The main change I would make is take each of the various "do something" sections, i.e. "Set up the various compiler flags", "Find python", etc... and create a function for it. Each function would be defined in its own file in the cMake directory.

This would allow our CMakeLists.txt file to look something like;

Code: Select all

...
CheckCompilerFlagsAndUpdate()
LocatePythonInstallation()
LocatePySideandShiboken()
....etc...
I also propose that we remove the FREECAD_VERSION check in code blocks such as:

Code: Select all

if (FREECAD_VERSION VERSION_GREATER 0.16)
        set(BUILD_ENABLE_CXX_STD "C++11"  CACHE STRING  "Enable C++ standard")
        set_property(CACHE BUILD_ENABLE_CXX_STD PROPERTY STRINGS
                     "C++11"
                     "C++14"
                     "C++17"
                     "C++20"
        )

        if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
            message(FATAL_ERROR "FreeCAD 0.17 and later requires C++11.  G++ must be 4.7 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}")
        elseif(CMAKE_COMPILER_IS_CLANGXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
            message(FATAL_ERROR "FreeCAD 0.17 and later requires C++11.  Clang must be 3.3 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}")
        endif()
    endif(FREECAD_VERSION VERSION_GREATER 0.16)
The fact that there is a specific git branch preserved for each release means that if in the future anyone wishes to build a specific version (say v0.16), it should be as simple as checking out that branch and compiling. That snapshot will include the CMakeLists.txt version from way back then, thus we should not need to incorporate this check.
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Any interest in cleaning up CMakeLists.txt?

Postby yorik » Tue Aug 20, 2019 1:43 pm

+1
ezzieyguywuf
Posts: 528
Joined: Tue May 19, 2015 1:11 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby ezzieyguywuf » Tue Aug 20, 2019 1:58 pm

yorik wrote:
Tue Aug 20, 2019 1:43 pm
+1
:P Alright then, I will get working on this.
wmayer
Site Admin
Posts: 14614
Joined: Thu Feb 19, 2009 10:32 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby wmayer » Tue Aug 20, 2019 2:26 pm

Maybe wait a couple of days before starting because there are a few things I want to remove beforehand. Then there is a pending PR that I want to merge too.
ezzieyguywuf
Posts: 528
Joined: Tue May 19, 2015 1:11 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby ezzieyguywuf » Tue Aug 20, 2019 2:26 pm

wmayer wrote:
Tue Aug 20, 2019 2:26 pm
Maybe wait a couple of days before starting because there are a few things I want to remove beforehand. Then there is a pending PR that I want to merge too.
:thumbs_up: you got it.
ezzieyguywuf
Posts: 528
Joined: Tue May 19, 2015 1:11 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby ezzieyguywuf » Sat Aug 24, 2019 7:38 pm

wmayer wrote:
Tue Aug 20, 2019 2:26 pm
ping
What's the status on these changes you mentioned?
wmayer
Site Admin
Posts: 14614
Joined: Thu Feb 19, 2009 10:32 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby wmayer » Sun Aug 25, 2019 7:48 pm

Done.
ezzieyguywuf
Posts: 528
Joined: Tue May 19, 2015 1:11 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby ezzieyguywuf » Mon Sep 02, 2019 3:54 am

Update: Here is a first-pass at pulling a majority of the logic out ouf our top-level CMakeLists.txt.

As of now, I have not made any adjustments to the actual logic. Rather, I simply copy/pasted what was already in CMakeLists.txt and moved it to a sub-directory of our cMake folder.

That being said - I'm open to input. The current approach creates individual files for each new macro that is called in the top-level CMakeLists.txt.

The reason of one file per macro is that this should (hopefully) make future updates/changes to CMake-related items less painful. It should also make it very clear what is being changed in a given commit.
User avatar
sgrogan
Posts: 5241
Joined: Wed Oct 22, 2014 5:02 pm

Re: Any interest in cleaning up CMakeLists.txt?

Postby sgrogan » Wed Sep 04, 2019 9:32 pm

ezzieyguywuf wrote:
Mon Sep 02, 2019 3:54 am
Update: Here is a first-pass at pulling a majority of the logic out ouf our top-level CMakeLists.txt.
I wish you luck on this, much appreciated.
I haven't tested yet, but the first thing I noticed
cMake/FindOpenCasCade.cmake
cMake/FreeCAD_Helpers/FindOpenCasCade.cmake

I know you are just trying to move the stuff and fix the logic next, but this elicited one WTF ;)
There are similar ones FindCoin3D.cmake for example.
ezzieyguywuf
Posts: 528
Joined: Tue May 19, 2015 1:11 am

Re: Any interest in cleaning up CMakeLists.txt?

Postby ezzieyguywuf » Wed Sep 04, 2019 10:18 pm

sgrogan wrote:
Wed Sep 04, 2019 9:32 pm
ezzieyguywuf wrote:
Mon Sep 02, 2019 3:54 am
Update: Here is a first-pass at pulling a majority of the logic out ouf our top-level CMakeLists.txt.
I wish you luck on this, much appreciated.
I haven't tested yet, but the first thing I noticed
cMake/FindOpenCasCade.cmake
cMake/FreeCAD_Helpers/FindOpenCasCade.cmake

I know you are just trying to move the stuff and fix the logic next, but this elicited one WTF ;)
There are similar ones FindCoin3D.cmake for example.
Thank you for your comments and well wishes.

I was hesitant to use FindXXX macro names due to the potential confusion with make find_package finders. Your comments have convinced me that I should change the names.

Maybe SetUpXXX
cron