Skip to content

[CMake] build flavors: win32, win32a, sdl2 (multi-platform), x11 (multi-platform) - #52

Closed
jwinarske wants to merge 20 commits into
Bill-Gray:masterfrom
jwinarske:master
Closed

jwinarske wants to merge 20 commits into
Bill-Gray:masterfrom
jwinarske:master

Conversation

@jwinarske

Copy link
Copy Markdown
Contributor

Hi Bill,

I've done some work with CMake/msbuild related to your project. I need to do a bit more work, but I wanted to see if this is something you would entertain merging.

Example to build x86 and x86_64 from a VS Dev Cmd Prompt:
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=c:\temp\PDCurses\dist\x86\bin -G"Visual Studio 14 2015" && cd ..
mkdir build64 && cd build64
cmake .. -DCMAKE_INSTALL_PREFIX=c:\temp\PDCurses\dist\x86_64\bin -G"Visual Studio 14 2015 Win64" && cd ..
cmake --build build --config Debug --target install
cmake --build build64 --config Debug --target install

Binary bits get copied to the CMAKE_INSTALL_PREFIX variable value. In the above cases c:\temp\PDCurses\dist\

Joel

@Bill-Gray

Copy link
Copy Markdown
Owner

Hi Joel,

Yes, I would consider merging this. I've never used CMake, but there seem to be those who are quite fond of it and for whom this would be a nice addition. (This might be a good opportunity for me to give CMake a try and see if it's something I ought to be using regularly.) I don't see a way in which it "interferes" with existing code (i.e., it can be added with a high degree of confidence that nothing will get broken).

