diff --git a/ProjectOptions.cmake b/ProjectOptions.cmake index 8bc95d9..559ca06 100644 --- a/ProjectOptions.cmake +++ b/ProjectOptions.cmake @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/makefile b/makefile index 715fab1..1d287d2 100644 --- a/makefile +++ b/makefile @@ -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 } }' diff --git a/psim/CMakeLists.txt b/psim/CMakeLists.txt index 63f72c7..722924b 100644 --- a/psim/CMakeLists.txt +++ b/psim/CMakeLists.txt @@ -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