2010-01-21 15:12:50 +00:00
#-------------------------------------------------------------------------------
# detectOperatingSystem
#-------------------------------------------------------------------------------
# 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 )
2014-12-28 06:41:57 +00:00
if ( WIN32 )
set ( Windows TRUE PARENT_SCOPE )
elseif ( UNIX AND APPLE )
# No easy way to filter out iOS.
message ( WARNING "OS X/iOS isn't supported, the build will most likely fail" )
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 ( )
2014-08-30 21:36:29 +00:00
endif ( )
2014-12-28 06:41:57 +00:00
elseif ( CMAKE_SYSTEM_NAME MATCHES "kFreeBSD" )
set ( kFreeBSD TRUE PARENT_SCOPE )
elseif ( CMAKE_SYSTEM_NAME STREQUAL "GNU" )
set ( GNU TRUE PARENT_SCOPE )
2013-01-02 13:34:38 +00:00
endif ( )
2014-12-28 06:41:57 +00:00
endif ( )
endfunction ( )
2013-06-28 10:43:50 +00:00
function ( write_svnrev_h )
2014-09-10 12:19:50 +00:00
set ( PCSX2_WC_TIME 0 )
2016-11-08 21:44:39 +00:00
set ( PCSX2_GIT_REV "" )
2015-01-07 02:14:10 +00:00
if ( GIT_FOUND AND EXISTS ${ PROJECT_SOURCE_DIR } /.git )
2014-08-04 16:08:00 +00:00
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
2014-03-25 16:29:47 +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 )
2014-08-04 16:08:00 +00:00
# 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
2018-01-10 02:17:15 +00:00
EXECUTE_PROCESS ( WORKING_DIRECTORY ${ PROJECT_SOURCE_DIR } COMMAND ${ GIT_EXECUTABLE } describe --always
2016-11-08 21:44:39 +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
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 )
2014-09-10 12:19:50 +00:00
endif ( )
if ( "${PCSX2_WC_TIME}" STREQUAL "" )
2014-08-04 16:08:00 +00:00
set ( PCSX2_WC_TIME 0 )
2013-06-28 10:43:50 +00:00
endif ( )
2016-11-08 21:44:39 +00:00
file ( WRITE ${ CMAKE_BINARY_DIR } /common/include/svnrev.h "#define SVN_REV ${PCSX2_WC_TIME}ll \n#define SVN_MODS 0\n#define GIT_REV \" ${ PCSX2_GIT_REV } \"")
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 )
2014-12-28 09:05:22 +00:00
if ( CMAKE_COMPILER_IS_GNUCXX )
2013-07-06 09:42:46 +00:00
execute_process ( COMMAND ${ CMAKE_C_COMPILER } -dumpversion OUTPUT_VARIABLE GCC_VERSION )
string ( STRIP "${GCC_VERSION}" GCC_VERSION )
if ( GCC_VERSION VERSION_LESS ${ version_err } )
2014-12-28 09:05:22 +00:00
message ( FATAL_ERROR " PCSX2 doesn't support your old GCC ${ GCC_VERSION } ! Please upgrade it!
2016-11-08 21:44:39 +00:00
2014-12-28 09:05:22 +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 " )
2013-07-06 09:42:46 +00:00
else ( )
if ( GCC_VERSION VERSION_LESS ${ version_warn } )
2014-12-28 09:05:22 +00:00
message ( WARNING "PCSX2 will stop supporting GCC ${GCC_VERSION} in the near future. Please upgrade to at least GCC ${version_warn}." )
2013-07-06 09:42:46 +00:00
endif ( )
endif ( )
2017-05-11 21:14:06 +00:00
set ( GCC_VERSION "${GCC_VERSION}" PARENT_SCOPE )
2013-07-06 09:42:46 +00:00
endif ( )
endfunction ( )
2014-03-30 14:25:11 +00:00
function ( check_no_parenthesis_in_path )
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 ( )
endfunction ( )
2014-08-04 16:08:00 +00:00
#NOTE: this macro is used to get rid of whitespace and newlines.
macro ( append_flags target flags )
if ( flags STREQUAL "" )
set ( flags " " ) # set to space to avoid error
endif ( )
get_target_property ( TEMP ${ target } COMPILE_FLAGS )
if ( TEMP STREQUAL "TEMP-NOTFOUND" )
set ( TEMP "" ) # set to empty string
else ( )
set ( TEMP "${TEMP} " ) # a space to cleanly separate from existing content
endif ( )
# append our values
set ( TEMP "${TEMP}${flags}" )
# fix arg list
set ( TEMP2 "" )
foreach ( _arg ${ TEMP } )
set ( TEMP2 "${TEMP2} ${_arg}" )
endforeach ( )
set_target_properties ( ${ target } PROPERTIES COMPILE_FLAGS "${TEMP2}" )
endmacro ( append_flags )
macro ( add_pcsx2_plugin lib srcs libs flags )
include_directories ( . )
add_library ( ${ lib } MODULE ${ srcs } )
target_link_libraries ( ${ lib } ${ libs } )
append_flags ( ${ lib } "${flags}" )
if ( NOT USER_CMAKE_LD_FLAGS STREQUAL "" )
target_link_libraries ( ${ lib } "${USER_CMAKE_LD_FLAGS}" )
endif ( NOT USER_CMAKE_LD_FLAGS STREQUAL "" )
if ( PACKAGE_MODE )
install ( TARGETS ${ lib } DESTINATION ${ PLUGIN_DIR } )
else ( PACKAGE_MODE )
install ( TARGETS ${ lib } DESTINATION ${ CMAKE_SOURCE_DIR } /bin/plugins )
endif ( PACKAGE_MODE )
endmacro ( add_pcsx2_plugin )
macro ( add_pcsx2_lib lib srcs libs flags )
include_directories ( . )
add_library ( ${ lib } STATIC ${ srcs } )
target_link_libraries ( ${ lib } ${ libs } )
append_flags ( ${ lib } "${flags}" )
if ( NOT USER_CMAKE_LD_FLAGS STREQUAL "" )
target_link_libraries ( ${ lib } "${USER_CMAKE_LD_FLAGS}" )
endif ( NOT USER_CMAKE_LD_FLAGS STREQUAL "" )
endmacro ( add_pcsx2_lib )
macro ( add_pcsx2_executable exe srcs libs flags )
add_definitions ( ${ flags } )
include_directories ( . )
add_executable ( ${ exe } ${ srcs } )
target_link_libraries ( ${ exe } ${ libs } )
append_flags ( ${ exe } "${flags}" )
if ( NOT USER_CMAKE_LD_FLAGS STREQUAL "" )
2015-07-24 17:24:40 +00:00
target_link_libraries ( ${ exe } "${USER_CMAKE_LD_FLAGS}" )
2014-08-04 16:08:00 +00:00
endif ( NOT USER_CMAKE_LD_FLAGS STREQUAL "" )
if ( PACKAGE_MODE )
2014-09-27 18:26:42 +00:00
install ( TARGETS ${ exe } DESTINATION ${ BIN_DIR } )
2014-08-04 16:08:00 +00:00
else ( PACKAGE_MODE )
install ( TARGETS ${ exe } DESTINATION ${ CMAKE_SOURCE_DIR } /bin )
endif ( PACKAGE_MODE )
endmacro ( add_pcsx2_executable )
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 )
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 } )
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 } )
endmacro ( )