Skip to content

Commit

Permalink
Update options and makefile
Browse files Browse the repository at this point in the history
Add option to statically link libc and libc++ to allow the corresponding executable to run on older systems
  • Loading branch information
GwGibson committed Aug 8, 2023
1 parent 3078be5 commit 76bca0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ProjectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro(psim_setup_options)
psim_supports_sanitizers()

if(ENABLE_DEVELOPER_MODE)
option(psim_ENABLE_IPO "Enable IPO/LTO" ON)
option(psim_ENABLE_IPO "Enable IPO/LTO" OFF)
option(psim_WARNINGS_AS_ERRORS "Treat Warnings As Errors" ON)
option(psim_ENABLE_DOXYGEN "Build documentation with Doxygen" OFF)
option(psim_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
Expand All @@ -42,8 +42,9 @@ macro(psim_setup_options)
option(psim_ENABLE_CPPCHECK "Enable cpp-check analysis" ON)
option(psim_ENABLE_PCH "Enable precompiled headers" OFF)
option(psim_ENABLE_CACHE "Enable ccache" ON)
option(psim_STATIC_LINK_LIBC "Statically link standard libraries" OFF)
else()
option(psim_ENABLE_IPO "Enable IPO/LTO" OFF)
option(psim_ENABLE_IPO "Enable IPO/LTO" ON)
option(psim_WARNINGS_AS_ERRORS "Treat Warnings As Errors" OFF)
option(psim_ENABLE_DOXYGEN "Build documentation with Doxygen" OFF)
option(psim_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
Expand All @@ -57,6 +58,7 @@ macro(psim_setup_options)
option(psim_ENABLE_CPPCHECK "Enable cpp-check analysis" OFF)
option(psim_ENABLE_PCH "Enable precompiled headers" OFF)
option(psim_ENABLE_CACHE "Enable ccache" OFF)
option(psim_STATIC_LINK_LIBC "Statically link standard libraries" OFF)
endif()

mark_as_advanced(FORCE ENABLE_DEVELOPER_MODE)
Expand Down Expand Up @@ -97,6 +99,16 @@ endmacro()
macro(psim_local_options)
if(PROJECT_IS_TOP_LEVEL)
include(cmake/StandardProjectSettings.cmake)
# Statically link the standard libraries to allow the executable to run
# on servers with older software
if (psim_STATIC_LINK_LIBC)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=skylake-avx512")
endif()

endif()
endif()

add_library(psim_warnings INTERFACE)
Expand Down
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ debug:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DENABLE_DEVELOPER_MODE:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Debug
cmake --build ./build --config Debug

link_libc:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=Release -Dpsim_STATIC_LINK_LIBC=ON
cmake --build ./build --config Release

format:
ifeq ($(OS), Windows_NT)
pwsh -c '$$files=(git ls-files --exclude-standard); foreach ($$file in $$files) { if ((get-item $$file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $$file } }'
Expand Down
6 changes: 6 additions & 0 deletions psim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=skylake-avx512")
endif()

file(GLOB_RECURSE PSIM_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" # Header files
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" # Source files
Expand Down

0 comments on commit 76bca0d

Please sign in to comment.