Skip to content

Commit

Permalink
BUILD: Added CMake options SWIPL_CC and SWIPL_CXX
Browse files Browse the repository at this point in the history
This selects the defaults for the `c_cc` and `c_cxx` flags.   Distributions
should normally set these to the common C and C++ compiler of the platform.
Local builds typically leave them default, setting these flags to the
same as used to build SWI-Prolog.
  • Loading branch information
JanWielemaker committed Jul 24, 2024
1 parent 2a8a88c commit 41d442a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMAKE.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ and libraries that are built.
| `-DSTATIC_EXTENSIONS=ON` | Include packages into the main system |
| `-DSWIPL_INSTALL_IN_LIB=ON` | Install libswipl.so in `<prefix>/lib` |
| `-DSWIPL_INSTALL_IN_SHARE=ON` | Install docs in `<prefix>/share` |
| `-DSWIPL_CC=<string>` | Default for `c_cc` flag |
| `-DSWIPL_CXX=<string>` | Default for `c_cxx` flag |
| `-DSWIPL_PACKAGES=OFF` | Only build the core system |
| `-DSWIPL_PACKAGES_BASIC=OFF` | Drop all basic packages |
| `-DSWIPL_PACKAGES_ODBC=OFF` | Drop ODBC and CQL packages |
Expand Down
17 changes: 11 additions & 6 deletions cmake/Params.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Populate parms.h

if(APPLE)
set(C_CC "cc")
set(C_CXX "c++")
else()
set(C_CC ${CMAKE_C_COMPILER})
set(C_CXX ${CMAKE_CXX_COMPILER})
set(SWIPL_CC "from-cmake" CACHE STRING
"Value for c_cc flag. When from-cmake, we use CMAKE_C_COMPILER")
set(SWIPL_CXX "from-cmake" CACHE STRING
"Value for c_cxx flag. When from-cmake, we use CMAKE_CXX_COMPILER")

if(SWIPL_CC STREQUAL "from-cmake")
set(SWIPL_CC ${CMAKE_C_COMPILER})
endif()
if(SWIPL_CXX STREQUAL "from-cmake")
set(SWIPL_CXX ${CMAKE_CXX_COMPILER})
endif()

if(NOT PLHOME)
set(PLHOME ${CMAKE_INSTALL_PREFIX}/${SWIPL_INSTALL_PREFIX})
endif()
Expand Down
28 changes: 27 additions & 1 deletion scripts/make-distribution
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ build_win32()
mkdir build.win32
( cd build.win32
cmake -DCMAKE_BUILD_TYPE=Release \
-DSWIPL_CC=gcc.exe -DSWIPL_CXX=g++.exe \
-DCMAKE_TOOLCHAIN_FILE=../cmake/cross/linux_win32.cmake \
-DJAVA_COMPATIBILITY=ON \
-G Ninja ..
Expand All @@ -56,6 +57,7 @@ build_win64()
mkdir build.win64
( cd build.win64
cmake -DCMAKE_BUILD_TYPE=Release \
-DSWIPL_CC=gcc.exe -DSWIPL_CXX=g++.exe \
-DJAVA_HOME="$HOME/.wine/drive_c/Program Files/Java/jdk-13.0.2" \
-DCMAKE_TOOLCHAIN_FILE=../cmake/cross/linux_win64.cmake \
-DJAVA_COMPATIBILITY=ON \
Expand All @@ -74,6 +76,7 @@ build_macosx()
export PATH=$HOME/deps/bin:$QT_BIN:$PATH
MACOSX_DEPLOYMENT_TARGET=10.14 \
cmake -DCMAKE_BUILD_TYPE=Release \
-DSWIPL_CC=cc -DSWIPL_CXX=c++ \
-DUSE_GMP=OFF \
-DMACOSX_DEPENDENCIES_FROM=$HOME/deps \
-DBUILD_MACOS_BUNDLE=ON \
Expand All @@ -93,6 +96,7 @@ build_macos_universal_binary()
CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" \
MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET \
cmake -DCMAKE_BUILD_TYPE=Release \
-DSWIPL_CC=cc -DSWIPL_CXX=c++ \
-DMACOSX_DEPENDENCIES_FROM=$HOME/deps \
-DMACOS_UNIVERSAL_BINARY=ON \
-DBUILD_MACOS_BUNDLE=ON \
Expand All @@ -114,6 +118,7 @@ build_macosx_gcc()
export CC=gcc-mp-13
MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET \
cmake -DCMAKE_BUILD_TYPE=PGO \
-DSWIPL_CC=cc -DSWIPL_CXX=c++ \
-DMACOSX_DEPENDENCIES_FROM=$HOME/deps \
-DBUILD_MACOS_BUNDLE=ON \
-DJAVA_COMPATIBILITY=ON \
Expand Down Expand Up @@ -152,6 +157,25 @@ is_clean_release()
fi
}

list_file()
{ if [ -f "$1" ]; then
ls -l "$1"
fi
}

list_built()
{ if [ $(uname) = Darwin ]; then
list_file build.macosx-fat/swipl-${version}-1.fat.dmg
list_file build.macosx-gcc/swipl-${version}-1.x86_64.dmg
list_file build.macosx/swipl-${version}-1.x86_64.dmg
else
ls -l build.win32/swipl-${version}-1.x86.exe
ls -l build.win64/swipl-${version}-1.x64.exe
ls -l build.pdf/man/SWI-Prolog-$version.pdf
ls -l ../swipl-$version.tar.gz
fi
}

build()
{ is_clean_release && force_build
}
Expand All @@ -168,8 +192,10 @@ force_build()
build_win32
build_win64
build_source
build_PPAs
[ "$PPA" = no ] || build_PPAs
fi

list_built
}

################
Expand Down
4 changes: 2 additions & 2 deletions src/parms.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#cmakedefine PLSHAREDHOME "@PLSHAREDHOME@"
#cmakedefine PLPKGNAME "@SWIPL_PKG_NAME@"
#define PLARCH "@PLARCH@"
#define C_CC "@C_CC@"
#define C_CXX "@C_CXX@"
#define C_CC "@SWIPL_CC@"
#define C_CXX "@SWIPL_CXX@"
#define C_CFLAGS "@C_CFLAGS@"
#cmakedefine SO_EXT "@SO_EXT@"
#cmakedefine SO_PATH "@SO_PATH@"
Expand Down

0 comments on commit 41d442a

Please sign in to comment.