Even more cmake work.

This commit is contained in:
Pietro Gagliardi 2016-05-30 14:32:05 -04:00
parent ee8b4f71c0
commit 308d0eca88
1 changed files with 64 additions and 16 deletions

View File

@ -2,22 +2,35 @@
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
project(libui) project(libui)
set(_NOSHARED FALSE)
if(WIN32)
if(NOT MSVC)
set(_NOSHARED TRUE)
endif()
endif()
macro(nosharedmingw _target)
add_custom_target(${_target}
COMMAND exit 1
COMMENT "Sorry, libui for Windows cannot be built as a DLL with MinGW. You will need to either build as a static library or build with MSVC.")
endmacro(nosharedmingw)
if(APPLE) if(APPLE)
set(_OSDIR darwin) set(_OSDIR darwin)
set(_OSSRCEXT m) set(_OSSRCEXT m)
set(_SETVERSION TRUE) set(_SETVERSION TRUE)
set(_VERSION "A") set(_VERSION "A")
set(_LIBUI_LDFLAGS "-framework Foundation -framework AppKit")
# always use our rpath # always use our rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# the / is required by some older versions of OS X # the / is required by some older versions of OS X
set(CMAKE_INSTALL_RPATH "@executable_path/") set(CMAKE_INSTALL_RPATH "@executable_path/")
set(CMAKE_MACOSX_RPATH TRUE) set(CMAKE_MACOSX_RPATH TRUE)
elseif(WINDOWS) elseif(WIN32)
set(_OSDIR windows) set(_OSDIR windows)
set(_OSSRCEXT cpp) set(_OSSRCEXT cpp)
set(_SETVERSION FALSE) set(_SETVERSION FALSE)
else(APPLE) else()
set(_OSDIR unix) set(_OSDIR unix)
set(_OSSRCEXT c) set(_OSSRCEXT c)
set(_SETVERSION TRUE) set(_SETVERSION TRUE)
@ -25,9 +38,9 @@ else(APPLE)
# always use our rpath # always use our rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif(APPLE) endif()
include_directories(. common ${_OSDIR} test) include_directories(. common ${_OSDIR})
file(GLOB SOURCES file(GLOB SOURCES
common/*.c common/*.c
${_OSDIR}/*.${_OSSRCEXT}) ${_OSDIR}/*.${_OSSRCEXT})
@ -39,28 +52,63 @@ macro(libui _name _mode _setver _exclude)
if(${_setver}) if(${_setver})
set_target_properties(${_name} PROPERTIES set_target_properties(${_name} PROPERTIES
SOVERSION ${_VERSION}) SOVERSION ${_VERSION})
endif(${_setver}) endif()
# omit libui-shared from default builds # omit libui-static from default builds
if(${_exclude}) if(${_exclude})
set_target_properties(${_name} PROPERTIES set_target_properties(${_name} PROPERTIES
EXCLUDE_FROM_ALL 1) EXCLUDE_FROM_ALL 1)
endif(${_exclude}) endif()
target_link_libraries(${_name} "-framework Foundation -framework AppKit") set_target_properties(${_name} PROPERTIES
endmacro(libui) LINK_FLAGS "${_LIBUI_LDFLAGS}")
endmacro()
libui(libui SHARED ${_SETVERSION} FALSE) libui(libui SHARED ${_SETVERSION} FALSE)
libui(libui-static STATIC FALSE TRUE) if(${_NOSHARED})
nosharedmingw(libui-static)
else()
libui(libui-static STATIC FALSE TRUE)
endif()
include_directories(test) include_directories(test)
file(GLOB TESTSOURCES test/*.c) file(GLOB TESTSOURCES test/*.c)
macro(test _name _libui) macro(executable_base _name _outname _libui _static)
add_executable(${_name} ${TESTSOURCES}) add_executable(${_name} ${XSRC})
set_target_properties(${_name} PROPERTIES set_target_properties(${_name} PROPERTIES
OUTPUT_NAME test OUTPUT_NAME ${_outname}
EXCLUDE_FROM_ALL 1) EXCLUDE_FROM_ALL 1)
target_link_libraries(${_name} ${_libui}) target_link_libraries(${_name} ${_libui})
endmacro(test) # be sure to include libui libraries in the output
if(${_static})
set_target_properties(${_name} PROPERTIES
LINK_FLAGS "${_LIBUI_LDFLAGS}")
endif()
endmacro()
test(tester libui) macro(executable _name _outname _dir)
test(tester-static libui-static) include_directories(${_dir})
file(GLOB XSRC ${_dir}/*.c ${_dir}/*.cpp)
executable_base(${_name} ${_outname} libui FALSE)
if(${_NOSHARED})
nosharedmingw(${_name}-static)
else()
executable_base(${_name}-static ${_outname} libui-static TRUE)
endif()
set(XSRC)
endmacro()
executable(tester test test)
executable(controlgallery controlgallery examples/controlgallery)
executable(histogram histogram examples/histogram)
executable(cpp-multithread cpp-multithread examples/cpp-multithread)
add_custom_target(examples
DEPENDS
controlgallery
histogram
cpp-multithread)
add_custom_target(examples-static
DEPENDS
controlgallery-static
histogram-static
cpp-multithread-static)