SingularInversions / FaceGenBaseLibrary

A simple cross-platform C++17 library for developing computational 3D graphics applications.
MIT License
46 stars 23 forks source link

Create CMakeLists.txt file for this library #4

Closed ab-cpp closed 6 years ago

ab-cpp commented 6 years ago

We need to retain, as similarly as is possible with cmake, the existing build functionality:

The solution files are currently automatically created but with our own tool which doesn't support all the platforms we'd like to.

We're open to suggestions about make use of existing CMakeLists.txt files for the included third party libraries (in combination), if this makes things easier.

tkaden4 commented 6 years ago

Ive almost completed this. I will push later this afternoon. All that needs to be added is the correct compiler flags and output directories.

tkaden4 commented 6 years ago

I have what I believe to be a finished version in my repo. Let me know if that works. It correctly builds on my system, which is ubuntu with gcc.

ab-cpp commented 6 years ago

OK, I'm correcting my previous post here as I'm a cmake newbie ...

Ubuntu is a great start. Here's what I get on Windows on your repo after deleting 'CMakeCache.txt':

D:\fg\tkaden4\FaceGenBaseLibrary\source>cmake . -- Building for: Visual Studio 15 2017 -- The CXX compiler identification is MSVC 19.13.26128.0 -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- WHAT -- status: D:/fg/tkaden4/FaceGenBaseLibrary/source/lib/win32/ -- The C compiler identification is MSVC 19.13.26128.0 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done CMake Error in LibTpBoost/CMakeLists.txt: A logical block opening on the line

D:/fg/tkaden4/FaceGenBaseLibrary/source/LibTpBoost/CMakeLists.txt:8 (if)

is not closed.

-- Configuring incomplete, errors occurred! See also "D:/fg/tkaden4/FaceGenBaseLibrary/source/CMakeFiles/CMakeOutput.log".

ab-cpp commented 6 years ago

Also note that I need to have multiple visual studio versions build in parallel, like the existing system, if this is possible under cmake. Currently I get a 'CMakeCache.txt' error if I change the VS target.

ab-cpp commented 6 years ago

OK, I fixed the issue in the boost CMakeLists.txt to get an SLN file but unfortunately there are build errors ... I guess you don't have a windows system and VS to test on ? The other issue is that it creates an SLN with only 32-bit. Of course I need 64-bit as well. I think I read that cmake creates separate SLNs for 32/64 which is kind of stupid and annoying but if that's what need to be done ... then we'll need that.

ab-cpp commented 6 years ago

I've now tried building on Ubuntu 16.04 (clang installed and latest cmake installed) and I get this error:

