Working great for me. I particularly like:
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR “Prevented in-tree built. This is bad practice.”)
endif()
Yes, so complete agree~
Couple of other comments:
-
Similarly to lowercase syntax, preferred end*() syntax is no
expression in the closing block. It just make maintaining files easier
(if you have if(XXX && YYY) and endif(XXX && YYY) you have to make two
changes every time you touch the statement; ending with endif() is
better unless you have nasty un-nested if statements with no
indentation).
-
As one of the irritating things about cmake UNIX matches for osx,
so you probably want to put your blocks either as:
if(APPLE)
…
elseif(UNIX)
…
endif()
or
if(UNIX AND NOT APPLE)
…
endif()
- Also seems you missed the file/cocoa .m files, and the frameworks
to link against.
Patch attached.~
Doug.
On Sat, Aug 18, 2012 at 9:14 PM, Marcus von Appen wrote:
Dear all,
an updated version of the CMake-based build system is available, which
adresses the following issues:
- proper -m machine flag handling for LLVM/CLang compilers
- use libtool-like library versioning
- X11 vidmode and screensaver detection works properly now
- fixed DirectFB detection
- fixed FusionSound detection
- use lower-case directives as suggested by Doug
- [untested] basic installation support
Known issues:
- configure/autotools internally use several defaults that can vary
depending on platforms. Their usefulness will be evaluated and take
into consideration later on
- dlopen options might behave differently from configure - I could not
find out the intended logic from the configure script (see the TODO
in CMakeLists.txt)
- mprotect check might not work as supposed
[- different option scenarios were not thoroughly tested yet]
- SDL2.pc, SDL2.spec and sdl-config might contain errors
You can find the patch at
http://www.sysfault.org/tmp/cmake_20120818.diff
Cheers
Marcus
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-------------- next part --------------
— CMakeLists.txt 2012-08-20 10:04:21.000000000 +0800
+++ …/CMakeLists.txt 2012-08-20 10:03:32.000000000 +0800
@@ -64,7 +64,7 @@
# TODO: validate this
set(WINDOWS_CE TRUE)
endif()
-elseif(UNIX)
+elseif(UNIX AND NOT APPLE)
if(CMAKE_SYSTEM_NAME MATCHES “.Linux")
set(LINUX TRUE)
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.”)
@@ -150,6 +150,13 @@
option(${_OPT} “Enable the ${_SUB} subsystem” ON)
endforeach()
+# Don’t mistake osx for unix
+if (UNIX AND NOT APPLE)
- set(UNIX_SYS ON)
+else()
- set(UNIX_SYS OFF)
+endif()
-
option_string(ASSERTIONS “Enable internal sanity checks (auto/disabled/release/enabled/paranoid)” “auto”)
set_option(DEPENDENCY_TRACKING “Use gcc -MMD -MT dependency tracking” ON)
set_option(LIBC “Use the system C library” ON)
@@ -170,24 +177,24 @@
set_option(VIDEO_DUMMY “Use dummy video driver” ON)
set_option(VIDEO_OPENGL “Include OpenGL support” ON)
set_option(VIDEO_OPENGLES “Include OpenGL ES support” ON)
-set_option(PTHREADS “Use POSIX threads for multi-threading” ${UNIX})
+set_option(PTHREADS “Use POSIX threads for multi-threading” ${UNIX_SYS})
dep_option(PTHREADS_SEM “Use pthread semaphores” ON “PTHREADS” OFF)
set_option(SDL_DLOPEN “Use dlopen for shared object loading” ON)
-set_option(OSS “Support the OSS audio API” ${UNIX})
-set_option(ALSA “Support the ALSA audio API” ${UNIX})
+set_option(OSS “Support the OSS audio API” ${UNIX_SYS})
+set_option(ALSA “Support the ALSA audio API” ${UNIX_SYS})
dep_option(ALSA_SHARED “Dynamically load ALSA audio support” ON “ALSA” OFF)
-set_option(ESD “Support the Enlightened Sound Daemon” ${UNIX})
+set_option(ESD “Support the Enlightened Sound Daemon” ${UNIX_SYS})
dep_option(ESD_SHARED “Dynamically load ESD audio support” ON “ESD” OFF)
-set_option(PULSEAUDIO “Use PulseAudio” ${UNIX})
+set_option(PULSEAUDIO “Use PulseAudio” ${UNIX_SYS})
dep_option(PULSEAUDIO_SHARED “Dynamically load PulseAudio support” ON “PULSEAUDIO” OFF)
-set_option(ARTS “Support the Analog Real Time Synthesizer” ${UNIX})
+set_option(ARTS “Support the Analog Real Time Synthesizer” ${UNIX_SYS})
dep_option(ARTS_SHARED “Dynamically load aRts audio support” ON “ARTS” OFF)
-set_option(NAS “Support the NAS audio API” ${UNIX})
-set_option(RPATH “Use an rpath when linking SDL” ${UNIX})
+set_option(NAS “Support the NAS audio API” ${UNIX_SYS})
+set_option(RPATH “Use an rpath when linking SDL” ${UNIX_SYS})
set_option(CLOCK_GETTIME “Use clock_gettime() instead of gettimeofday()” OFF)
-set_option(INPUT_EVENTS “Use Linux 2.4 unified input interface” ${UNIX})
-set_option(INPUT_TSLIB “Use the Touchscreen library for input” ${UNIX})
-set_option(VIDEO_X11 “Use X11 video driver” ${UNIX})
+set_option(INPUT_EVENTS “Use Linux 2.4 unified input interface” ${UNIX_SYS})
+set_option(INPUT_TSLIB “Use the Touchscreen library for input” ${UNIX_SYS})
+set_option(VIDEO_X11 “Use X11 video driver” ${UNIX_SYS})
dep_option(X11_SHARED “Dynamically load X11 support” ON “VIDEO_X11” OFF)
set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
foreach(_SUB ${SDL_X11_OPTIONS})
@@ -523,7 +530,7 @@
endif(VIDEO)
Platform-specific options and settings
-if(UNIX)
+if(UNIX AND NOT APPLE)
if(AUDIO)
if(SYSV5 OR SOLARIS OR HPUX)
set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
@@ -812,6 +819,24 @@
endif(MINGW OR CYGWIN)
endif(HAVE_WINCE)
elseif(APPLE)
+
-
Apple frameworks
- include_directories(/System/Library/Frameworks)
- find_library(CARBON_LIBRARY Carbon)
- find_library(FORCEFEEDBACK ForceFeedback)
- find_library(COCOA_LIBRARY Cocoa)
- find_library(OpenGL_LIBRARY OpenGL)
- find_library(COREAUDIO CoreAudio)
- find_library(AUDIOUNIT AudioUnit)
- find_library(AUDIOTOOLBOX AudioToolbox)
- find_library(IOKIT IOKit)
- set(EXTRA_LIBS ${CARBON_LIBRARY} ${COCOA_LIBRARY} ${OpenGL_LIBRARY} ${COREAUDIO} ${AUDIOUNIT} ${AUDIOTOOLBOX} ${IOKIT})
-
-
Cocoa file support
- file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
- set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
- set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
-
if(VIDEO)
CheckCOCOA()