From 2383e2b0f57ebad3eecab885d433341f2dbbfe20 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Fri, 5 Nov 2010 02:23:24 +0000 Subject: [PATCH] Improve the compiler flags for the cmake build system. -fPIC only needs to be specified for static libraries that are linked into shared libraries. cmake automatically uses -fPIC for shared libraries. Also ported several other needed compiler flags from the scons build. Set up the debug build, enabled with "-D CMAKE_BUILD_TYPE=Release", to work with wxWidgets debugging. Note that most users will want to use the release build to get a -O3 optimized build. This can be enabled by adding "-D CMAKE_BUILD_TYPE=Release". git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6344 8ced0084-cf51-0410-be5f-012b33b47a6e --- CMakeLists.txt | 38 +++++++++++++-------- Source/Core/AudioCommon/CMakeLists.txt | 3 ++ Source/Core/Common/CMakeLists.txt | 3 ++ Source/Core/DSPCore/CMakeLists.txt | 3 ++ Source/Core/DebuggerUICommon/CMakeLists.txt | 3 ++ Source/Core/VideoCommon/CMakeLists.txt | 3 ++ 6 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55f14e30bf..a7bf4464d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,24 +30,33 @@ endif() include(FindPkgConfig REQUIRED) # TODO: Make this optional or even implement our own package detection -# Various compile flags - TODO: Can these be simplified with a more general CMake variable? -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g") +# Various compile flags +add_definitions(-msse2 -Wall) # gcc uses some optimizations which might break stuff without this flag -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") +add_definitions(-fno-strict-aliasing) -add_definitions(-DFILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG(-fvisibility-inlines-hidden VISIBILITY_INLINES_HIDDEN) +if(VISIBILITY_INLINES_HIDDEN) + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden) +endif(VISIBILITY_INLINES_HIDDEN) -if(UNIX) - # UNIX needs -fPIC for shared libraries, TODO: Would -fpic be enough as well? - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") -endif(UNIX) +CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden VISIBILITY_HIDDEN) +if(VISIBILITY_HIDDEN) + add_definitions(-fvisibility=hidden) +endif(VISIBILITY_HIDDEN) + +add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) + +if(CMAKE_BUILD_TYPE STREQUAL Debug) + add_definitions(-D_DEBUG -ggdb) + set(wxWidgets_USE_DEBUG ON CACHE BOOL "Use wxWidgets Debugging") +endif(CMAKE_BUILD_TYPE STREQUAL Debug) + +if(CMAKE_BUILD_TYPE STREQUAL Release) + add_definitions(-fomit-frame-pointer) +endif(CMAKE_BUILD_TYPE STREQUAL Release) ######################################## # Dependency checking @@ -171,7 +180,6 @@ endif(XRANDR_FOUND) # include_directories(Source/PluginSpecs) include_directories(Externals) -include_directories(.) # config.h, TODO: Move to Source? Or just add the corresponding definitions to the compiler flags? include_directories(Source/Core/AudioCommon/Src) include_directories(Source/Core/Common/Src) include_directories(Source/Core/Core/Src) diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index da7a000ea2..237ebd6f4d 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -36,3 +36,6 @@ endif() add_library(audiocommon STATIC ${SRCS}) target_link_libraries(audiocommon ${LIBS}) +if(UNIX) + add_definitions(-fPIC) +endif(UNIX) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index e7aded6b8e..e573f32d05 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -40,3 +40,6 @@ if(WIN32) endif(WIN32) add_library(common STATIC ${SRCS}) +if(UNIX) + add_definitions(-fPIC) +endif(UNIX) diff --git a/Source/Core/DSPCore/CMakeLists.txt b/Source/Core/DSPCore/CMakeLists.txt index 8212a545dc..79a7c588e7 100644 --- a/Source/Core/DSPCore/CMakeLists.txt +++ b/Source/Core/DSPCore/CMakeLists.txt @@ -23,3 +23,6 @@ set(SRCS Src/assemble.cpp Src/Jit/DSPJitMisc.cpp) add_library(dspcore STATIC ${SRCS}) +if(UNIX) + add_definitions(-fPIC) +endif(UNIX) diff --git a/Source/Core/DebuggerUICommon/CMakeLists.txt b/Source/Core/DebuggerUICommon/CMakeLists.txt index a036501b73..45455c93b1 100644 --- a/Source/Core/DebuggerUICommon/CMakeLists.txt +++ b/Source/Core/DebuggerUICommon/CMakeLists.txt @@ -3,3 +3,6 @@ set(SRCS Src/CodeView.cpp Src/MemoryView.cpp) add_library(debugger_ui_util STATIC ${SRCS}) +if(UNIX) + add_definitions(-fPIC) +endif(UNIX) diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt index 7ebae97765..a52aff9493 100644 --- a/Source/Core/VideoCommon/CMakeLists.txt +++ b/Source/Core/VideoCommon/CMakeLists.txt @@ -39,3 +39,6 @@ if(OPENCL_FOUND) endif(OPENCL_FOUND) add_library(videocommon STATIC ${SRCS}) +if(UNIX) + add_definitions(-fPIC) +endif(UNIX)