SWI-Prolog / roadmap

Discuss future development
20 stars 3 forks source link

Convert projects and subprojects to CMake #48

Closed TeamSPoon closed 5 years ago

TeamSPoon commented 8 years ago

"CMake is cross-platform free and open-source software for managing the build process of software using a compiler-independent method. It is designed to support directory hierarchies and applications that depend on multiple libraries."

From CMake one generates makefiles for various IDEs

wouterbeek commented 8 years ago

@logicmoo What are the benefits for SWI over the current situation? Would this improve external IDE support, internal (PCE) IDE support or the SWISH IDE?

o314 commented 7 years ago

IMHO, Cmake files are a lot easier to read and maintain.

This link could help :

o314 commented 5 years ago

CMake contains at least two others interesting tools:

CPack can generate package in the following formats

More there ...

XVilka commented 5 years ago

While CMake is mature now, it is still have quite a lot of legacy code, dependency on make, etc. In my opinion it makes sense to use modern tools like ninja for low-level building and higher level ninja files generator, something like Meson

JanWielemaker commented 5 years ago

I started a branch cmake. It currently allows you to build the core system. Do do so (tested on Linux),

There is no installation, no testing and all the complicated tests have not been migrated. So far the experience is quite positive. The CMake spec looks pretty clean and deals with a lot of stuff that looks pretty ugly in the current build environment. This looks like a way out to support people with a non-linux development environment and clean up the build infrastructure.

Jump in if you want to contribute in any way. Work to do

JanWielemaker commented 5 years ago

@XVilka I think I prefer a mature solution. Note that CMake can also use Ninja as backend. The project is too small for make/ninja performance to matter though. CMake gives way better configure performance compared to autotools. That brings the build time down considerably.

kamahen commented 5 years ago

One problem I've run into with cmake is that the latest versions aren't available for install using the usual tools (e.g., apt-get). Of course, you could add it to the SWI-Prolog PPA.

XVilka commented 5 years ago

@JanWielemaker everything is better than autotools.

JanWielemaker commented 5 years ago

? Debian sid provides 3.12 and my dev machine (Ubuntu 18.04) provides 3.10. Both is recent enough.

JanWielemaker commented 5 years ago

Pushed a lot of stuff, so now we have compilation, testing, installation and (a single) package. There is now also a toplevel CMakeList.txt, making the processing a little easier. To build, do e.g.

mkdir build
cd build
cmake ..
make -j 8

Most needed now is some advice by an experienced CMake user to check this is on the right track.

JanWielemaker commented 5 years ago

Got a lot of good advice from Keri. Current cmake branch builds natively on Ubuntu 18.04 and can do cross compilation from Linux to Win64 using MinGW, given that the dependencies are compiled as described in README.mingw. See CMAKE.md in the top dir.

pmoura commented 5 years ago

On macOS 10.13.6 I get:

[  6%] Linking C shared module libedit4pl.so
Undefined symbols for architecture x86_64:
  "_PL_call_predicate", referenced from:
      _prolog_function in libedit4pl.c.o
...
JanWielemaker commented 5 years ago

That is an issue between ELF (most Unix-like systems) and (X)COFF (Windows, MacOS and some more) binaries. Thanks for reporting. Will solve that (but not today).

JanWielemaker commented 5 years ago

Actually looks very easy with cmake ... Please try again.

pmoura commented 5 years ago

We now get as far as:

[ 24%] Building C object src/CMakeFiles/libswipl.dir/pl-bag.c.o
In file included from /Users/pmoura/Documents/Prolog/swipl-devel/src/pl-atom.c:37:
/Users/pmoura/Documents/Prolog/swipl-devel/src/pl-incl.h:307:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
JanWielemaker commented 5 years ago

Thanks. Guess it is easier for me to try and get this to work on my ancient Mac ... Seems cmake has fairly good support for packages in non-standard locations, but I don't use all of that yet.

pmoura commented 5 years ago

With the commit that just landed:

[ 51%] Building C object src/CMakeFiles/libswipl.dir/pl-thread.c.o
/Users/pmoura/Documents/Prolog/swipl-devel/src/pl-thread.c:904:3: warning: 'sem_init' is deprecated [-Wdeprecated-declarations]
  sem_init(sem_canceled_ptr, USYNC_THREAD, 0);
  ^
/usr/include/sys/semaphore.h:55:42: note: 'sem_init' has been explicitly marked deprecated here
int sem_init(sem_t *, int, unsigned int) __deprecated;
                                         ^
/usr/include/sys/cdefs.h:176:37: note: expanded from macro '__deprecated'
#define __deprecated    __attribute__((deprecated))
                                       ^
/Users/pmoura/Documents/Prolog/swipl-devel/src/pl-thread.c:1008:5: warning: 'sem_destroy' is deprecated [-Wdeprecated-declarations]
    sem_destroy(sem_canceled_ptr);
    ^
/usr/include/sys/semaphore.h:53:26: note: 'sem_destroy' has been explicitly marked deprecated here
int sem_destroy(sem_t *) __deprecated;
                         ^
/usr/include/sys/cdefs.h:176:37: note: expanded from macro '__deprecated'
#define __deprecated    __attribute__((deprecated))
                                       ^
/Users/pmoura/Documents/Prolog/swipl-devel/src/pl-thread.c:1638:43: error: too many arguments to function call, expected 1, have 2
  if ( pthread_setname_np(pthread_self(), name) == 0 )
       ~~~~~~~~~~~~~~~~~~                 ^~~~
