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 cleanup & MinGW support #121

Merged
merged 12 commits into from
Jul 25, 2019
Merged

Conversation

crypto-ape
Copy link

@crypto-ape crypto-ape commented Apr 8, 2019

Hey Monkeys!

I have cleaned up the CMake build a little bit:

  • removed unused and irrelevant code
    • editline, old and not supported Boost library handling, OpenSSL config search, ...
  • the custom FindBoost.cmake is evil
    • I have put it into a separate directory and it is loaded only on Apple ecosystem
  • MinGW support ( supports building Windows binaries on Linux )
  • renamed _mm_crc32_u64 to _mm_crc32_u64_impl
    • caused Internal compiler errors with MSVC because the symbol is already defined as a compiler intrinsic

Hopefully this helps.

Related: bitshares/bitshares-core#1706

Ape out!

@jmjatlanta
Copy link

jmjatlanta commented Apr 8, 2019

* the custom `FindBoost.cmake` is evil
  
  * I have put it into a separate directory and it is loaded only on Apple ecosystem

Do you know why the FindBoost.cmake is there? It would be nice to get rid of it totally. I do not know the reason for its existence, and therefore am hesitant to remove it.

Another note: Your comment says you moved it to another directory, but it seems as if it is gone completely. Perhaps you need to include that directory in a commit?

@crypto-ape
Copy link
Author

* the custom `FindBoost.cmake` is evil
  
  * I have put it into a separate directory and it is loaded only on Apple ecosystem

Do you know why the FindBoost.cmake is there? It would be nice to get rid of it totally. I do not know the reason for its existence, and therefore am hesitant to remove it.

Another note: Your comment says you moved it to another directory, but it seems as if it is gone completely. Perhaps you need to include that directory in a commit?

I would also like to remove the custom FindBoost.cmake, which overrides the find_package(BOOST...) routines.

What is does, is that it overrides the functionality that is bundled with your current version of CMake, effectively using Boost searching routines from an older CMake version regardless of your current version.

It brings only trouble when used on Windows and with newer Boost versions.

Why is it there ?
My guess is, that somebody wanted to fix a problem in the search routine, copied the most up-to-date version of FindBoost.cmake, patched it and included it in the project to override the default behaviour.

I have looked into it, and probably found the FindBoost.cmake that was the original file.

For convinience a comparison between the original file from CMake and our file in bitshares/fc is here:
crypto-ape/find-boost-compare@4075201

The interesting changes are:

  1. extending the list of default Boost search paths
  2. adding pthread as a library in some cases

So,

  1. This looks like a correct usage of BOOST_ROOT and/or building an up-to-date Boost from source would fix.
  2. This is more interesting.
    It might be related to the error that broke the Travis CI task ( compilation failed with linker undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12').
    Importantly, the whole project was built successfully, making me think that the pthread
    dependency is defined in some other way in the main project.

Yes @jmjatlanta, it seems like I have forgotten to include the commit with the FindBoost.cmake moved to Legacy folder.

Additionally, I will rework the CMake script to include the standalone FindPython scripts only for relevant CMake versions ( < 3.10 ).

@pmconrad
Copy link

It seems the travis build needs libpthread...

@pmconrad
Copy link

We've discussed this within the Core Team and agreed to bump CMake minimum to 3.2.

@pmconrad
Copy link

Can we get rid of FindBoost completely? If it's only required on APPLE and can be worked around by setting BOOST_LIBRARYDIR we should remove it and update the documentation. @jmjatlanta what do you think?

@crypto-ape
Copy link
Author

Thanks @pmconrad for the review.

I have just compiled the whole project under Windows.

I do not have a Mac which I can experiment on, but you can see from the diff crypto-ape/find-boost-compare@4075201 that the custom FindBoost is not doing anything special compared to the default FindBoost.

Just to be sure, someone with a Mac should verify the compilation with default system libraries and BOOST_LIBRARYDIR set, before removing the legacy script.

@jmjatlanta
Copy link

jmjatlanta commented Apr 23, 2019

I have a mac. I will test to figure out what is needed for getting rid of FindBoost.cmake.

I believe we always need pthread on platforms that have it. Is there a reason to not simply add it to our CMakeLists.txt file?

@crypto-ape
Copy link
Author

I have a mac. I will test to figure out what is needed for getting rid of FindBoost.cmake.

Please try compile it with the custom FindBoost.cmake file deleted, so CMake would use the bundled version.
If it won't compile automatically, try setting the BOOST_LIBRARYDIR.

I believe we always need pthread on platforms that have it. Is there a reason to not simply add it to our CMakeLists.txt file?

I would not force this. If Boost requires pthread, let him ask for it.

@pmconrad
Copy link

Please rebase on master to get rid of the conflict

@crypto-ape
Copy link
Author

Rebased & tested.

Compiles with MinGW on Linux and Windows hosts.

# - this is here to fix some older CMake + Boost configurations
set(Boost_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Boost" PARENT_SCOPE)

if (APPLE OR USE_LEGACY_FIND_BOOST)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed on apple or can we remote the old FindBoost? @jmjatlanta

CMakeLists.txt Outdated
@@ -22,6 +22,8 @@ INCLUDE(GetGitRevisionDescription)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckLibcxxAtomic)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm experimenting with cross-compiling core using gitian. It seems that the CheckLibcxxAtomic include must be moved further down, after FIND_PACKAGE(Boost....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried compiling it recently, with current codebase ?

I successfully compiled the the main project's develop branch with fc being this branch, using Gitian through Docker, without the need to move CheckLibcxxAtomic.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yes, seems to be working now.
I wonder why - CheckLibcxxAtomic compiles a test program that uses boost::lockfree - how can that work before boost has been detected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you were right.

I have moved CheckLibcxxAtomic after find_package(Boost...), because in some cases it did not work, specifically when working with MinGW compiler.

Still, I can't explain the behaviour. I thought that CMake might do some multi-pass magic, but it has probably something to do with default compiler paths and also with the fact that the main project runs find_package(Boost...) before CheckLibcxxAtomic.

@pmconrad
Copy link

pmconrad commented Jun 8, 2019

@crypto-ape please check https://github.com/pmconrad/bitshares-gitian/pull/6 and the cross-build instructions contained therein.

@pmconrad
Copy link

pmconrad commented Jun 8, 2019

More precisely, I'm unsure which of these hacks are generally applicable and which ones are only due to the way I'm building this and the 3rd party libs.
https://github.com/pmconrad/bitshares-gitian/blob/d9e7f2fac9d6bc9da25abcd5f25d55f909435df0/descriptors/bitshares-core-win.yml#L113-L117

@crypto-ape
Copy link
Author

crypto-ape commented Jun 11, 2019

@pmconrad, I looked into this

@pmconrad
Copy link

Checked both my native Linux build and Gitian cross-build for windows with latest develop plus merging this.
Gitian build produces errors that are unrelated to this PR (apparently the new hardening compiler options are not checked properly).
Linux build works but seems to be more sensitive to the cmake-boost version interdependency.
I think we should merge this and hopefully get rid of the included FindBoost later.

Thanks @crypto-ape !

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

Successfully merging this pull request may close these issues.

4 participants