Skip to content

Commit

Permalink
Fix building with cmake+ninja on BSD systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
tx00100xt committed Nov 20, 2023
1 parent 6425779 commit e35c6b6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 37 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ endif()


# Set up some sanity stuff...
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD")
SET(LINUX TRUE)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU")
set(LINUX TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
SET(FREEBSD TRUE)
set(FREEBSD TRUE)
endif()
if(APPLE)
SET(MACOSX TRUE)
set(MACOSX TRUE)
endif()
if(MSVC)
SET(WINDOWS TRUE)
set(WINDOWS TRUE)
endif()

# remove clang spam.
Expand All @@ -102,9 +102,9 @@ endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
SET(DEBUG FALSE)
set(DEBUG FALSE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(DEBUG TRUE)
set(DEBUG TRUE)
endif()

if (LINUX)
Expand Down
57 changes: 42 additions & 15 deletions SamTFE/Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,46 @@ endif()
###############################################################

# Set up some sanity stuff...
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD")
SET(LINUX TRUE)
# Set up some sanity stuff...
# Note:
# "-rpath,$ORIGIN" allows you not to use LD_LIBRARY_PATH and is well suited for local installation
# "-rpath,$ORIGIN" don't like new versions of clang + ninja and crashes during linking of the Engine library
# "-rpath=/tmp" is suitable for linking clang + ninja and installing the game into the system
# "-rpath=/var/tmp/portage" is suitable for Gentoo and installing the game into the system
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU")
set(LINUX TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format")
set(RPATH_SETTINGS "-rpath,$ORIGIN")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
SET(FREEBSD TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-enum-constexpr-conversion -Wno-unused-but-set-variable -Wno-uninitialized -Wno-unused-function -Wno-format")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-enum-constexpr-conversion -Wno-unused-but-set-variable -Wno-uninitialized -Wno-unused-function -Wno-format")
set(FREEBSD TRUE)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") # for local install
set(RPATH_SETTINGS "-rpath,$ORIGIN")
message(STATUS "Using cmake generator 'Unix Makefiles'")
elseif(CMAKE_GENERATOR STREQUAL "Ninja") # defalt for install to the system
set(RPATH_SETTINGS "-rpath=/tmp")
message(STATUS "Using cmake generator 'Ninja'")
else()
message(FATAL_ERROR "Unknown cmake generator")
endif()
endif()
if(APPLE)
SET(MACOSX TRUE)
set(MACOSX TRUE)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(RPATH_SETTINGS "-rpath,$ORIGIN")
message(STATUS "Using cmake generator 'Unix Makefiles'")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(RPATH_SETTINGS "-rpath=/tmp")
message(STATUS "Using cmake generator 'Ninja'")
else()
message(FATAL_ERROR "Unknown cmake generator")
endif()
endif()
if(MSVC)
SET(WINDOWS TRUE)
set(WINDOWS TRUE)
endif()

# RAKE! Where to install the binaries.
Expand Down Expand Up @@ -187,9 +214,9 @@ endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
SET(DEBUG FALSE)
set(DEBUG FALSE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(DEBUG TRUE)
set(DEBUG TRUE)
endif()

if (LINUX)
Expand Down Expand Up @@ -1429,13 +1456,13 @@ if(RPI4)
endif()

if(FREEBSD OR MACOSX)
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
else()
if(USE_SYSTEM_VULKAN)
target_link_libraries(${ENGINELIB} vulkan)
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-lvulkan,-rpath,$ORIGIN")
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-lvulkan,${RPATH_SETTINGS}")
else()
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
endif()
endif()

Expand Down Expand Up @@ -1531,22 +1558,22 @@ if(MACOSX)
endif()

if(LINUX)
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(SeriousSam${MP} "m")
target_link_libraries(SeriousSam${MP} "dl")
target_link_libraries(SeriousSam${MP} "pthread")
target_link_libraries(SeriousSam${MP} ${SDL2_LIBRARY})
target_link_libraries(SeriousSam${MP} ${ZLIB_LIBRARIES})
if(BUILD_DEDICATED_SERVER)
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(DedicatedServer${MP} "m")
target_link_libraries(DedicatedServer${MP} "dl")
target_link_libraries(DedicatedServer${MP} "pthread")
target_link_libraries(DedicatedServer${MP} ${SDL2_LIBRARY})
target_link_libraries(DedicatedServer${MP} ${ZLIB_LIBRARIES})
endif()
if(BUILD_MAKEFONT)
set_target_properties(MakeFONT${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(MakeFONT${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(MakeFONT${MP} "m")
target_link_libraries(MakeFONT${MP} "dl")
target_link_libraries(MakeFONT${MP} "pthread")
Expand All @@ -1556,13 +1583,13 @@ if(LINUX)
endif()

if(FREEBSD)
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(SeriousSam${MP} "m")
target_link_libraries(SeriousSam${MP} "pthread")
target_link_libraries(SeriousSam${MP} ${SDL2_LIBRARY})
target_link_libraries(SeriousSam${MP} ${ZLIB_LIBRARIES})
if(BUILD_DEDICATED_SERVER)
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(DedicatedServer${MP} "m")
target_link_libraries(DedicatedServer${MP} "pthread")
target_link_libraries(DedicatedServer${MP} ${SDL2_LIBRARY})
Expand Down
56 changes: 41 additions & 15 deletions SamTSE/Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,45 @@ endif()
###############################################################

# Set up some sanity stuff...
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU|kFreeBSD")
SET(LINUX TRUE)
# Note:
# "-rpath,$ORIGIN" allows you not to use LD_LIBRARY_PATH and is well suited for local installation
# "-rpath,$ORIGIN" don't like new versions of clang + ninja and crashes during linking of the Engine library
# "-rpath=/tmp" is suitable for linking clang + ninja and installing the game into the system
# "-rpath=/var/tmp/portage" is suitable for Gentoo and installing the game into the system
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME MATCHES "GNU")
set(LINUX TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-format")
set(RPATH_SETTINGS "-rpath,$ORIGIN")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
SET(FREEBSD TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-enum-constexpr-conversion -Wno-unused-but-set-variable -Wno-uninitialized -Wno-unused-function -Wno-format")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-enum-constexpr-conversion -Wno-unused-but-set-variable -Wno-uninitialized -Wno-unused-function -Wno-format")
set(FREEBSD TRUE)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") # for local install
set(RPATH_SETTINGS "-rpath,$ORIGIN")
message(STATUS "Using cmake generator 'Unix Makefiles'")
elseif(CMAKE_GENERATOR STREQUAL "Ninja") # defalt for install to the system
set(RPATH_SETTINGS "-rpath=/tmp")
message(STATUS "Using cmake generator 'Ninja'")
else()
message(FATAL_ERROR "Unknown cmake generator")
endif()
endif()
if(APPLE)
SET(MACOSX TRUE)
set(MACOSX TRUE)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(RPATH_SETTINGS "-rpath,$ORIGIN")
message(STATUS "Using cmake generator 'Unix Makefiles'")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(RPATH_SETTINGS "-rpath=/tmp")
message(STATUS "Using cmake generator 'Ninja'")
else()
message(FATAL_ERROR "Unknown cmake generator")
endif()
endif()
if(MSVC)
SET(WINDOWS TRUE)
set(WINDOWS TRUE)
endif()

# RAKE! Where to install the binaries.
Expand Down Expand Up @@ -187,9 +213,9 @@ endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
SET(DEBUG FALSE)
set(DEBUG FALSE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(DEBUG TRUE)
set(DEBUG TRUE)
endif()

if (LINUX)
Expand Down Expand Up @@ -1429,13 +1455,13 @@ if(RPI4)
endif()

if(FREEBSD OR MACOSX)
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
else()
if(USE_SYSTEM_VULKAN)
target_link_libraries(${ENGINELIB} vulkan)
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-lvulkan,-rpath,$ORIGIN")
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-lvulkan,${RPATH_SETTINGS}")
else()
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(${ENGINELIB} PROPERTIES ENABLE_EXPORTS ON LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
endif()
endif()

Expand Down Expand Up @@ -1531,22 +1557,22 @@ if(MACOSX)
endif()

if(LINUX)
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(SeriousSam${MP} "m")
target_link_libraries(SeriousSam${MP} "dl")
target_link_libraries(SeriousSam${MP} "pthread")
target_link_libraries(SeriousSam${MP} ${SDL2_LIBRARY})
target_link_libraries(SeriousSam${MP} ${ZLIB_LIBRARIES})
if(BUILD_DEDICATED_SERVER)
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(DedicatedServer${MP} "m")
target_link_libraries(DedicatedServer${MP} "dl")
target_link_libraries(DedicatedServer${MP} "pthread")
target_link_libraries(DedicatedServer${MP} ${SDL2_LIBRARY})
target_link_libraries(DedicatedServer${MP} ${ZLIB_LIBRARIES})
endif()
if(BUILD_MAKEFONT)
set_target_properties(MakeFONT${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(MakeFONT${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(MakeFONT${MP} "m")
target_link_libraries(MakeFONT${MP} "dl")
target_link_libraries(MakeFONT${MP} "pthread")
Expand All @@ -1556,13 +1582,13 @@ if(LINUX)
endif()

if(FREEBSD)
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(SeriousSam${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(SeriousSam${MP} "m")
target_link_libraries(SeriousSam${MP} "pthread")
target_link_libraries(SeriousSam${MP} ${SDL2_LIBRARY})
target_link_libraries(SeriousSam${MP} ${ZLIB_LIBRARIES})
if(BUILD_DEDICATED_SERVER)
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,-rpath,$ORIGIN")
set_target_properties(DedicatedServer${MP} PROPERTIES LINK_FLAGS "-Wl,${RPATH_SETTINGS}")
target_link_libraries(DedicatedServer${MP} "m")
target_link_libraries(DedicatedServer${MP} "pthread")
target_link_libraries(DedicatedServer${MP} ${SDL2_LIBRARY})
Expand Down

0 comments on commit e35c6b6

Please sign in to comment.