From 7d7ab70279df554959eec29ff43a2eb304a3d578 Mon Sep 17 00:00:00 2001 From: Johannes Ekberg Date: Wed, 24 Dec 2014 10:34:25 +0100 Subject: Generic PLATFORM_LIBRARIES var This both reduces redundancy in add_executable definitions, and makes it easier to link additional libraries. In particular, extra libraries are needed on OSX - see next commit. --- CMakeLists.txt | 6 ++++++ src/citra/CMakeLists.txt | 12 +----------- src/citra_qt/CMakeLists.txt | 9 +-------- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 884520ce..36b9344e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,8 +108,14 @@ endif() IF (APPLE) # CoreFoundation is required only on OSX FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation) + SET(PLATFORM_LIBRARIES iconv ${COREFOUNDATION_LIBRARY}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") +ELSEIF(WIN32) + set(PLATFORM_LIBRARIES winmm) +ELSE() + set(PLATFORM_LIBRARIES rt) ENDIF (APPLE) option(ENABLE_QT "Enable the Qt frontend" ON) diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index bbb3374f..7f3ab3e0 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt @@ -16,20 +16,10 @@ create_directory_groups(${SRCS} ${HEADERS}) add_executable(citra ${SRCS} ${HEADERS}) target_link_libraries(citra core common video_core) target_link_libraries(citra ${GLFW_LIBRARIES} ${OPENGL_gl_LIBRARY} inih) +target_link_libraries(citra ${PLATFORM_LIBRARIES}) if (UNIX) target_link_libraries(citra -pthread) endif() -if (APPLE) - target_link_libraries(citra iconv ${COREFOUNDATION_LIBRARY}) -elseif (WIN32) - target_link_libraries(citra winmm wsock32 ws2_32) - if (MINGW) # GCC does not support codecvt, so use iconv instead - target_link_libraries(citra iconv) - endif() -else() # Unix - target_link_libraries(citra rt) -endif() - #install(TARGETS citra RUNTIME DESTINATION ${bindir}) diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index a0ba252b..420bede1 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -60,17 +60,10 @@ endif() add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS}) target_link_libraries(citra-qt core common video_core qhexedit) target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) +target_link_libraries(citra-qt ${PLATFORM_LIBRARIES}) if (UNIX) target_link_libraries(citra-qt -pthread) endif() -if (APPLE) - target_link_libraries(citra-qt iconv ${COREFOUNDATION_LIBRARY}) -elseif (WIN32) - target_link_libraries(citra-qt winmm wsock32 ws2_32) -else() # Unix - target_link_libraries(citra-qt rt) -endif() - #install(TARGETS citra-qt RUNTIME DESTINATION ${bindir}) -- cgit v1.2.3 From 13518198109fad9f19cc81aa1d06c3d85d1126f5 Mon Sep 17 00:00:00 2001 From: Johannes Ekberg Date: Wed, 24 Dec 2014 10:40:26 +0100 Subject: Link Cocoa, IOKit and CoreVideo on OSX These are implicitly linked by Xcode, but with this, you can also build it with any other generator, which does not have this behavior. CoreFoundation is included as a part of Cocoa (which is an umbrella framework), and Cocoa is generally recommended to link against, rather than its individual components (CoreFoundation, Foundation, libobjc, ...). --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36b9344e..c6423909 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,9 +106,10 @@ if (ENABLE_GLFW) endif() IF (APPLE) - # CoreFoundation is required only on OSX - FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation) - SET(PLATFORM_LIBRARIES iconv ${COREFOUNDATION_LIBRARY}) + FIND_LIBRARY(COCOA_LIBRARY Cocoa) # Umbrella framework for everything GUI-related + FIND_LIBRARY(IOKIT_LIBRARY IOKit) # GLFW dependency + FIND_LIBRARY(COREVIDEO_LIBRARY CoreVideo) # GLFW dependency + set(PLATFORM_LIBRARIES iconv ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") -- cgit v1.2.3 From d7ad14ae2088789a853d36fb3a465a920c0116ee Mon Sep 17 00:00:00 2001 From: Johannes Ekberg Date: Thu, 25 Dec 2014 11:49:00 +0100 Subject: Use -pthread where and only where needed Passing -pthread to GCC as a flag makes it both link to libpthread, and make C standard library routines reentrant. This makes the additional explicit links unnecessary. Additionally, on OSX, this is the default behavior, and clang will print a message about it being unused if it's present there. --- CMakeLists.txt | 6 +++++- src/citra/CMakeLists.txt | 4 ---- src/citra_qt/CMakeLists.txt | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6423909..81a793dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,11 @@ project(citra) if (NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes") - add_definitions(-pthread) + + if (NOT APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") + endif() else() # Silence deprecation warnings add_definitions(/D_CRT_SECURE_NO_WARNINGS) diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index 7f3ab3e0..713f4919 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt @@ -18,8 +18,4 @@ target_link_libraries(citra core common video_core) target_link_libraries(citra ${GLFW_LIBRARIES} ${OPENGL_gl_LIBRARY} inih) target_link_libraries(citra ${PLATFORM_LIBRARIES}) -if (UNIX) - target_link_libraries(citra -pthread) -endif() - #install(TARGETS citra RUNTIME DESTINATION ${bindir}) diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 420bede1..bbc521f8 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -62,8 +62,4 @@ target_link_libraries(citra-qt core common video_core qhexedit) target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) target_link_libraries(citra-qt ${PLATFORM_LIBRARIES}) -if (UNIX) - target_link_libraries(citra-qt -pthread) -endif() - #install(TARGETS citra-qt RUNTIME DESTINATION ${bindir}) -- cgit v1.2.3 From b027f7fe1537c9437f43782c6aa0bc6c98649831 Mon Sep 17 00:00:00 2001 From: Johannes Ekberg Date: Sat, 27 Dec 2014 00:19:18 +0100 Subject: Looks like that might be needed on OSX after all --- CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81a793dc..d9fc9c8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,12 +5,8 @@ cmake_minimum_required(VERSION 2.8.11) project(citra) if (NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes") - - if (NOT APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") - endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-attributes -pthread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") else() # Silence deprecation warnings add_definitions(/D_CRT_SECURE_NO_WARNINGS) -- cgit v1.2.3