OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: david.oakford on January 19, 2024, 08:53:35 pm

Title: CMake
Post by: david.oakford on January 19, 2024, 08:53:35 pm
How do I indicate to CMake that an executable is a PM (WINDOWAPI) program.
Is there a keyword for the add_executable(targetName [WIN32] [?WINDOWAPI | PM?]
I took one of Martin's Sample programs, vectfont, created a CMakeLists.txt file. 
It configured successfully and the make worked, producing an executable, but it doesn't run.

Title: Re: CMake
Post by: Martin Iturbide on January 19, 2024, 09:21:52 pm
Hello David

Welcome to the forum !!! After all those years meeting at Warpstock, I'm glad you are here on the OS2World forum.

Maybe it can be interesting (if you want) to post the sample and CMakeLists.txt file here as an attachment to the forum (as a zip file).

My thoughts are:
1) If you run the executable (vectfont.exe) on a OS/2 command line, what errors does it gives you?
2) For what I have learn the "WINDOWAPI" app type is set on the .DEF file
          NAME           VECTFONT  WINDOWAPI
But maybe here someone with more experience can reply that.

Regards
Title: Re: CMake
Post by: Dave Yeo on January 19, 2024, 10:14:43 pm
From @unixroot\usr\share\cmake\Modules\Platform\OS2.cmake
...
Code: [Select]
# With the TARGET_SHORT you can create a shorter name for the dll
#
# The 2 settings with OS2_DEF_EXE_ are for executables only.
# Usually the Stack value is not needed, so omit it please.
#
# if(OS2)
#   set_target_properties(<TARGET> PROPERTIES
#    OS2_DEF_VENDOR "whoever you are"
#    OS2_DEF_PATCH "${VERSION_PATCH}"
#    OS2_DEF_VERSION "${VERSION}"
#    TARGET_SHORT shortn
#    OS2_DEF_EXEType "WINDOWAPI"
#    OS2_DEF_EXEStack "STACKSIZE 0x8000")
# endif()
#
...
includes stuff for bldlevel.
Edit: Typo
Title: Re: CMake
Post by: david.oakford on January 20, 2024, 03:32:07 am
David,
Thanks. I will give it a try in the morning.
David
Title: Re: CMake
Post by: david.oakford on January 20, 2024, 05:08:32 am
Thanks David Yeo.

This is what finally worked. 
That OS2.cmake file had  the clues.
In addition to the stuff that added the necessary info to the .def file,
some more is needed to get the rc file compiled and included.

This is the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.15)
project(vectfont)
add_executable(vectfont
    vectfont.c
    vf00.c
    vf01.c
    vf02.c
    vf03.c
    vf04.c
    vf05.c
    vf06.c
    vf07.c
    vf08.c
    vf09.c
    vf10.c
    vf11.c
    vf12.c
    vf13.c
    vf14.c
    vf15.c
    vectfont.rc
)
if(OS2)
  enable_language(RC)
  set_source_files_properties(vectfont.rc PROPERTIES LANGUAGE RC)
  set(project_SOURCES ${project_SOURCES}
   vectfont.rc
  )
  set_target_properties(vectfont PROPERTIES
   OS2_DEF_VENDOR "oakford"
   OS2_DEF_PATCH "${VERSION_PATCH}"
   OS2_DEF_VERSION "${VERSION}"
   OS2_DEF_EXEType "WINDOWAPI"
  )
endif()


Then run this in the directory with the source code and CMakeLists.txt file:
cmake  -B build
cmake --build build
It will create the exe in the build  subdirectory.

This really helps.

David
Title: Re: CMake
Post by: david.oakford on January 20, 2024, 05:13:04 am
Attached CMakeLists.txt
Title: Re: CMake
Post by: Dave Yeo on January 20, 2024, 06:14:28 am
Glad it worked for you, plus a different thing for Martin to play with.
Title: Re: CMake
Post by: david.oakford on January 20, 2024, 04:11:13 pm
Any idea who does the port of cmake and where the source code is?
I am curious why those things were implemented that way instead for doing the more natural way, with the equivalent of WIN32 (WINDOWAPI or OS2PM) as a parameter to add_executable, and having RC available on among the LANGUAGES on the project.
Title: Re: CMake
Post by: Dave Yeo on January 20, 2024, 04:49:33 pm
Bitwise did the port, https://github.com/bitwiseworks/cmake-os2 (https://github.com/bitwiseworks/cmake-os2)
Title: Re: CMake
Post by: david.oakford on January 20, 2024, 07:24:19 pm
Thanks. 
And do you know if there is a port of Ninja for OS/2?
Title: Re: CMake
Post by: Dave Yeo on January 20, 2024, 07:31:42 pm
Part of Qt, 5&6, I think the webengine. Paul might have the best port, here's one.
May be incomplete
Title: Re: CMake
Post by: david.oakford on March 12, 2024, 06:32:10 pm
Has anyone built a qt5 application using cmake?  This is what I tried. I builds but doesn't run. Any suggestions?

qmain.cpp:

#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
int main(int argc, char* argv[]) {
  QApplication a(argc, argv);
  QLabel l("Hello World");
  l.show();
  return a.exec();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(qmain)
add_executable(qmain qmain.cpp)
target_include_directories(qmain PRIVATE "C:\\usr\\include\\qt5")
target_link_libraries(qmain PRIVATE Qt5Widgets
                            PRIVATE Qt5Core
)
if(OS2)
  set_target_properties(qmain PROPERTIES
    OS2_DEF_VENDOR "oakford"
    OS2_DEF_PATCH "${VERSION_PATCH}"
    OS2_DEF_VERSION "${VERSION}"
    OS2_DEF_EXEType "WINDOWAPI"
  )
endif()
Title: Re: CMake
Post by: Jochen Schäfer on March 13, 2024, 09:43:31 am
Most likely you are missing libcx:
Code: [Select]
set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -lcx")
If you want to test and get some output on the shell, set the Exe type to WINDOWCOMPAT.
For the app icon to show in PM, you need to set the exe type to WINDOWAPI. The console output then isn't shown, but can be captured like this:
Code: [Select]
app -someparameter | less
My Qt5 ports are here:
https://github.com/josch1710/FeatherNotes (https://github.com/josch1710/FeatherNotes)
https://github.com/josch1710/FeatherPad (https://github.com/josch1710/FeatherPad)
Title: Re: CMake
Post by: david.oakford on March 14, 2024, 05:01:03 pm
Jochen,
Thanks so much.  Worked like a charm.  I'll take a look later at your ports.
David