Skip to content

Commit

Permalink
Updated compiled and linker flags with no-pie properly
Browse files Browse the repository at this point in the history
- There were some differences between the Makefile flags and CMake. Now they are identical
- Updated the Findmpg123.cmake file with the latest one from upstream
  • Loading branch information
midwan committed Sep 23, 2024
1 parent 59d6f2b commit 6f86eb8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 37 deletions.
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ enable_language(C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_FLAGS_RELEASE "-O3 -pipe")
set(CMAKE_C_FLAGS_DEBUG "-Og -g -funwind-tables -DDEBUG -pipe")
set(CMAKE_C_FLAGS_RELEASE "-O3 -pipe -fno-pie -no-pie")
set(CMAKE_C_FLAGS_DEBUG "-Og -g -funwind-tables -DDEBUG -pipe -fno-pie -no-pie")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")

Expand Down Expand Up @@ -418,7 +418,6 @@ else ()
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
endif()

target_compile_options(${PROJECT_NAME} PRIVATE -fno-pie)
target_compile_definitions(${PROJECT_NAME} PRIVATE _FILE_OFFSET_BITS=64)

if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
Expand Down Expand Up @@ -464,10 +463,7 @@ add_subdirectory(external/libguisan)
add_dependencies(${PROJECT_NAME} mt32emu floppybridge capsimage guisan)

target_include_directories(${PROJECT_NAME} PRIVATE src src/osdep src/include src/threaddep src/archivers src/ppc/pearpc external/libguisan/include external/mt32emu/src external/floppybridge/src)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2 SDL2_image SDL2_ttf guisan mt32emu ${DBUS_LIBRARIES} FLAC portmidi png mpg123 mpeg2convert mpeg2 serialport z)
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_options(${PROJECT_NAME} PRIVATE "LINKER:-as-needed,-no-pie")
endif ()
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2 SDL2_image SDL2_ttf guisan mt32emu ${DBUS_LIBRARIES} FLAC portmidi png MPG123::libmpg123 mpeg2convert mpeg2 serialport z pthread dl)

if (USE_OPENGL)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_OPENGL)
Expand Down
91 changes: 61 additions & 30 deletions cmake/Findmpg123.cmake
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
# - Find mpg123
# Find the native mpg123 includes and libraries
#
# MPG123_INCLUDE_DIRS - where to find mpg123.h, etc.
# MPG123_LIBRARIES - List of libraries when using mpg123.
# MPG123_FOUND - True if Mpg123 found.

if (MPG123_INCLUDE_DIR)
#[=======================================================================[.rst:
Findmpg123
-------

Finds the mpg123 library.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported targets, if found:

``MPG123::libmpg123``
The mpg123 library

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables:

``mpg123_FOUND``
True if the system has the mpg123 package.
``mpg123_VERSION``
The version of mpg123 that was found on the system.

Cache Variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``mpg123_INCLUDE_DIR``
The directory containing ``mpg123.h``.
``mpg123_LIBRARY``
The path to the mpg123 library.

#]=======================================================================]

if (mpg123_INCLUDE_DIR)
# Already in cache, be silent
set(MPG123_FIND_QUIETLY TRUE)
set(mpg123_FIND_QUIETLY TRUE)
endif ()

find_package (PkgConfig QUIET)
pkg_check_modules(PC_MPG123 QUIET libmpg123>=1.25.10)

set (MPG123_VERSION ${PC_MPG123_VERSION})

find_path (MPG123_INCLUDE_DIR mpg123.h
find_path (mpg123_INCLUDE_DIR mpg123.h
HINTS
${PC_MPG123_INCLUDEDIR}
${PC_MPG123_INCLUDE_DIRS}
${MPG123_ROOT}
${mpg123_ROOT}
)

# MSVC built mpg123 may be named mpg123_static.
# The provided project files name the library with the lib prefix.

find_library (MPG123_LIBRARY
find_library (mpg123_LIBRARY
NAMES
mpg123
mpg123_static
Expand All @@ -34,31 +61,35 @@ find_library (MPG123_LIBRARY
HINTS
${PC_MPG123_LIBDIR}
${PC_MPG123_LIBRARY_DIRS}
${MPG123_ROOT}
${mpg123_ROOT}
)

# Handle the QUIETLY and REQUIRED arguments and set MPG123_FOUND
if (PC_MPG123_FOUND)
set (mpg123_VERSION ${PC_MPG123_VERSION})
elseif (mpg123_INCLUDE_DIR)
file (READ "${mpg123_INCLUDE_DIR}/mpg123.h" _mpg123_h)
string (REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" _mpg123_version_re "${_mpg123_h}")
set (mpg123_VERSION "${_mpg123_version_re}")
endif ()

# Handle the QUIETLY and REQUIRED arguments and set mpg123_FOUND
# to TRUE if all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args (mpg123
REQUIRED_VARS
MPG123_LIBRARY
MPG123_INCLUDE_DIR
mpg123_LIBRARY
mpg123_INCLUDE_DIR
VERSION_VAR
MPG123_VERSION
mpg123_VERSION
)

if (MPG123_FOUND)
set (MPG123_LIBRARIES ${MPG123_LIBRARY})
set (MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR})

if (NOT TARGET MPG123::libmpg123)
add_library (MPG123::libmpg123 UNKNOWN IMPORTED)
set_target_properties (MPG123::libmpg123 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MPG123_INCLUDE_DIRS}"
IMPORTED_LOCATION "${MPG123_LIBRARIES}"
if (mpg123_FOUND AND NOT TARGET MPG123::libmpg123)
add_library (MPG123::libmpg123 UNKNOWN IMPORTED)
set_target_properties (MPG123::libmpg123
PROPERTIES
IMPORTED_LOCATION "${mpg123_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${mpg123_INCLUDE_DIR}"
)
endif ()
endif ()

mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY)
mark_as_advanced(mpg123_INCLUDE_DIR mpg123_LIBRARY)

0 comments on commit 6f86eb8

Please sign in to comment.