Code Monkey home page Code Monkey logo

cmake-cookbook's Introduction

License: MIT

Travis AppVeyor CircleCI

GitHub issues GitHub forks GitHub stars

CMake Cookbook

This repository collects sources for the recipes contained in the CMake Cookbook published by Packt and authored by Radovan Bast and Roberto Di Remigio

Table of contents

cmake-cookbook's People

Contributors

axiosleo avatar bast avatar ericantidot avatar kwoodle avatar robertodr avatar theerk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmake-cookbook's Issues

How to properly compile an MPI program?

There seems to be two options, which are currently shown in the C++ and C examples for recipe 16 in Chapter 3.

C++ Example

Use the MPI compiler wrapper. If I do VERBOSE=1 make I see the compile line:

/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/bin/mpicxx     
-std=c++11 -o CMakeFiles/hello-mpi.dir/hello-mpi.cpp.o 
-c /home/roberto/Workspace/robertodr/cmake-recipes/Chapter03/recipe-0016/cxx-example/hello-mpi.cpp

and the link line:

/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/bin/mpicxx      
CMakeFiles/hello-mpi.dir/hello-mpi.cpp.o  -o hello-mpi -rdynamic 

mpicxx --showme:compile shows that the wrapper has added

-I/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/include -pthread

mpicxx --showme:link shows that the wrapper has added

-pthread -Wl,-rpath -Wl,/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/lib -Wl,--enable-new-dtags -L/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/lib -lmpi_cxx -lmpi

C Example

Use the unwrapped compiler and then prepare the wrapper using CMake using target_compile_options, target_include_directories and target_link_libraries. The compile line is:

/nix/store/j1yn1np5g2vgm5yp8qmqg67x8riwy2kr-gcc-wrapper-5.4.0/bin/gcc   
-I/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/include  
-std=c11 -o CMakeFiles/hello-mpi.dir/hello-mpi.c.o   
-c /home/roberto/Workspace/robertodr/cmake-recipes/Chapter03/recipe-0016/c-example/hello-mpi.c

and the link line is:

/nix/store/j1yn1np5g2vgm5yp8qmqg67x8riwy2kr-gcc-wrapper-5.4.0/bin/gcc     
CMakeFiles/hello-mpi.dir/hello-mpi.c.o  -o hello-mpi -rdynamic -lmpi

Whereas the wrapper tells me:

-I/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/include -pthread

for the compile line and

-pthread -Wl,-rpath -Wl,/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/lib -Wl,--enable-new-dtags -L/nix/store/8f1nmsd4cw7sdk8xrssmkk9zbq26pc2j-openmpi-1.10.1/lib -lmpi

for the link line

Question

This is the same for C and C++ (and most likely for Fortran too) You can see that some of the wrapper options have disappeared, both for compiling and linking. What is the best practice here? Reset the compiler to the wrapped version discovered by CMake?

Numbering of recipes: per chapter instead of global index?

Should we perhaps number recipes only within chapters? For book readers they will be easy to find since they can search by chapter. For instance chapter-9/recipe-4 would be 4th recipe in chapter 9. This would spare us the work and possible breakage of renumbering recipes. Especially if we draft recipes across chapters and not chapter by chapter.

CI script

The CI script is very simple-minded. Things to improve:

  1. The report dumps all info to screen. Should we agree on a less cluttered output format? EDIT I have also noticed that non-STATUS messages from CMake are printed elsewhere from where you'd expect (separate from the CMake configuration output stream) I suspect CMake might use the stderr instead of stdout for these.
  2. Some of the failing builds, fail the whole CI. But maybe we want to show that some stuff doesn't work. How can we implement an "expected failure" behavior?
  3. It would be good to move the environment variables inside the various subdirectories. I think this will contribute to have cleaner build matrices on the CI services. I have played around with direnv to no avail. Maybe I can get you up to speed with what I've done, before we decide the next steps.

Build specification with menu.yml

My take on menu.yml:

appveyor:
    env:
    definitions:
    expect_failure:
        - true
        - fail_message: 'Build does not work in this case'
drone:
    env:
    definitions:
        - CMAKE_CXX_COMPILER: g++
travis:
   env:
   definitions:
       - CMAKE_CXX_COMPILER: g++

Three mandatory sections, with fixed names, one for each CI service we are using.
Each section has env and definitions subsections. The end goal is to avoid logical switches in the top-level script (like the one we have now for Visual Studio and Fortran)

Travis CI on Mac OS X failures

Builds on Travis CI for Mac OS X are currently failing. Two problems:

  • Apple Clang does not support OpenMP. Some recipes in chapter 3 require OpenMP. We need the expected failure section in menu.yml for this.
  • The implementation of UUID seems not to be the same as on Linux, specifically the uuid_generate_time_safe is not there. I'll fix it by using uuid_generate in the source code.

FindPythonModule.cmake

See here: cmake-recipes/Chapter03/recipe-0013/FindPythonModule.cmake
Works:
find_package(PythonModule COMPONENTS numpy REQUIRED)
Works:
find_package(PyhonModule COMPONENTS numpy matplotlib REQUIRED)
Works:
find_package(PythonModule 1.12 EXACT COMPONENTS numpy REQUIRED)
Ambiguous:
find_package(PythonModule 1.12 EXACT COMPONENTS numpy matplotlib REQUIRED)

Convert ISSUES.md to proper GitHub issues

Roberto, can you please have a go at this since you know best what you meant when writing these down. It would IMO be good to track them in one place (issue tracker).

Chapter 3 outline modifications

This will give us a complete draft of Chapter 3 without offsetting deadlines:

  • Remove recipe-0017 (OpenACC parallel environment)
  • Show how to find LibUUID with pkg-config in recipe-0020
  • Move recipe-0021 to a later chapter (to be discussed)
  • When we have FindOpenACC.cmake either beef up recipe-0020 or add a recipe-0021

AppVeyor CI

AppVeyor ships 3 images (see here):

  • VS 2013. MinGW and Cygwin pre-installed
  • VS 2015. MinGW and Cygwin pre-installed
  • VS 2017. Only Cygwin pre-installed

We should use all three images, because:

  • CMake 3.0 supports VS 2013, at most.
  • CMake 3.9 supports all three of them.

However, I am not sure about MinGW vs. Cygwin. Should we try to use both? Or just one of the two?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.