ldthomas/apg-7.0

A handy cmake script

Closed this issue · 11 comments

I wrote a cmake script based on the Installation.md, hoping to help people save some time, I can also mark it.

environment:
windows 10 64bit
msys2 (mingw-w64-x86_64-gcc)

2021-05-23.

CMakeLists.txt

Thank you. I'm not familiar with CMake but I will take a serious look at it when I come back to this project.

Hi hhaoao,
I have CMakeLists.txt files created for apg and all of the examples. I have scripts that build them all for release applications and for debug Eclipse projects. It works great on Linux Ubuntu 20.04. Really great. All of those Eclipse projects were very tedious to build manually. cmake builds them all in a second. But here's the problem. I can't get cmake to work with Windows. I have git for Windows (MinGW) and Eclipse installed. Eclipse can build the applications with the projects that I created manually. But cmake fails with both release and with debug and -G "Eclipse CDT4 - Unix Makefiles". I've tried many things but cmake always fails.

Can you tell me how you get this to work on Windows?

With this example in mind, I would like to share my experience of success.

cd F:\temp\apg-7.0
mkdir debug
cmake -S ./ -B ./debug/ -DCMAKE_ECLIPSE_VERSION=4.19 -DCMAKE_BUILD_TYPE:STRING="Debug" -G "Eclipse CDT4 - Unix Makefiles"

The next step is to import the CMake project in the Eclipse for C/C++ IDE:

  • Switch Workspace "apg-7.0".

  • Uncheck the menu "Project->Build Automatically".

  • Import... -> Existing Projects into Workspace.

  • Select the directory "F:\temp\apg-7.0" (cmake only supports generating single configuration, I don’t know how to configure eclipse multiple configuration, here I only select the "debug" directory)

  • Click "Build All" or a particular target in the "Make Target" tab in Eclipse to build the project.

Note:

  • CMAKE_ECLIPSE_VERSION Can be found in help -> About Eclipse IDE -> (version)

  • CMAKE_ECLIPSE_MAKE_ARGUMENTS and more information can search Eclipse in cmake.

  • Release version just CMAKE_BUILD_TYPE:STRING="Release".

  • remove Cmake Warning, Create "debug dir" outside the "apg-7.0" project and use it.

CMake Warning in CMakeLists.txt:
  The build directory is a subdirectory of the source directory.

  This is not supported well by Eclipse.  It is strongly recommended to use a
  build directory which is a sibling of the source directory.

Thank you for your response. Yes, I have looked at the example you linked to and it works great on Linux Ubuntu. No problems. However, on Windows 10 I have installed cmake version 3.20.3. But when I run your example above I get this:

..\apg-7.0>cmake -S ./ -B ./debug/ -DCMAKE_ECLIPSE_VERSION=4.16 -DCMAKE_BUILD_TYPE="Debug" -G "Eclipse CDT4 - Unix Makefiles"
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "../apg-7.0/debug/CMakeFiles/CMakeOutput.log".

cmake --help tells me that "Eclipse CDT4 - Unix Makefiles" is a valid option, but it doesn't work.
I've searched the Internet for hours and have not been able to find a solution to this. Any ideas?

I think you should check your system PATH and MINGW toolchain.

cmake --version
make --version
gcc --version

If all is well and cmake is still not working properly, download Msys2. It only needs mingw64-x86_64-toolchain and cmake to work properly.

Well, I'm close but not quite there. You were right about the PATH. I corrected that and using git bash:

$ cmake -S ./ -B ./Debug/ -DCMAKE_ECLIPSE_VERSION=4.16 -DCMAKE_BUILD_TYPE=STRING:"Debug" -G "Eclipse CDT4 - Unix Makefiles"

runs without errors. But after importing the generated project into Eclipse the build fails:

C:/MinGW/bin/gcc.exe -DAPG_AST -std=gnu11 -MD -MT CMakeFiles/library.dir/library/ast.c.obj -MF CMakeFiles/library.dir/library/ast.c.obj.d -o CMakeFiles/library.dir/library/ast.c.obj -c C:/Users/orman/Projects/apg-cmake/apg-7.0/library/ast.c
CMakeFiles/library.dir/build.make:75: recipe for target 'CMakeFiles/library.dir/library/ast.c.obj' failed

However,

cmake --build ./debug

works OK. It builds apg.exe and ex-basic.exe and they both work as expected.

So I installed msys2 and tried it again. Same result except that 1) when I import the generated project I get the message:

"Some project cannot be imported because they already exist or are corrupt"

The project is created anyway, but 2) when building it there are build errors like this:

/usr/bin/cc.exe -DAPG_AST -g -std=gnu11 -MD -MT CMakeFiles/api.dir/api/input.c.o -MF CMakeFiles/api.dir/api/input.c.o.d -o CMakeFiles/api.dir/api/input.c.o -c /home/orman/Projects/apg-7.0/api/input.c
C:/msys64/usr/lib/gcc/x86_64-pc-msys/10.2.0/cc1.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

However, as before:

cmake --build ./debug

builds working executables.

Internet searching finds no reasonable explanation for this. In fact, nothing even close. Any ideas on this? I take it this is working OK for you on Windows?

Oh, I think I know your problem. You made a typo and the generated configuration file Eclipse cannot read properly.But I can't skip this error and continue creating the project.

;error input
CMAKE_BUILD_TYPE=STRING:"Debug"
; The correct input
CMAKE_BUILD_TYPE:STRING="Debug"

image

I wish it were that simple. The "Creation" problem only happens with msys2 but not with git for windows. I corrected the typo as you have pointed out and get the same problem. I actually have used just

-DCMAKE_BUILD_TYPE=Debug

and that works fine. The real problem is that after the project generation and importing it into Eclipse the build fails with the error messages I've listed above. The build fails with both msys2 and git for windows.

If I create the project manually in Eclipse it builds fine. The imported projects won't build with either msys2 or git for windows. So I'm stuck here. I will probably just go ahead and push up the cmake files (I've created a cmake file for each project. Necessary because they all in general use a different set of defines) and note that it works ok for me on Ubuntu and it is up to the user to use the cmake files to build for their favorite OS and IDE.

Oh, post my successful configuration file and log. I hope people who encounter the same problem can have a way to reproduce this phenomenon.

  1. Create a new directory. /f/shortcut/temporary-project/

  2. Unzip to the above directory. result: /f/shortcut/temporary-project/newdebug,
    newdebug.zip.
    SHA256: E0B848F00F2C8F781F4BC401BFD497B4F904AF3836F4F8C98C6E43CCEE62D9CB

  3. Copy apg-7.0 project to the specified directory. result: /f/shortcut/temporary-project/apg-7.0.

Eclipse's work.

  1. Enter the workspace /f/shortcut/temporary-project/newdebug.
  2. Uncheck the menu "Project->Build Automatically".
  3. Import... -> Existing Projects into Workspace.
  4. Select the root directory "/f/shortcut/temporary-project/newdebug/debug".
  5. Click "Project" -> "Build All" or a particular target in the "Make Target" tab in Eclipse to build the project.(You may need to clean first, "Project -> clean")

Sorry but newdebug.7z.zip seems to be corrupted. Attempts to unzip it lead to corrupt file or not a zip file error messages. But even if it contains working project files, the real question is how did you get them? My problem here is that I can't seem to get cmake to generate correct Eclipse project files on Windows - msys2 or git bash either one.

My mistake, I re-uploaded the compressed package, I am sure that only you will have the problem, others should not have this phenomenon, I once suspected that your cache file was not cleared, but it doesn't feel like it.