Skip to content

Commit

Permalink
made linux auto-builds more portable
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Jul 11, 2024
1 parent 6696c52 commit 5eabdab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
mkdir build
- name: cmake
working-directory: ./build
run: cmake -G Ninja -DCMAKE_BUILD_TYPE=Portable64 -DVENDORED_DEPENDENCIES=1 ..
run: cmake -G Ninja -DCMAKE_BUILD_TYPE=Portable64 ..
- name: make
working-directory: ./build
run: ninja
Expand Down
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ ELSE ()
MESSAGE( FATAL_ERROR "Portable target is deprecated, please use Portable32 or Portable64 instead" )
ELSEIF ( CMAKE_BUILD_TYPE STREQUAL "Portable64" OR CMAKE_BUILD_TYPE STREQUAL "Portable32" )
TARGET_COMPILE_DEFINITIONS( ${PROJECT_NAME} PRIVATE PORTABLE=1 )
SET( VENDORED_DEPENDENCIES 1 ) # for static linking
IF ( WIN32 )
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -static ) # this won't work on linux because there may be binary video drivers without static libraries
ELSE ()
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -static-libgcc -static-libstdc++ )
ENDIF ()
IF ( CMAKE_BUILD_TYPE STREQUAL "Portable32" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -march=i686 -mtune=i686" )
ELSEIF ( CMAKE_BUILD_TYPE STREQUAL "Portable64" )
Expand All @@ -70,18 +76,16 @@ IF ( VISUAL_STUDIO ) # (Provided in CMakePresets)
ELSEIF ( WIN32 ) # probably mingw or github runner
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE wsock32 )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE ws2_32 )
# TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -static-libgcc -static-libstdc++ -static-winpthread )
TARGET_LINK_OPTIONS( ${PROJECT_NAME} PRIVATE -static )
ENDIF ()

# needed for some uncommon IDE and OS combinations
FIND_LIBRARY( LIBCPP_LIBRARY NAMES libc++.so libc++.a )
IF ( LIBCPP_LIBRARY )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} -lc++ )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE -lc++ )
ENDIF ()
FIND_LIBRARY( LIBM_LIBRARY NAMES libm.so libm.a )
IF ( LIBM_LIBRARY )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} -lm )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE -lm )
ENDIF ()

IF ( VENDORED_DEPENDENCIES )
Expand Down Expand Up @@ -120,7 +124,7 @@ ELSE ()
PKG_SEARCH_MODULE( YAMLCPP REQUIRED yaml-cpp )

INCLUDE_DIRECTORIES( ${FT2_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${OSSPUUID_INCLUDE_DIRS} ${YAMLCPP_INCLUDE_DIRS} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${FT2_LIBRARIES} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${GLEW_LIBRARIES} ${OSSPUUID_LIBRARIES} ${YAMLCPP_LIBRARIES} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE ${FT2_LIBRARIES} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${GLEW_LIBRARIES} ${OSSPUUID_LIBRARIES} ${YAMLCPP_LIBRARIES} )
ENDIF ()

IF ( NOT WIN32 )
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ For same build as before (or Release if it's first build): `cmake -S . -B build

Add -j parameter to make to speed up if you have multiple cores, i.e. `make -C build -j9` for 8 cores.

Optionally, add `-DVENDORED_DEPENDENCIES=YES` to cmake parameters to download and build all required libraries, instead of using system-installed ones. By default this is enabled on Windows and disabled on other OSes. You can't disable it on Windows.
Optionally, add `-DVENDORED_DEPENDENCIES=YES` to cmake parameters to download and build all required libraries, instead of using system-installed ones. By default this is enabled on Windows and disabled on other OSes. You can't disable it on Windows. Portable32 and Portable64 enable vendored dependencies automatically.

Optionally, use `VERBOSE=1 make -C build` to see actual compiling/linking commands (useful when build fails)

Expand Down

0 comments on commit 5eabdab

Please sign in to comment.