Skip to content

Commit

Permalink
Set -fno-PIE by default as a Ubuntu/Mint workaround
Browse files Browse the repository at this point in the history
Older versions of Ubuntu and its derivates have an issue where the
`file` utility will interpret Position Independent Executables as
shared libraries:

https://bugs.launchpad.net/ubuntu/+source/file/+bug/1747711

As a workaround, allow setting the option COMPILE_WITH_FPIE
(defaults to OFF) and add a suitable message for maintainers in both
the CMake code, during configuration runs and in ccmake.

Update the build instructions in the README to reflect this change.

Closes vegastrike#94
  • Loading branch information
ermo committed May 12, 2020
1 parent 374316f commit a97b265
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
17 changes: 14 additions & 3 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 . -jN # (where N is the number of available CPU threads/cores on your system)
mkdir ../bin && cp vegastrike ../bin/ && cp setup/vssetup ../bin/ && cd ..
```

Expand All @@ -260,13 +260,24 @@ 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 . -jN # (where N is the number of available CPU threads/cores on your system)
mkdir ../bin && cp vegastrike ../bin/ && cp setup/vssetup ../bin/ && cd ..
```

*TIPS:*

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

```bash
cmake ../engine -DUSE_PYTHON_3=ON -DCPU_SMP=2 -DCPUINTEL_native=ON -CMAKE_BUILD_TYPE=Debug
cmake ../engine -COMPILE_WITH_FPIE=ON -DUSE_PYTHON_3=ON -DCPU_SMP=2 -DCPUINTEL_native=ON -CMAKE_BUILD_TYPE=Debug
```
In the above example, a non-Ubuntu/Mint packager has wisely decided to compile a
Position Independent Executable because his OS isn't
[buggy](https://bugs.launchpad.net/ubuntu/+source/file/+bug/1747711) when doing so.

To enable verbose output for debugging purposes (will show compilation commands), supply the `-v` flag:
```bash
cmake --build . -v
```

[Link to list of dependencies in wiki](http://vegastrike.sourceforge.net/wiki/HowTo:Compile_from_CVS)
Expand Down
31 changes: 30 additions & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=gnu++03)
endif()


# Provide boolean options for enabling various cpu optimizations.
OPTION(CPUAMD_k8 "Enable AMD K8 optimizations (Athlon through athlon64)"
OFF )
Expand Down Expand Up @@ -650,6 +649,36 @@ ELSE("${CMAKE_BUILD_TYPE}" STREQUAL "Profiler")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "Profiler")


# 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.
#
# 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(COMPILE_WITH_FPIE CACHE)
UNSET(CMAKE_POSITION_INDEPENDENT_CODE)
OPTION(COMPILE_WITH_FPIE
"Enable Position Independent Executables (NOT RECOMMENDED on Debian/Ubuntu/Mint)"
OFF)
IF(COMPILE_WITH_FPIE)
message("!! Enabling Position Independent Executables (NOT RECOMMENDED on Debian/Ubuntu/Mint) !!")
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
ELSE(COMPILE_WITH_FPIE)
message("++ Disabling Position Independent Executables (Recommended on Debian/Ubuntu/Mint)")
add_compile_options(-fno-PIE)
ENDIF(COMPILE_WITH_FPIE)


# Turn off compiling vegastrike bin
OPTION(DISABLE_CLIENT "Disable building the vegastrike bin"
OFF )
Expand Down

0 comments on commit a97b265

Please sign in to comment.