Speaking from the aforementioned near-total knowledge of CMake: should this be extended to include X11, SDL1, and/or SDL2? (I'd assume DOS and OS2 would be out of the picture.)

@jwinarske

Copy link
Copy Markdown
Contributor Author

Hi Bill,

Cool!

The CMake implementation certainly could be extended for X11, SDL1, and SDL2.

This current commit enables building DLL with proper exports, and addresses missing libs only for ARM.

These are some additional example usage/generator scenarios:
mkdir build64 && cd build64
cmake .. -DCMAKE_INSTALL_PREFIX=c:\temp\PDCurses\dist\x86_64\bin -G"NMake Makefiles"
nmake install
-or-
mkdir buildarm && cd buildarm
cmake .. -DCMAKE_INSTALL_PREFIX=c:\temp\PDCurses\dist\arm\bin -G"Visual Studio 14 2015 ARM" -DPDC_DLL_BUILD=ON -DPDC_WIDE=TRUE
cmake --build build --config Debug --target install

Packaging is next. Cheers

@GitMensch

Copy link
Copy Markdown
Collaborator

Note: There are plans for removing the def files completely, see https://github.com/Bill-Gray/PDCurses/pull/48 (I just wait for Bill to leave a "go" for this, ideally with an issue to track this).

@INRIX-joel-winarske I don't see why this shouldn't be extended to win32 and win32a - please share your thoughts. It would be nice to have the vc[x]proj files generated (ideally one sln containing one project for each of the [under Win32 working] projects: win32 win32a sdl2 [maybe sdl1]).

@Bill-Gray I think adding CMake is fine as long as the working (and maybe later on the generated) Makefiles aren't removed from the repo - I really dislike to force anyone to install "another 'nearly standard' tool" just to be able to create the build.

@jwinarske

Copy link
Copy Markdown
Contributor Author

Currently you can build any configuration type, and it generates output for both win32 and win32a.
Available configurations are:

Debug
MinSizeRel
Release
RelWithDebugInfo

So build like this:

mkdir build64
cd build64
cmake .. -DCMAKE_INSTALL_PREFIX=c:\temp\PDCurses\dist\x86_64 -G"Visual Studio 14 2015 Win64" -DPDC_DLL_BUILD=ON -DPDC_WIDE=TRUE
cd ..
cmake --build build --target install --config Debug
cmake --build build --target install --config MinSizeRel
cmake --build build --target install --config Release
cmake --build build --target install --config RelWithDebugInfo

Or build/debug via the Visual Studio solution (pdcurses.sln)

@GitMensch Changes are in to support win32/win32a in the same solution.

@Bill-Gray

Copy link
Copy Markdown
Owner

My apologies to you both; I've just thrown a small spanner into the works, which (I hope) may actually make things a little easier.

A while back, I tried out Simon's suggestion for eliminating the .def files. I got it working. Then I threw out my back; I've not been at a keyboard much for a while now.

Now I'm back, and... I've just pushed the changes, which cause all exported functions in curses.h and panel.h to be declared as PDCEX. That gets rid of the .def files. I also fixed a few other small issues that (I think) won't interfere with the proposed CMake changes.

Simon, I agree that there's no reason to remove the existing Makefiles, and plenty of reason to leave them. As mentioned above, one nice thing about Joel's proposed change is that, from the viewpoint of those of us doing 'traditional' builds without CMake, not a single byte changes; we just have a few more files lying around that we totally ignore.

@GitMensch

GitMensch commented Aug 22, 2017 •

Copy link
Copy Markdown
Collaborator

@Bill-Gray Yes, it is fine (my PR https://github.com/Bill-Gray/PDCurses/pull/51 got nearly in).

I did not tried the CMake patch but it looks good so far, it now likely just misses the remove of the def files. @jwinarske : after doing these changes, can you please upload the generated VS project files (VS2008 and VS2017) for review? As I understood this these would have all curses platforms as single projects, all providing each VS Plattforms (Win32,x64,ARM), with different VS configurations (Debug, MinSizeRel, Release, RelWithDebugInfo).
Note (I'm not sure how much you can apply this to CMake generated project files, but you likely do): All VS builds should create PDBs (and ideally they should be shipped with binary releases or - in the case of providing a "minimal" binary release - make them available as extra downloadable package, too)

@GitMensch

Copy link
Copy Markdown
Collaborator

@jwinarske - can you add an additional set of VS configurations that create static libraries? As PDCurses is under Public Domain nearly all programs under all licenses can be linked against a static version without any license issues (this is quite different for a lot of other licenses)...
While it removes the freedom for the user to switch the PDCurses parts independently (for example a bug-fixed version or another curses platform) it gives a slightly additional performance and size boost and convenience in distributing (you don't have to include another dll file).

Thank you.

@jwinarske

Copy link
Copy Markdown
Contributor Author

@GitMensch Changes made. Regarding solution files, what is the desired location for the install prefix? If you don't run "target" install, it will be as is expected. Also where should I document?

@GitMensch

Copy link
Copy Markdown
Collaborator

@jwinarske Looks good. I can't decide on the CMAKE_INSTALL_PREFIX but the default seems reasonable.
Can you please upload the generated VS files?

@jwinarske

jwinarske commented Aug 24, 2017 •

Copy link
Copy Markdown
Contributor Author

@GitMensch

VS 2012 Win64 dev prompt
cd cmake\pdcurses.vs12
cmake ..\.. -G"Visual Studio 12 Win64" -DPDC_DLL_BUILD=TRUE

VS 2015 Win64 dev prompt
cd cmake\pdcurses.vs15
cmake ..\.. -G"Visual Studio 15 Win64" -DPDC_DLL_BUILD=TRUE

@GitMensch

Copy link
Copy Markdown
Collaborator

@jwinarske Thank you for uploading the vs2015 files (I meant to just upload them in this discussion, not committing them but we can remove them later).

Just had a quick look and the generated VS2015 files. The following questions target the "generate once, work on all machines" goal which seems not be the goal of CMake (which seems to be more like Autoconf than like Makefiles) - but maybe CMake can be tweaked this way (allowing the generated files to be uploaded/shipped with source tarballs).

  1. General: Can the generated project files be independent from CMake? They all include CMake references (with the hard-wired CMake installation path from your system). Maybe there is an option for invocation of cmake to generate these files different?

  2. Most important issue: the generated files all contain "hard wired" paths.
    Is it possible to replace these by relative paths with cmake or would this be a manual post-step (which we could either integrate in PDCurses/CMakeLists.txt or add an extra shell/bash script that would be called after running CMake)?
    The most notable would be:

  • C:\Users\joel\Documents\GitHub\PDCurses\ and C:/Users/joel/Documents/GitHub/PDCurses by $(SolutionDir)..\.. (I've done this via NPP - 2165 occurences replaced !)
  • C:\Users\joel\Documents\GitHub\PDCurses\build1[25] or $(SolutionDir)..\..\build1[25]->* $(SolutionDir)..\..\build_vs\
  1. Can the different output / target directories use $(Configuration) instead of its value like MinRelSize?

  2. Can the different platform targets be included in the same vc[x]proj files? Currently they only contain one platform (x64) and $(Platform) isn't part of the output / target directory.

  3. For PDCurses the "install" part in the vc[x]proj files don't make any sense (it is a library which is linked against an application, not an application you'd install - and you would not to install the demos). Note: this is different for POSIX environments where an installation to /usr/... actually makes sense.

@jwinarske

Copy link
Copy Markdown
Contributor Author

@GitMensch Taken care of.
cmake.zip

Regarding your points on the CMake built solution files. I understand your points. Keep in mind CMake was never meant to be a stand alone Solution Wizard, but rather a powerful build automation tool. It has multiple features I'm not using (CPack/CTest). The default install output is changed by setting the CMAKE_INSTALL_PREFIX variable. I used the default per your request.

All that said, CMake is what it is. It's a quick way to automate building, and it accounts for many different platforms.

Cheers

@GitMensch

Copy link
Copy Markdown
Collaborator

@jwinarske

Taken care of

Hm, what exactly was taken care of? Please help me to understand this by answering my questions from the previous post. Thank you!

@Bill-Gray

Copy link
Copy Markdown
Owner

Just a quick note... I see this has been hanging fire for 29 days. As you may have seen (issue #64), it looks as if CMake support is of interest to several folks.

Is it the opinion of you both that we ought to first pull in a Win32 and Win32a solution, and then extend that to include X11, SDL1/2, etc.? Or should we hold off until there's a "full" solution?

@GitMensch

Copy link
Copy Markdown
Collaborator

@Bill-Gray : I've thought about CMake to be a similar tool to automake/autoconf in the way that it is possible to use it for generating VS and other project files that are portable and can be used anywhere without further changes. But it seems that this was a completely wrong assumption and the generated files are system specific, forcing people to always use CMake for setting up the build system (which is OK if this is the "way CMake does it" as long as we have the primary build scripts in Makefiles and the CMake version is only additional).

But in this case there is zero usefulness to upload any of the generated files to vcs and "adding CMake build files" just means to add the CMakelists.txt.
The problem with the forks mentioned in #64 is that all have different "design" approaches... for these files (from the ones I've checked the versions of @jwinarske are best).

@Bill-Gray In general (maybe see a s prerequisite) I'd like to move pdcurses.ico and pdcurses.rc (which is outdated btw) to a single separate directory, maybe pdcurses/build_aux pr pdcurses/additional_win32 or ??? To not have to change the version number and copyright parts I'd replace these by defines that are set in the makefiles from the version include we already have. Thoughts?

In general I'd like to see someone that knows CMake to recheck the versions from @jwinarske (which could be changed to not use the version.rc [if this is possible]) and adding them to a new branch, include the "not VS" parts and when everything (or most) is in merge this "fresh" and (nearly) complete branch to master. This would allow @wmcbrine to merge the changes of this branch to his master if he's interested, too.

@Bill-Gray

Copy link
Copy Markdown
Owner

@GitMensch : If I'm understanding how CMake works, then you're right: you write up your CMakelists.txt file, and CMake uses that to create a makefile for MinGW, Cygwin, etc. I am not really clear as to the utility of this, since we already have makefiles for almost every compiler in existence... perhaps it makes it easier when using PDCurses as part of a larger project that does rely on CMake?

In re pdcurses.ico and pdcurses.rc: those can certainly be moved to a common folder. (Though the .rc files should, perhaps, contain something saying that they're for Win32 console or Win32 GUI. We currently have no .rc file for Windows compiles for SDL1 or SDL2, but perhaps we should... anyway, it seems to me we could end up with different .rc files for each flavor, instead of the current two identical .rc files.)

Not clear on how you're thinking of addressing an automated update to the .rc file, but I'm quite open to that idea. For the moment, I've just made identical updates to both files, just as a first (tiny) step.

@GitMensch

GitMensch commented Sep 24, 2017 •

Copy link
Copy Markdown
Collaborator

Not clear on how you're thinking of addressing an automated update to the .rc file

I don't think of this - I think of using compiler defines (all resource compilers understand them) - just use constants in there and define the actual value (and the port) by defines. Nice side effect: we only need one in a common folder.

@ghost

ghost commented Sep 25, 2017

Copy link
Copy Markdown

@Bill-Gray

Sorry my Github notifications were hidden in a buried folder!

  1. I say go with win32/win32a, then add on. It's easy to add on to the existing solution. I'll take a look at pulling in SDL tonight/tomorrow. SDL2 only, or both SDL1/2?
  2. We can dynamically generate the rc populating with CMake variables - if desired.

@GitMensch I'll take a look at your questions and get back to you.

@jwinarske jwinarske changed the title CMake (msbuild) implementation for win32 and win32a [CMake] build flavors: win32, win32a, and sdl2 Sep 26, 2017
@jwinarske

jwinarske commented Sep 26, 2017 •

Copy link
Copy Markdown
Contributor Author

I refactored for sdl2, added an example, and a README.md (cmake\README.md). Take a peek.

minor typos
@GitMensch

Copy link
Copy Markdown
Collaborator

Looks nice. Some questions:

  • What do you need the Windows SDK for when building with Cygwin?
  • Can you please add SDL_ttf which is needed for SDL2 WIDE? (BTW: this optional external dependency handling is nice)
  • I understand the readme in a way that every possible port (Win32, Win32a, SDL2) is build by default. Is this correct? If not: can you add some information to the readme how to choose which ones to build?
  • Isn't x86 an optional [arch], too?

@jwinarske

Copy link
Copy Markdown
Contributor Author

@GitMensch

  • This for a scenario where you use Cygwin bits from not a Cygwin shell.
  • Just about done with it. It pulls in and builds zlib, freetype2, sdl2_ttf.
  • I have a build flag to disable building SDL2. Do we want to have build parameters for each project type?
  • x86 is the default, unless you use -G"Visual Studio 15 Win64".

@ghost

ghost commented Sep 27, 2017

Copy link
Copy Markdown

@GitMensch Forgot to elaborate on the Cygwin question, if you specify the "Unix Makefile" Generator it won't look for "Windows Kit" paths.

@GitMensch

Copy link
Copy Markdown
Collaborator

@INRIX-joel-winarske Your changes look very promising.

Two questions:

  • What do you think about changing "DLL" build to "SHARED" and include the option shared/static to the SDL2 linux targets?
  • Can you integrate x11 linux/cygwin support, please? This would lead to this PR cover all parts where people did cmake changes to the PDCurses repositories. Bill-Gray/PDCurses@f419e6d is not 100% compatible to what you have done already but is likely a very good point to start from. I've compared the cmake parts (ana area I obviously don't know much of) to the Makefile.in and configure.ac (an area where I'm quite comfortable with) and the cmake parts look complete.

@ghost

ghost commented Sep 29, 2017

Copy link
Copy Markdown

@GitMensch Hi Simon.

  • Funny I used the same flag name prior, then changed it. I'll add this flag. In the case of WIN32 it will set the compiler definition "DLL". If set it will only affect the libpdcurses library type, as the dependencies already build both (less freetype). Linux build output:
    .
    ├── cmake
    │   ├── freetype
    │   │   ├── freetype-config.cmake
    │   │   └── freetype-config-debug.cmake
    │   └── SDL2
    │   ├── SDL2Config.cmake
    │   ├── SDL2ConfigVersion.cmake
    │   ├── SDL2Targets.cmake
    │   └── SDL2Targets-debug.cmake
    ├── libfreetyped.a
    ├── libSDL2-2.0d.so -> libSDL2-2.0d.so.0
    ├── libSDL2-2.0d.so.0 -> libSDL2-2.0d.so.0.6.0
    ├── libSDL2-2.0d.so.0.6.0
    ├── libSDL2d.a
    ├── libSDL2maind.a
    ├── libSDL2.so -> libSDL2-2.0.so
    ├── libSDL2_ttfd.so
    ├── libSDL2_ttf-staticd.a
    ├── libz.a
    ├── libz.so -> libz.so.1
    ├── libz.so.1 -> libz.so.1.2.11
    ├── libz.so.1.2.11
    ├── pkgconfig
    │   └── sdl2.pc
    └── sdl2
    └── libpdcursesstaticd.a

Dynamic section at offset 0x160d38 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libsndio.so.6.1]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libSDL2-2.0d.so.0]

Dynamic section at offset 0xe8d48 contains 26 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libSDL2-2.0d.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libSDL2_ttfd.so]

  • I'll add X11 support. I'm out all next week on Holiday, so worst case two weeks.

@Bill-Gray @GitMensch
To clarify this is my proposed CMake Support Matrix. What's missing?

Target Win32 Win32a SDL2 X11
Windows Native X X X
Cygwin X X X X
Linux X X
Mac X X

@GitMensch

Copy link
Copy Markdown
Collaborator

@INRIX-joel-winarske I'm out next week, too :-)

It is unclear for me what "Windows Native" means to you, but I guess you meant Visual Studio (that is a complete different issue, PGI, Borland and others [and MinGW, too] build "Windows native" applications.

There are some compilations that are not in your Matrix but we have the Makefiles for these already and for the CMake parts this matrix is completely fine.

I'm looking forward seeing the last piece added and integrating it (or having it integrated, if @Bill-Gray wants to do it) to PDCurses.

One last note: I think it is strange to include a build bat exclusive for vs2015, especially as CMake's intension seems to be to not need these.

@ghost

ghost commented Sep 29, 2017

Copy link
Copy Markdown

@GitMensch Nice!

"Windows Native" meaning compiled and linked with a MSFT toolchain. Perhaps instead of "Target" the matrix would indicate the CMake Generator "target". The variations quickly grow.

The vs2015_build.cmd file is a test case that provides a valid command line build example. I can remove it.

@GitMensch

Copy link
Copy Markdown
Collaborator

@INRIX-joel-winarske I think cmake/README.md has enough for "what is the correct use" (if you're not 100% sure about it it would be good to add the missing bits there and remove the vs2015_build.cmd afterwards. Read you in about 10 days :-)

@GitMensch GitMensch changed the title [CMake] build flavors: win32, win32a, and sdl2 [CMake] build flavors: win32, win32a, sdl2 (multi-platform), x11 (multi-platform) Oct 8, 2017
@GitMensch

Copy link
Copy Markdown
Collaborator

@INRIX-joel-winarske I'm really looking forward for the X11 addition and final merge of your changes!

@GitMensch

Copy link
Copy Markdown
Collaborator

@INRIX-joel-winarske / @jwinarske I'd like to merge this soon - Are there any news from you?

@jwinarske

Copy link
Copy Markdown
Contributor Author

Closing and re-opening a new PR.

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