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

pm5example1 failure #13

Open
arnholm opened this issue Jul 28, 2021 · 5 comments · Fixed by #14
Open

pm5example1 failure #13

arnholm opened this issue Jul 28, 2021 · 5 comments · Fixed by #14

Comments

@arnholm
Copy link
Contributor

arnholm commented Jul 28, 2021

I have written a Code::Blocks plugin to generate a premake5 script from a Code::Blocks workspace. There is an example with generated premake5 lua script at https://github.com/arnholm/pm5example1 . This example contains a static library, a shared library and a console application, all extremely small and simple.

It is possible to successfully build this example on linux or windows using premake5 generating makefiles or Visual Studion files:

premake5 --file=pm5example1_premake5.lua gmake2
premake5 --file=pm5example1_premake5.lua vs2019

Now I installed your premake-cmake under Kubuntu 20.04 to see if it would be possible to build the same via CMake, so I did

premake5 --file=pm5example1_premake5.lua cmake
Building configurations...
Running action 'cmake'...
Generated build/cmake/CMakeLists.txt...
Generated build/cmake/long/path/staticlib1/staticlib1.cmake...
Generated build/cmake/dynlib1/dynlib1.cmake...
Generated build/cmake/testconsole/testconsole.cmake...

and then

cd build/cmake
cmake .
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /ssd1/codeblocks/gtk2-unicode-3.0/plugin_dev/pm5example1/build/cmake

So far so good, but build fails

make
Scanning dependencies of target staticlib1
[ 16%] Building CXX object CMakeFiles/staticlib1.dir/ssd1/codeblocks/gtk2-unicode-3.0/plugin_dev/pm5example1/long/path/staticlib1/staticlib1_class.cpp.o
[ 33%] Linking CXX executable long/path/staticlib1/bin/debug/staticlib1
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/staticlib1.dir/build.make:84: long/path/staticlib1/bin/debug/staticlib1] Error 1
make[1]: *** [CMakeFiles/Makefile2:108: CMakeFiles/staticlib1.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
@Enhex
Copy link
Owner

Enhex commented Jul 28, 2021

undefined reference to `main' - seems like you're trying to build an executable instead of a static lib?

@arnholm
Copy link
Contributor Author

arnholm commented Jul 28, 2021

It is premake-cmake that causes this. staticlib1 is a static lib without main. It works fine when building makefiles with premake5, but via cmake it fails. That's why I reported it here. The code and premake file is at https://github.com/arnholm/pm5example1

@Enhex
Copy link
Owner

Enhex commented Jul 28, 2021

i suggest trying to put some prints in the if-else's at
https://github.com/Enhex/premake-cmake/blob/master/cmake_project.lua#L53
and seeing if it goes into the staticlib or executable path.

note that I don't use this project anymore and working on other stuff so i dont maintain it right now.

@arnholm
Copy link
Contributor Author

arnholm commented Jul 29, 2021

Thanks for the tip. The reason for the failure is that prj.kind is nil in this case, because 'kind' is defined on premake config level and not on project level https://github.com/arnholm/pm5example1/blob/master/pm5example1_premake5.lua#L33

That looks like a bug in cmake-premake. A work-around in cmake_project.lua, i.e. test for prj.kind == nil and let the configs define it

function m.generate(prj)
    p.utf8()

    if prj.kind == nil then
        for cfg in project.eachconfig(prj) do
            prj.kind = cfg.kind
        end
    end

    if prj.kind == 'Utility' then
        return
    end
    ...

This fixes the immediate problem, but another problem appears when targetname is defined on config level in premake5. Unlike 'kind', 'targetname' is different for the different configs and premake-cmake doesn't handle that correctly. If I comment out 'targetname' in the premake5 file, it links properly.

So premake-cmake is almost working, but not quite.

EDIT: I should add that the file linked to above does not contain 'targetname' on config level, so it works with the fix mentioned. I observed the 'targetname' problem with a local modified copy

@Enhex Enhex linked a pull request Jul 29, 2021 that will close this issue
@Enhex
Copy link
Owner

Enhex commented Jul 29, 2021

I merged your PR, so closing this issue.
If you'll need to use targetname in a similar manner make a PR and I'll merge it.

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 a pull request may close this issue.

2 participants