2010-01-21 15:12:50 +00:00
#-------------------------------------------------------------------------------
2021-07-04 05:24:21 +00:00
# detectOperatingSystem
2010-01-21 15:12:50 +00:00
#-------------------------------------------------------------------------------
# This function detects on which OS cmake is run and set a flag to control the
# build process. Supported OS: Linux, MacOSX, Windows
2013-01-02 13:34:38 +00:00
#
# On linux, it also set a flag for specific distribution (ie Fedora)
2010-01-21 15:12:50 +00:00
#-------------------------------------------------------------------------------
function ( detectOperatingSystem )
2021-07-04 05:24:21 +00:00
if ( WIN32 )
set ( Windows TRUE PARENT_SCOPE )
elseif ( UNIX AND APPLE )
2023-02-14 10:32:39 +00:00
if ( IOS )
message ( WARNING "iOS isn't supported, the build will most likely fail" )
endif ( )
2021-07-04 05:24:21 +00:00
set ( MacOSX TRUE PARENT_SCOPE )
elseif ( UNIX )
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
set ( Linux TRUE PARENT_SCOPE )
if ( EXISTS /etc/os-release )
# Read the file without CR character
file ( STRINGS /etc/os-release OS_RELEASE )
if ( "${OS_RELEASE}" MATCHES "^.*ID=fedora.*$" )
set ( Fedora TRUE PARENT_SCOPE )
message ( STATUS "Build Fedora specific" )
elseif ( "${OS_RELEASE}" MATCHES "^.*ID=.*suse.*$" )
set ( openSUSE TRUE PARENT_SCOPE )
message ( STATUS "Build openSUSE specific" )
endif ( )
endif ( )
elseif ( CMAKE_SYSTEM_NAME MATCHES "kFreeBSD" )
set ( kFreeBSD TRUE PARENT_SCOPE )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "GNU" )
set ( GNU TRUE PARENT_SCOPE )
endif ( )
endif ( )
2014-12-28 06:41:57 +00:00
endfunction ( )
2013-06-28 10:43:50 +00:00
2020-05-24 06:19:47 +00:00
function ( get_git_version_info )
2021-07-04 05:24:21 +00:00
set ( PCSX2_WC_TIME 0 )
set ( PCSX2_GIT_REV "" )
2021-10-18 04:09:42 +00:00
set ( PCSX2_GIT_TAG "" )
2022-05-12 15:54:02 +00:00
set ( PCSX2_GIT_HASH "" )
2021-07-04 05:24:21 +00:00
if ( GIT_FOUND AND EXISTS ${ PROJECT_SOURCE_DIR } /.git )
EXECUTE_PROCESS ( WORKING_DIRECTORY ${ PROJECT_SOURCE_DIR } COMMAND ${ GIT_EXECUTABLE } show -s --format=%ci HEAD
O U T P U T _ V A R I A B L E P C S X 2 _ W C _ T I M E
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
# Output: "YYYY-MM-DD HH:MM:SS +HHMM" (last part is time zone, offset from UTC)
string ( REGEX REPLACE "[%:\\-]" "" PCSX2_WC_TIME "${PCSX2_WC_TIME}" )
string ( REGEX REPLACE "([0-9]+) ([0-9]+).*" "\\1\\2" PCSX2_WC_TIME "${PCSX2_WC_TIME}" )
2016-11-08 21:44:39 +00:00
2021-08-12 04:18:21 +00:00
EXECUTE_PROCESS ( WORKING_DIRECTORY ${ PROJECT_SOURCE_DIR } COMMAND ${ GIT_EXECUTABLE } describe
2021-07-04 05:24:21 +00:00
O U T P U T _ V A R I A B L E P C S X 2 _ G I T _ R E V
2021-08-12 04:18:21 +00:00
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
E R R O R _ Q U I E T )
2021-10-18 04:09:42 +00:00
EXECUTE_PROCESS ( WORKING_DIRECTORY ${ PROJECT_SOURCE_DIR } COMMAND ${ GIT_EXECUTABLE } tag --points-at HEAD
O U T P U T _ V A R I A B L E P C S X 2 _ G I T _ T A G
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
E R R O R _ Q U I E T )
2022-05-12 15:54:02 +00:00
EXECUTE_PROCESS ( WORKING_DIRECTORY ${ PROJECT_SOURCE_DIR } COMMAND ${ GIT_EXECUTABLE } rev-parse HEAD
O U T P U T _ V A R I A B L E P C S X 2 _ G I T _ H A S H
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
E R R O R _ Q U I E T )
2021-07-04 05:24:21 +00:00
endif ( )
2022-04-11 08:14:48 +00:00
if ( "${PCSX2_GIT_TAG}" MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" )
string ( REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" PCSX2_VERSION_LONG "${PCSX2_GIT_TAG}" )
string ( REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" PCSX2_VERSION_SHORT "${PCSX2_GIT_TAG}" )
elseif ( PCSX2_GIT_REV )
2021-07-04 05:24:21 +00:00
set ( PCSX2_VERSION_LONG "${PCSX2_GIT_REV}" )
string ( REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?(-[a-z][a-z0-9]+)?" PCSX2_VERSION_SHORT "${PCSX2_VERSION_LONG}" )
else ( )
set ( PCSX2_VERSION_LONG "Unknown (git unavailable)" )
set ( PCSX2_VERSION_SHORT "Unknown" )
endif ( )
if ( "${PCSX2_WC_TIME}" STREQUAL "" )
set ( PCSX2_WC_TIME 0 )
endif ( )
2020-05-24 06:19:47 +00:00
2021-07-04 05:24:21 +00:00
set ( PCSX2_WC_TIME "${PCSX2_WC_TIME}" PARENT_SCOPE )
set ( PCSX2_GIT_REV "${PCSX2_GIT_REV}" PARENT_SCOPE )
2021-11-01 22:32:22 +00:00
set ( PCSX2_GIT_TAG "${PCSX2_GIT_TAG}" PARENT_SCOPE )
2022-05-12 15:54:02 +00:00
set ( PCSX2_GIT_HASH "${PCSX2_GIT_HASH}" PARENT_SCOPE )
2021-07-04 05:24:21 +00:00
set ( PCSX2_VERSION_LONG "${PCSX2_VERSION_LONG}" PARENT_SCOPE )
set ( PCSX2_VERSION_SHORT "${PCSX2_VERSION_SHORT}" PARENT_SCOPE )
2020-05-24 06:19:47 +00:00
endfunction ( )
function ( write_svnrev_h )
2021-10-18 04:09:42 +00:00
if ( PCSX2_GIT_TAG )
2022-01-21 14:05:13 +00:00
if ( "${PCSX2_GIT_TAG}" MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" )
file ( WRITE ${ CMAKE_BINARY_DIR } /common/include/svnrev.h
" #define SVN_REV ${PCSX2_WC_TIME}ll\n"
" #define GIT_TAG \"${PCSX2_GIT_TAG}\"\n"
" #define GIT_TAGGED_COMMIT 1\n"
" #define GIT_TAG_HI ${CMAKE_MATCH_1}\n"
" #define GIT_TAG_MID ${CMAKE_MATCH_2}\n"
" #define GIT_TAG_LO ${CMAKE_MATCH_3}\n"
" #define GIT_REV \"\"\n"
2022-05-12 15:54:02 +00:00
" #define GIT_HASH \"${PCSX2_GIT_HASH}\"\n"
2022-01-21 14:05:13 +00:00
)
else ( )
file ( WRITE ${ CMAKE_BINARY_DIR } /common/include/svnrev.h
" #define SVN_REV ${PCSX2_WC_TIME}ll\n"
" #define GIT_TAG \"${PCSX2_GIT_TAG}\"\n"
" #define GIT_TAGGED_COMMIT 1\n"
" #define GIT_REV \"\"\n"
2022-05-12 15:54:02 +00:00
" #define GIT_HASH \"${PCSX2_GIT_HASH}\"\n"
2022-01-21 14:05:13 +00:00
)
endif ( )
2021-10-18 04:09:42 +00:00
else ( )
2022-01-21 14:05:13 +00:00
file ( WRITE ${ CMAKE_BINARY_DIR } /common/include/svnrev.h
" #define SVN_REV ${PCSX2_WC_TIME}ll\n"
" #define GIT_TAG \"${PCSX2_GIT_TAG}\"\n"
" #define GIT_TAGGED_COMMIT 0\n"
" #define GIT_REV \"${PCSX2_GIT_REV}\"\n"
2022-05-12 15:54:02 +00:00
" #define GIT_HASH \"${PCSX2_GIT_HASH}\"\n"
2022-01-21 14:05:13 +00:00
)
2021-10-18 04:09:42 +00:00
endif ( )
2013-06-28 10:43:50 +00:00
endfunction ( )
2013-07-06 09:42:46 +00:00
function ( check_compiler_version version_warn version_err )
2021-07-04 05:24:21 +00:00
if ( CMAKE_COMPILER_IS_GNUCXX )
execute_process ( COMMAND ${ CMAKE_C_COMPILER } -dumpversion OUTPUT_VARIABLE GCC_VERSION )
string ( STRIP "${GCC_VERSION}" GCC_VERSION )
if ( GCC_VERSION VERSION_LESS ${ version_err } )
message ( FATAL_ERROR " PCSX2 doesn't support your old GCC ${ GCC_VERSION } ! Please upgrade it!
2016-11-08 21:44:39 +00:00
2021-07-04 05:24:21 +00:00
T h e m i n i m u m s u p p o r t e d v e r s i o n i s $ { v e r s i o n _ e r r } b u t $ { v e r s i o n _ w a r n } i s w a r m l y r e c o m m e n d e d " )
else ( )
if ( GCC_VERSION VERSION_LESS ${ version_warn } )
message ( WARNING "PCSX2 will stop supporting GCC ${GCC_VERSION} in the near future. Please upgrade to at least GCC ${version_warn}." )
endif ( )
endif ( )
2017-05-11 21:14:06 +00:00
2021-07-04 05:24:21 +00:00
set ( GCC_VERSION "${GCC_VERSION}" PARENT_SCOPE )
endif ( )
2013-07-06 09:42:46 +00:00
endfunction ( )
2014-03-30 14:25:11 +00:00
function ( check_no_parenthesis_in_path )
2021-07-04 05:24:21 +00:00
if ( "${CMAKE_BINARY_DIR}" MATCHES "[()]" OR "${CMAKE_SOURCE_DIR}" MATCHES "[()]" )
message ( FATAL_ERROR "Your path contains some parenthesis. Unfortunately Cmake doesn't support them correctly.\nPlease rename your directory to avoid '(' and ')' characters\n" )
endif ( )
2014-03-30 14:25:11 +00:00
endfunction ( )
2014-08-04 16:08:00 +00:00
2021-04-17 20:30:03 +00:00
# Makes an imported target if it doesn't exist. Useful for when find scripts from older versions of cmake don't make the targets you need
function ( make_imported_target_if_missing target lib )
if ( ${ lib } _FOUND AND NOT TARGET ${ target } )
add_library ( _ ${ lib } INTERFACE )
target_link_libraries ( _ ${ lib } INTERFACE "${${lib}_LIBRARIES}" )
target_include_directories ( _ ${ lib } INTERFACE "${${lib}_INCLUDE_DIRS}" )
add_library ( ${ target } ALIAS _ ${ lib } )
endif ( )
endfunction ( )
# like add_library(new ALIAS old) but avoids add_library cannot create ALIAS target "new" because target "old" is imported but not globally visible. on older cmake
function ( alias_library new old )
string ( REPLACE "::" "" library_no_namespace ${ old } )
2022-05-22 03:28:06 +00:00
if ( NOT TARGET _alias_ ${ library_no_namespace } )
add_library ( _alias_ ${ library_no_namespace } INTERFACE )
target_link_libraries ( _alias_ ${ library_no_namespace } INTERFACE ${ old } )
endif ( )
2021-04-17 20:30:03 +00:00
add_library ( ${ new } ALIAS _alias_ ${ library_no_namespace } )
endfunction ( )
2017-04-12 16:42:04 +00:00
# Helper macro to generate resources on linux (based on glib)
macro ( add_custom_glib_res out xml prefix )
2021-07-04 05:24:21 +00:00
set ( RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res" )
set ( RESOURCE_FILES "${ARGN}" )
# Note: trying to combine --generate-source and --generate-header doesn't work.
# It outputs whichever one comes last into the file named by the first
add_custom_command (
O U T P U T $ { o u t } . h
C O M M A N D g l i b - c o m p i l e - r e s o u r c e s - - s o u r c e d i r " $ { R E S O U R C E _ D I R } " - - g e n e r a t e - h e a d e r
- - c - n a m e $ { p r e f i x } " $ { R E S O U R C E _ D I R } / $ { x m l } " - - t a r g e t = $ { o u t } . h
D E P E N D S r e s / $ { x m l } $ { R E S O U R C E _ F I L E S } )
2017-04-12 16:42:04 +00:00
2021-07-04 05:24:21 +00:00
add_custom_command (
O U T P U T $ { o u t } . c p p
C O M M A N D g l i b - c o m p i l e - r e s o u r c e s - - s o u r c e d i r " $ { R E S O U R C E _ D I R } " - - g e n e r a t e - s o u r c e
- - c - n a m e $ { p r e f i x } " $ { R E S O U R C E _ D I R } / $ { x m l } " - - t a r g e t = $ { o u t } . c p p
D E P E N D S r e s / $ { x m l } $ { R E S O U R C E _ F I L E S } )
2017-04-12 16:42:04 +00:00
endmacro ( )
2021-05-07 22:35:36 +00:00
function ( source_groups_from_vcxproj_filters file )
file ( READ "${file}" filecontent )
get_filename_component ( parent "${file}" DIRECTORY )
if ( parent STREQUAL "" )
set ( parent "." )
endif ( )
set ( regex "<[^ ]+ Include=\" ( [^\ "]+)\" >[ \t\r\n]+<Filter>([^<]+)<\\/Filter>[ \t\r\n]+<\\/[^ >]+> " )
string ( REGEX MATCHALL "${regex}" filterstrings "${filecontent}" )
foreach ( filterstring IN LISTS filterstrings )
string ( REGEX REPLACE "${regex}" "\\1" path "${filterstring}" )
string ( REGEX REPLACE "${regex}" "\\2" group "${filterstring}" )
source_group ( "${group}" FILES "${parent}/${path}" )
endforeach ( )
endfunction ( )
2022-05-22 03:28:06 +00:00
function ( optional_system_library library )
string ( TOUPPER ${ library } upperlib )
set ( USE_SYSTEM_ ${ upperlib } "" CACHE STRING "Use system ${library} instead of bundled. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled, blank - Delegate to USE_SYSTEM_LIBS. Default is blank." )
if ( "${USE_SYSTEM_${upperlib}}" STREQUAL "" )
set ( RESOLVED_USE_SYSTEM_ ${ upperlib } ${ USE_SYSTEM_LIBS } PARENT_SCOPE )
else ( )
set ( RESOLVED_USE_SYSTEM_ ${ upperlib } ${ USE_SYSTEM_${upperlib } } PARENT_SCOPE )
endif ( )
endfunction ( )
function ( find_optional_system_library library bundled_path )
string ( TOUPPER ${ library } upperlib )
if ( RESOLVED_USE_SYSTEM_ ${ upperlib } )
find_package ( ${ library } ${ ARGN } QUIET )
if ( ( NOT ${ library } _FOUND ) AND ( NOT ${ RESOLVED_USE_SYSTEM_${upperlib } } STREQUAL "AUTO" ) )
find_package ( ${ library } ${ ARGN } ) # For the message
message ( FATAL_ERROR "No system ${library} was found. Please install it or set USE_SYSTEM_${upperlib} to AUTO." )
endif ( )
endif ( )
if ( ${ library } _FOUND )
message ( "Found ${library}: ${${library}_VERSION}" )
set ( ${ library } _TYPE "System" PARENT_SCOPE )
else ( )
if ( ${ RESOLVED_USE_SYSTEM_${upperlib } } STREQUAL "AUTO" )
message ( "No system ${library} was found. Using bundled." )
endif ( )
if ( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${bundled_path}/CMakeLists.txt" )
message ( FATAL_ERROR "No bundled ${library} was found. Did you forget to checkout submodules?" )
endif ( )
add_subdirectory ( ${ bundled_path } EXCLUDE_FROM_ALL )
set ( ${ library } _TYPE "Bundled" PARENT_SCOPE )
endif ( )
endfunction ( )
2022-05-25 21:43:11 +00:00
function ( fixup_file_properties target )
get_target_property ( SOURCES ${ target } SOURCES )
if ( APPLE )
foreach ( source IN LISTS SOURCES )
# Set the right file types for .inl files in Xcode
if ( "${source}" MATCHES "\\.(inl|h)$" )
set_source_files_properties ( "${source}" PROPERTIES XCODE_EXPLICIT_FILE_TYPE sourcecode.cpp.h )
endif ( )
# CMake makefile and ninja generators will attempt to share one PCH for both cpp and mm files
# That's not actually OK
if ( "${source}" MATCHES "\\.mm$" )
set_source_files_properties ( "${source}" PROPERTIES SKIP_PRECOMPILE_HEADERS ON )
endif ( )
endforeach ( )
endif ( )
endfunction ( )