/usr/include/pthread.h:499:1: note: 'pthread_setname_np' declared here
__API_AVAILABLE(macos(10.6), ios(3.2))
^
/usr/include/Availability.h:415:126: note: expanded from macro '__API_AVAILABLE'
    #define __API_AVAILABLE(...) __API_AVAILABLE_GET_MACRO(__VA_ARGS__,__API_AVAILABLE5, __API_AVAILABLE4, __API_AVAILABLE3, __API_AVAILA...
                                                                                                                             ^
[ 52%] Building C object src/CMakeFiles/libswipl.dir/pl-xterm.c.o
2 warnings and 1 error generated.
make[2]: *** [src/CMakeFiles/libswipl.dir/pl-thread.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
2 warnings generated.
make[1]: *** [src/CMakeFiles/libswipl.dir/all] Error 2
make: *** [all] Error 2
pmoura commented 5 years ago

Now at:

SWI-Prolog boot files loaded
Boot compilation has created ./swipl.prc
[ 99%] Built target libedit4pl
[100%] Built target prolog_products
JanWielemaker commented 5 years ago

Progress! Pushed some more patches. Now the entire build and install is clean on (my) MacOS. make check passes as well. This is good news. The amount of MacOS specific stuff in the configuration process I had to write myself is way less than what it was before.

JanWielemaker commented 5 years ago

All stuff is now pushed to master. I will delete the cmake branches shortly. Basic build seems to work while the old stuff still works as well. I'll start using cmake for development from now on.

pmoura commented 5 years ago

On macOS High Sierra (10.13.6), after updating to the latest git version, I get:

$ make distclean && ./build && swipl -g "jpl_config_dylib" -t halt
...
ar: creating archive ../lib/x86_64-darwin17.7.0/libswipl.a
ar: pl-codetable.o: No such file or directory
clang: error: no such file or directory: 'pl-codetable.o'
make[1]: *** [../lib/x86_64-darwin17.7.0/libswipl.dylib] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [../lib/x86_64-darwin17.7.0/libswipl.a] Error 1
make: *** [lite] Error 2

I assume this is a temporary issue that would be fixed by a forthcoming update to build.templ? I get a different error if trying instead:

$ mkdir b && cd b && cmake .. && make && swipl -g "jpl_config_dylib" -t halt
...
-- Found Libedit: /opt/local/lib/libedit.dylib  
-- Looking for sys/ioctl.h
CMake Warning (dev) at /opt/local/share/cmake-3.12/Modules/CheckIncludeFile.cmake:70 (message):
  Policy CMP0075 is not set: Include file check macros honor
  CMAKE_REQUIRED_LIBRARIES.  Run "cmake --help-policy CMP0075" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  CMAKE_REQUIRED_LIBRARIES is set to:

    /opt/local/lib/libedit.dylib

  For compatibility with CMake 3.11 and below this check is ignoring it.
Call Stack (most recent call first):
  cmake/Utils.cmake:30 (check_include_file)
  packages/libedit/CMakeLists.txt:10 (AC_CHECK_HEADERS)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Looking for sys/ioctl.h - found
-- Looking for el_cursor
-- Looking for el_cursor - found
-- Looking for el_wset
-- Looking for el_wset - found
-- Found Readline: /opt/local/include  
-- Looking for readline/readline.h
CMake Warning (dev) at /opt/local/share/cmake-3.12/Modules/CheckIncludeFile.cmake:70 (message):
  Policy CMP0075 is not set: Include file check macros honor
  CMAKE_REQUIRED_LIBRARIES.  Run "cmake --help-policy CMP0075" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  CMAKE_REQUIRED_LIBRARIES is set to:

    /opt/local/lib/libreadline.dylib

  For compatibility with CMake 3.11 and below this check is ignoring it.
Call Stack (most recent call first):
  cmake/Utils.cmake:30 (check_include_file)
  packages/readline/CMakeLists.txt:11 (AC_CHECK_HEADERS)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Looking for readline/readline.h - found
-- Looking for readline/history.h
-- Looking for readline/history.h - found
-- Looking for rl_completion_matches
-- Looking for rl_completion_matches - found
-- Looking for rl_insert_close
-- Looking for rl_insert_close - found
-- Looking for rl_set_prompt
-- Looking for rl_set_prompt - found
-- Looking for rl_clear_pending_input
-- Looking for rl_clear_pending_input - found
-- Looking for rl_cleanup_after_signal
-- Looking for rl_cleanup_after_signal - found
-- Looking for rl_filename_completion_function
-- Looking for rl_filename_completion_function - found
-- Looking for rl_readline_state
-- Looking for rl_readline_state - not found
-- Looking for rl_done
-- Looking for rl_done - not found
-- Looking for rl_event_hook
-- Looking for rl_event_hook - not found
-- Configuring done
CMake Error at src/CMakeLists.txt:273 (add_library):
  Cannot find source file:

    pl-codetable.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

CMake Error at src/CMakeLists.txt:273 (add_library):
  No SOURCES given to target: libswipl

-- Build files have been written to: /Users/pmoura/Documents/Prolog/swipl-devel/b
JanWielemaker commented 5 years ago

pl-codetable.c used to be a generated file. It is now a fixed file that includes the generated pl-codetable.ic, making cmake build a little easier. The make distclean however deletes pl-codetable.c ...

So, after the make distclean you need a git reset --hard. That also holds for a couple of similar cases in packages. Run git status in the toplevel to find which packages are dirty.

That is a bit awkward transition. I don't see a clean solution for that.

pmoura commented 5 years ago

Maybe having the recipe you posted earlier today in the mailing list in build.templ?

JanWielemaker commented 5 years ago

I'd assume that most people do not update their build copy often. Note this is not a problem for a new clone, just a one-time problem when following development with git pull and make distclean. The makefile generated on the next build should no longer remove these source files.

JanWielemaker commented 5 years ago

Closing this topic as cmake is now fully supported as of 7.7.20