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

Add CMake build system. #27

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

KokaKiwi
Copy link

Because cmake is pretty cool :D

@MatthewLM
Copy link
Owner

Hi, thanks for this. I'll have to take a closer look, when cbitcoin is closer to being complete. What benefits does cmake give over make? Maintaining two build systems might be more effort than it is worth.

@KokaKiwi
Copy link
Author

cmake is good for creating libraries because cmake provide a builtin command 'find_package' which is pretty cool to find others libraries (and so, it's easier to compile an executable with a library like cbitcoin)
And cmake allow to include sub-projects, and it's more easier to link these to a main executable (for example, if I have a project with cbitcoin as a subdirectory, i can link my main executable with cbitcoin)

@MatthewLM
Copy link
Owner

Okay. I'm going to finish what I'm working on at the moment and I will try to take a closer look at cmake then. One thing it will need is a "test" goal, which runs the tests, which I've implemented with the current Makefile system.

@scathey1
Copy link

Great! I'm following this and will have time to give a whirl on Intel32 and PPC64 architectures when your cmake mods are done.

@KokaKiwi
Copy link
Author

I added tests in CMakeLists.txt and fixed a small warning I had when compiling testCBScript.c (with clang and -Wall)

- Updated Doxyfile to doxygen 1.8.4
@MatthewLM
Copy link
Owner

Hi. I gave this a go but unfortunately there seems to be some linking problems with the dependency libraries when running make:

Undefined symbols for architecture x86_64:
  "_CBAddressStorageDeleteAddress", referenced from:
      _CBNetworkCommunicatorProcessMessageAutoDiscovery in CBNetworkCommunicator.c.o
  "_CBAddressStorageSaveAddress", referenced from:
      _CBNetworkCommunicatorProcessMessageAutoDiscovery in CBNetworkCommunicator.c.o
  "_CBBlockChainStorageBlockExists", referenced from:
      _CBFullValidatorBasicBlockValidation in CBFullValidator.c.o
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
  "_CBBlockChainStorageCommitData", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
      _CBFullValidatorAddBlockToOrphans in CBFullValidator.c.o
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
      _CBFullValidatorProcessIntoBranch in CBFullValidator.c.o
  "_CBBlockChainStorageDeleteBlock", referenced from:
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
  "_CBBlockChainStorageDeleteTransactionRef", referenced from:
      _CBFullValidatorUpdateUnspentOutputsBackward in CBFullValidator.c.o
  "_CBBlockChainStorageDeleteUnspentOutput", referenced from:
      _CBFullValidatorUpdateUnspentOutputsForward in CBFullValidator.c.o
      _CBFullValidatorUpdateUnspentOutputsBackward in CBFullValidator.c.o
  "_CBBlockChainStorageExists", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
  "_CBBlockChainStorageGetBlockLocation", referenced from:
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
  "_CBBlockChainStorageGetBlockTarget", referenced from:
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
  "_CBBlockChainStorageGetBlockTime", referenced from:
      _CBFullValidatorGetMedianTime in CBFullValidator.c.o
  "_CBBlockChainStorageIsTransactionWithUnspentOutputs", referenced from:
      _CBFullValidatorCompleteBlockValidation in CBFullValidator.c.o
  "_CBBlockChainStorageLoadBasicValidator", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
  "_CBBlockChainStorageLoadBlock", referenced from:
      _CBFullValidatorProcessIntoBranch in CBFullValidator.c.o
      _CBFullValidatorUpdateUnspentOutputsAndLoad in CBFullValidator.c.o
  "_CBBlockChainStorageLoadBranch", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
  "_CBBlockChainStorageLoadBranchWork", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
  "_CBBlockChainStorageLoadOrphan", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
  "_CBBlockChainStorageLoadOutputs", referenced from:
      _CBFullValidatorUpdateUnspentOutputsBackward in CBFullValidator.c.o
  "_CBBlockChainStorageLoadUnspentOutput", referenced from:
      _CBFullValidatorInputValidation in CBFullValidator.c.o
  "_CBBlockChainStorageMoveBlock", referenced from:
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
  "_CBBlockChainStorageReset", referenced from:
      _CBFullValidatorProcessIntoBranch in CBFullValidator.c.o
  "_CBBlockChainStorageSaveBasicValidator", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
      _CBFullValidatorAddBlockToOrphans in CBFullValidator.c.o
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
      _CBFullValidatorProcessIntoBranch in CBFullValidator.c.o
  "_CBBlockChainStorageSaveBlock", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
      _CBFullValidatorAddBlockToBranch in CBFullValidator.c.o
  "_CBBlockChainStorageSaveBranch", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
      _CBFullValidatorAddBlockToBranch in CBFullValidator.c.o
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
      _CBFullValidatorProcessIntoBranch in CBFullValidator.c.o
      _CBFullValidatorSaveLastValidatedBlocks in CBFullValidator.c.o
  "_CBBlockChainStorageSaveBranchWork", referenced from:
      _CBInitFullValidator in CBFullValidator.c.o
      _CBFullValidatorAddBlockToBranch in CBFullValidator.c.o
      _CBFullValidatorProcessBlock in CBFullValidator.c.o
  "_CBBlockChainStorageSaveOrphan", referenced from:
      _CBFullValidatorAddBlockToOrphans in CBFullValidator.c.o
  "_CBBlockChainStorageSaveTransactionRef", referenced from:
      _CBFullValidatorUpdateUnspentOutputsForward in CBFullValidator.c.o
  "_CBBlockChainStorageSaveUnspentOutput", referenced from:
      _CBFullValidatorUpdateUnspentOutputsForward in CBFullValidator.c.o
      _CBFullValidatorUpdateUnspentOutputsBackward in CBFullValidator.c.o
  "_CBBlockChainStorageUnspentOutputExists", referenced from:
      _CBFullValidatorInputValidation in CBFullValidator.c.o
  "_CBCloseSocket", referenced from:
      _CBNetworkCommunicatorAcceptConnection in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorStopListening in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorConnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDidConnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDisconnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorStartListening in CBNetworkCommunicator.c.o
  "_CBEcdsaVerify", referenced from:
      _CBScriptExecute in CBScript.c.o
  "_CBEndTimer", referenced from:
      _CBNetworkCommunicatorStopPings in CBNetworkCommunicator.c.o
  "_CBExitEventLoop", referenced from:
      _CBNetworkCommunicatorStop in CBNetworkCommunicator.c.o
  "_CBFreeSecureRandomGenerator", referenced from:
      _CBFreeAddressManager in CBAddressManager.c.o
      _CBInitAddressManager in CBAddressManager.c.o
  "_CBGetMilliseconds", referenced from:
      _CBNetworkCommunicatorOnCanReceive in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorOnCanSend in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorOnHeaderRecieved in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorOnMessageReceived in CBNetworkCommunicator.c.o
  "_CBLogError", referenced from:
      _CBNewAddressFromRIPEMD160Hash in CBAddress.c.o
      _CBInitAddressFromRIPEMD160Hash in CBAddress.c.o
      _CBNewAddressFromString in CBAddress.c.o
      _CBNewAddressBroadcast in CBAddressBroadcast.c.o
      _CBNewAddressBroadcastFromData in CBAddressBroadcast.c.o
      _CBAddressBroadcastDeserialise in CBAddressBroadcast.c.o
      _CBAddressBroadcastSerialise in CBAddressBroadcast.c.o
      ...
  "_CBNewEventLoop", referenced from:
      _CBNetworkCommunicatorStart in CBNetworkCommunicator.c.o
  "_CBNewSecureRandomGenerator", referenced from:
      _CBInitAddressManager in CBAddressManager.c.o
  "_CBNewSocket", referenced from:
      _CBNetworkCommunicatorConnect in CBNetworkCommunicator.c.o
  "_CBRandomSeed", referenced from:
      _CBAddressManagerSetBucketIndex in CBAddressManager.c.o
  "_CBRipemd160", referenced from:
      _CBScriptExecute in CBScript.c.o
  "_CBSecureRandomInteger", referenced from:
      _CBInitAddressManager in CBAddressManager.c.o
      _CBAddressManagerGetAddresses in CBAddressManager.c.o
      _CBAddressManagerSetBucketIndex in CBAddressManager.c.o
      _CBAddressManagerSelectAndRemoveAddress in CBAddressManager.c.o
  "_CBSecureRandomSeed", referenced from:
      _CBInitAddressManager in CBAddressManager.c.o
  "_CBSha160", referenced from:
      _CBScriptExecute in CBScript.c.o
  "_CBSha256", referenced from:
      _CBInitAddressFromRIPEMD160Hash in CBAddress.c.o
      _CBDecodeBase58Checked in CBBase58.c.o
      _CBBlockCalculateHash in CBBlock.c.o
      _CBBuildMerkleTree in CBMerkleNode.c.o
      _CBNetworkCommunicatorSendMessage in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorOnMessageReceived in CBNetworkCommunicator.c.o
      _CBScriptExecute in CBScript.c.o
      ...
  "_CBSocketAccept", referenced from:
      _CBNetworkCommunicatorAcceptConnection in CBNetworkCommunicator.c.o
  "_CBSocketAddEvent", referenced from:
      _CBNetworkCommunicatorAcceptConnection in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorOnCanReceive in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorOnCanSend in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorConnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDidConnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorSendMessage in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorStartListening in CBNetworkCommunicator.c.o
      ...
  "_CBSocketBind", referenced from:
      _CBNetworkCommunicatorStartListening in CBNetworkCommunicator.c.o
  "_CBSocketCanAcceptEvent", referenced from:
      _CBNetworkCommunicatorStartListening in CBNetworkCommunicator.c.o
  "_CBSocketCanReceiveEvent", referenced from:
      _CBNetworkCommunicatorAcceptConnection in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDidConnect in CBNetworkCommunicator.c.o
  "_CBSocketCanSendEvent", referenced from:
      _CBNetworkCommunicatorAcceptConnection in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDidConnect in CBNetworkCommunicator.c.o
  "_CBSocketConnect", referenced from:
      _CBNetworkCommunicatorConnect in CBNetworkCommunicator.c.o
  "_CBSocketDidConnectEvent", referenced from:
      _CBNetworkCommunicatorConnect in CBNetworkCommunicator.c.o
  "_CBSocketFreeEvent", referenced from:
      _CBNetworkCommunicatorAcceptConnection in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorStopListening in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorConnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDidConnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorDisconnect in CBNetworkCommunicator.c.o
      _CBNetworkCommunicatorStartListening in CBNetworkCommunicator.c.o
  "_CBSocketListen", referenced from:
      _CBNetworkCommunicatorStartListening in CBNetworkCommunicator.c.o
  "_CBSocketReceive", referenced from:
      _CBNetworkCommunicatorOnCanReceive in CBNetworkCommunicator.c.o
  "_CBSocketRemoveEvent", referenced from:
      _CBNetworkCommunicatorOnCanSend in CBNetworkCommunicator.c.o
  "_CBSocketSend", referenced from:
      _CBNetworkCommunicatorOnCanSend in CBNetworkCommunicator.c.o
  "_CBStartTimer", referenced from:
      _CBNetworkCommunicatorStartPings in CBNetworkCommunicator.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libcbitcoin.dylib] Error 1
make[1]: *** [CMakeFiles/cbitcoin.dir/all] Error 2
make: *** [all] Error 2

@KokaKiwi
Copy link
Author

Oh, I don't have this error on Arch (64bits too).
I think it's because core library require to be linked against other sub-libs (storage, network, etc...).
But it's weird, because in your Makefile.in, the core library is linked alone without other sub-libs.
I'll change the CMakeLists.txt to make core library linked against sub-libs.

@MatthewLM
Copy link
Owner

I know what the issue is. The core library is designed to be separated from the dependency libraries, so that it doesn't need to be linked to them. What I've done is used -undefined dynamic_lookup for OSX (I'm using OSX) to allow for weak linking. The dependency libraries are later linked to the executables. So if instead of linking the core library to the dependencies, the core library can be linked with -undefined dynamic_lookup and thus it should work on OSX as then the symbols do not need to exist when linking the core library.

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.

3 participants