Skip to content

Commit

Permalink
Merge pull request #112 from ermo/cmake-fpie-off-by-default
Browse files Browse the repository at this point in the history
Set -fno-PIE by default as a Ubuntu/Mint workaround
  • Loading branch information
BenjamenMeyer authored May 13, 2020
2 parents 374316f + 4389419 commit f1584dd
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 23 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ sudo apt-get -y install git cmake python-dev build-essential automake autoconf l
ccmake ../engine
# (configure/edit options to taste in ccmake, press 'c' to save the selected options
# and press 'g' to update the build configuration files used by the make build tool)
make -jN # (where N is the number of available CPU threads/cores on your system)
cmake --build . -j $(nproc) # (where $(nproc) returns the number of available CPU threads/cores on the system)
mkdir ../bin && cp vegastrike ../bin/ && cp setup/vssetup ../bin/ && cd ..
```

Expand All @@ -260,15 +260,45 @@ sudo apt-get -y install git cmake python-dev build-essential automake autoconf l
```bash
mkdir build & cd build
cmake ../engine
make -jN # (where N is the number of available CPU threads/cores on your system)
cmake --build . -j $(nproc) # (where $(nproc) returns the number of available CPU threads/cores on the system)
mkdir ../bin && cp vegastrike ../bin/ && cp setup/vssetup ../bin/ && cd ..
```
To enable/disable compile-time options with cmake, use `cmake -D<option>`. Example:

__TIPS__:

To enable verbose output for debugging purposes (will show compilation commands), pass the `-- VERBOSE=1` argument:

```bash
cmake --build . -- VERBOSE=1
```

To enable/disable compile-time options with cmake, use `cmake -D<option>=<value>`. Example:

```bash
cmake ../engine -DUSE_PYTHON_3=ON -DCPU_SMP=2 -DCPUINTEL_native=ON -CMAKE_BUILD_TYPE=Debug
cmake ../engine -DENABLE_PIE=ON -DUSE_PYTHON_3=ON -DCPU_SMP=2 -DCPUINTEL_native=ON -CMAKE_BUILD_TYPE=Debug
```

__NOTE__:

On some Ubuntu versions and derivatives, a bug exists whereby enabling
PIE compilation (Position Independent Executables) results in the
`file` utility incorrectly recognising the compiled vegastrike binary
as a shared library instead of a position independent shared executable
object.

The effect of the bug is that vegastrike can still be started from the
command line but that it will not be recognised as an executable by GUI
file managers such as Nautilus and Dolphin.

To avoid this scenario, turn off this flag by default and let packagers
on other distributions turn this on if their OS is able to correctly deal
with Position Independent Executables.

For more info, see:

- https://bugs.launchpad.net/ubuntu/+source/file/+bug/1747711
- https://github.com/vegastrike/Vega-Strike-Engine-Source/issues/94

[Link to list of dependencies in wiki](http://vegastrike.sourceforge.net/wiki/HowTo:Compile_from_CVS)

If there are any problems with this installation method,
Expand Down
42 changes: 37 additions & 5 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,40 @@ IF(DATADIR)
ENDIF(DATADIR)


# On some Ubuntu versions and derivatives, a bug exists whereby enabling
# PIE compilation (Position Independent Executables) results in the
# `file` utility incorrectly recognising the compiled vegastrike binary
# as a shared library instead of a position independent shared executable
# object.
#
# The effect of the bug is that vegastrike can still be started from the
# command line but that it will not be recognised as an executable by GUI
# file managers such as Nautilus and Dolphin.
#
# To avoid this scenario, turn off this flag by default and let packagers
# on other distributions turn this on if their OS is able to correctly deal
# with Position Independent Executables.

# For more info, see:
# - https://bugs.launchpad.net/ubuntu/+source/file/+bug/1747711
# - https://github.com/vegastrike/Vega-Strike-Engine-Source/issues/94
#
#UNSET(CMAKE_POSITION_INDEPENDENT_CODE)
OPTION(ENABLE_PIE
"Enable Position Independent Executables/Shared Libraries (NOT RECOMMENDED on Ubuntu/Mint)"
OFF)
IF(ENABLE_PIE)
message("!! Enabling Position Independent Executables/Shared Libraries (NOT RECOMMENDED on Ubuntu/Mint) !!")
#SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_options("-pie")
link_libraries("-pie")
ELSE(ENABLE_PIE)
message("++ Disabling Position Independent Executables/Shared Libraries (Recommended on Ubuntu/Mint)")
add_compile_options("-no-pie")
link_libraries("-no-pie")
ENDIF(ENABLE_PIE)


# Debug target block.
SET(CMAKE_CXX_FLAGS_DEBUG " ${BUILD_OPT} ${CPU_OPTS} ${DEFINES} -include config.h -pipe -g2 -std=c++11 -Wall -fvisibility=hidden" CACHE STRING
"Flags used by the C++ compiler during debug builds."
Expand Down Expand Up @@ -1000,13 +1034,11 @@ add_subdirectory(setup)
add_subdirectory(objconv)




# show debug output
get_directory_property(TEMP_DIRECTORY INCLUDE_DIRECTORIES)
message("Default build type is Release, no cpu opts enabled. ")
message("Building with BUILD_OPT: ${BUILD_OPT}")
#message("Building with CFLAGS: ${CMAKE_CXX_FLAGS}")
message("-- Default build type is Release, no cpu opts enabled. ")
message("++ Building with BUILD_OPT: ${BUILD_OPT}")
#message("++ Building with CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
#message("Linking with : ${TST_LIBS}")
#message("including : ${TEMP_DIRECTORY}")
# end debug output
Expand Down
25 changes: 11 additions & 14 deletions sh/vsbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


echo "-------------------------------"
echo "--- vsbuild.sh | 2020-02-09 ---"
echo "--- vsbuild.sh | 2020-05-13 ---"
echo "-------------------------------"

#----------------------------------
Expand All @@ -32,26 +32,23 @@ BIN_DIR=$ROOT_DIR/bin
SRC_DIR=$ROOT_DIR/engine
COMMAND=""

if [ ! -d "$BUILD_DIR" ]; then
mkdir $BUILD_DIR
fi
# -p creates if the target doesn't exist, noop otherwise
mkdir -pv $BUILD_DIR && cd $BUILD_DIR

cd $BUILD_DIR

# configure libraries
cmake -DCMAKE_BUILD_TYPE=Release $@ $SRC_DIR
# configure libraries and prepare for the Debug build having -Werror set,
# thus gating VS commits on being warning-free at some point in the near
# future -- see https://github.com/vegastrike/Vega-Strike-Engine-Source/issues/50
cmake -DCMAKE_BUILD_TYPE=Debug $@ $SRC_DIR

# for a clean build only
# mut we can do it manually
#make clean

# compile now using all cpus
make -j$(nproc)
# compile now using all cpus and show compilation commands
cmake --build . -j $(nproc) -- VERBOSE=1

cd $ROOT_DIR

if [ ! -d "$BIN_DIR" ]; then
mkdir $BIN_DIR
fi
mkdir -pv $BIN_DIR

cp $BUILD_DIR/{vegastrike,setup/vssetup,objconv/mesh_tool} $BIN_DIR
cp -v $BUILD_DIR/{vegastrike,setup/vssetup,objconv/mesh_tool} $BIN_DIR

0 comments on commit f1584dd

Please sign in to comment.