[ 10%] Building C object LibImageMagickCore/CMakeFiles/LibImageMagickCore.dir/ImageMagick-6.6.2/coders/png_0.c.o /home/andrew/tkaden4/FaceGenBaseLibrary/source/LibImageMagickCore/ImageMagick-6.6.2/coders/png_0.c:96:17: fatal error: png.h: No such file or directory compilation terminated. LibImageMagickCore/CMakeFiles/LibImageMagickCore.dir/build.make:1037: recipe for target 'LibImageMagickCore/CMakeFiles/LibImageMagickCore.dir/ImageMagick-6.6.2/coders/png_0.c.o' failed make[2]: [LibImageMagickCore/CMakeFiles/LibImageMagickCore.dir/ImageMagick-6.6.2/coders/png_0.c.o] Error 1 CMakeFiles/Makefile2:238: recipe for target 'LibImageMagickCore/CMakeFiles/LibImageMagickCore.dir/all' failed make[1]: [LibImageMagickCore/CMakeFiles/LibImageMagickCore.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2

ab-cpp commented 6 years ago

It seems the 'Makefile' created by cmake just redirects back to 'cmake'. Is this how cmake normally works ? Is it possible to have cmake create a makefile that only requires 'make' and the compiler/linker ?

sohailsomani commented 6 years ago

@ab-cpp (Subscribed to your repo and saw this)

You may want to consider using the Ninja generator instead, it's a much faster build system.

ab-cpp commented 6 years ago

cmake will generate ninja files as I understand it. Ninja files look a lot like makefiles ... any idea why it's faster ?

sohailsomani commented 6 years ago

@ab-cpp on that point, I think you will have to hit Google but I did write a post about a different comparison here: https://uint32t.blogspot.ca/2014/05/moving-from-scons-to-cmake.html

ab-cpp commented 6 years ago

I'll probably keep our custom build generator for existing platforms as I like they way it configures better. But need cmake for android and xcode.

sohailsomani commented 6 years ago

Ah ok, I thought you were switching everything over.

ab-cpp commented 6 years ago

Custom build system creates separate SLN/VCXPROJ files and output directories for each VS version, as well as SLNs with both 32 and 64bit build options ... it doesn't seem like cmake can do this ... ?

tkaden4 commented 6 years ago

I've fixed the missing png errors on my fork, which was odd because it was compiling without it just fine, even though it seems to be a required library. As for the Visual studio issue, it seems that cmake is limited to one build target at a time, and that the only workaround would be to create a shell script to call it multiple times. There might be some good in investigating the CMake plugin/feature of Visual Studio, though.

ab-cpp commented 6 years ago

OK, gotcha, if that's all cmake can output then leave it at that. Just re-cloned your repo and everything now builds on Ubuntu but warnings need to be turned of for ImageMagick. On windows I tried building but ImageMagick doesn't build. Do you have access to Windows+VS ?

ab-cpp commented 6 years ago

A clear description of files used in build is in source for our custom build tool in: ~/source/LibFgBase/src/FgCons.cpp (or perhaps clearer than looking at the VS solution / project files).

tkaden4 commented 6 years ago

I don't have access to Windows currently. I'll take a look at that file and see what I can do, though.

tkaden4 commented 6 years ago

What error are you getting on windows?

ab-cpp commented 6 years ago

Looks like wrong OS flags or wrong files included:

LibImageMagickCore Build started 2018-05-04 11:52:30 AM. Target ResolveProjectReferences: Target InitializeBuildStatus: Touching "LibImageMagickCore.dir\Release\LibImage.B037CBEB.tlog\unsuccessfulbuild". Target CustomBuild: All outputs are up-to-date. Target ClCompile: X11_stubs.c d:\fg\tkaden4\facegenbaselibrary\source\libimagemagickcore\imagemagick-6.6.2\xlib\x11_stubs.c(1590): error C2143: syntax error: missing ')' before 'type' d:\fg\tkaden4\facegenbaselibrary\source\libimagemagickcore\imagemagick-6.6.2\xlib\x11_stubs.c(1590): error C2059: syntax error: ')' d:\fg\tkaden4\facegenbaselibrary\source\libimagemagickcore\imagemagick-6.6.2\xlib\x11_stubs.c(1592): error C2085: 'a': not in formal parameter list d:\fg\tkaden4\facegenbaselibrary\source\libimagemagickcore\imagemagick-6.6.2\xlib\x11_stubs.c(1592): error C2143: syntax error: missing ';' before '{' C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(380,5): error MSB6006: "CL.exe" exited with code 2. Done building target "ClCompile" in project "LibImageMagickCore.vcxproj" -- FAILED.

Done building project "LibImageMagickCore.vcxproj" -- FAILED.

tkaden4 commented 6 years ago

Ah yes, cant compile xlib on windows. I've suppressed the warnings and removed the xlib dependency for windows.

ab-cpp commented 6 years ago

Now errors in imagemagick like this:

2> 2> cl : Command line error D8021: invalid numeric argument '/W3;/w' 2> 2> cl : Command line error D8021: invalid numeric argument '/W3;/w' 2> 2> cl : Command line error D8021: invalid numeric argument '/W3;/w' 2> 2> cl : Command line error D8021: invalid numeric argument '/W3;/w'

tkaden4 commented 6 years ago

My most recent push should have fixed it.

ab-cpp commented 6 years ago

Still lots of these:

2>Target ClCompile: 2> 2> cl : Command line error D8021: invalid numeric argument '/W3;/w' 2> 2> cl : Command line error D8021: invalid numeric argument '/W3;/w'

After I pulled I deleted the top level 'CMakeCache.txt' before running 'cmake .', then in VS did a clean before building. Not sure if I'm supposed to do some kind of clean command with cmake ...

tkaden4 commented 6 years ago

Usually I make a directory called build and run cmake .. from there. If that doesnt fix it then the msvc compiler is doing odd things.

ab-cpp commented 6 years ago

I tried that and loaded the fresh SLN in 'build'. That's how cmake is supposed to be used then ? Same issue (affects ImageMagick files).

tkaden4 commented 6 years ago

Turns out list(APPEND ...) wont work for compiler flags. I will update shortly.

tkaden4 commented 6 years ago

I've updated the compiler options, and if all goes well it should work.

ab-cpp commented 6 years ago

Got rid of issue in imagemagick lib but still persists in LibFgWin:

5> cl : Command line warning D9025: overriding '/W3' with '/w'

ab-cpp commented 6 years ago

Wait, let me delete everything, it's unclear that just deleting 'build' is working

ab-cpp commented 6 years ago

Yup, still lots of these after removing entire repo and re-pulling and running cmake:

2> 2> cl : Command line warning D9025: overriding '/W3' with '/w'

tkaden4 commented 6 years ago

Looks like cmake is adding in some things i didnt want it to. I've changed it to override the default options.

tkaden4 commented 6 years ago

Also, if you need to do a debug or release build, you must specify -DCMAKE_BUILD_TYPE=Debug|Release. I've set it to default to Debug now

ab-cpp commented 6 years ago

Same problem. I'm going to close this issue now as I think we've gotten as far as we can and there are no other contributors. I'll issue the bounty.