diff --git a/CMakeLists.txt b/CMakeLists.txt index b7a8f918..6c6c3bb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,24 @@ set(CMAKE_CONFIGURATION_TYPES Debug Static Release ReleaseStatic) # we load the variables after calling project() # default to Debug if no configuration specified if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) + # the CACHE FORCE is necessary for this to work properly + set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type; one of: Debug Release Static ReleaseStatic" FORCE) endif() +# and save whether this is shared in a variable +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set(_SHARED TRUE) +elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release") + set(_SHARED TRUE) +endif() +if(WIN32) + if(NOT MSVC) + if(_SHARED) + message(FATAL_ERROR + "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.") + endif() + endif() +endif() + # and we need to set this up prior to project() too set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8") @@ -25,18 +41,6 @@ cfgcopy(CMAKE_SHARED_LINKER_FLAGS) cfgcopy(CMAKE_STATIC_LINKER_FLAGS) cfgcopy(CMAKE_EXE_LINKER_FLAGS) -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) - macro(append _var _val) set(${_var} "${${_var}} ${_val}") endmacro() @@ -122,3 +126,21 @@ append2(CMAKE_EXE_LINKER_FLAGS_STATIC CMAKE_EXE_LINKER_FLAGS_RUNTIMESTATIC " ${_PLATFORM_LIBS}") add_subdirectory("common") +add_subdirectory("${_OSDIR}") +if(_SHARED) + add_library(libui SHARED + $ + $ + ) + if(_SETVERSION) + set_target_properties(libui PROPERTIES + SOVERSION "${_VERSION}") + endif() +else() + _add_static(libui + $ + $ + ) +endif() +set_target_properties(libui PROPERTIES + OUTPUT_NAME ui) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ab960223..cc93822d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -12,5 +12,4 @@ add_library(libui-common OBJECT ) set_target_properties(libui-common PROPERTIES COMPILE_FLAGS "${_LIBUI_CFLAGS}" - LINK_FLAGS "${_LIBUI_LDFLAGS}" ) diff --git a/darwin/CMakeLists.txt b/darwin/CMakeLists.txt new file mode 100644 index 00000000..651a175e --- /dev/null +++ b/darwin/CMakeLists.txt @@ -0,0 +1,62 @@ +# 31 may 2016 + +include_directories(.. . ../common) + +add_library(libui-darwin OBJECT + alloc.m + area.m + areaevents.m + autolayout.m + box.m + button.m + checkbox.m + colorbutton.m + combobox.m + control.m + datetimepicker.m + debug.m + draw.m + drawtext.m + editablecombo.m + entry.m + fontbutton.m + group.m + label.m + main.m + map.m + menu.m + multilineentry.m + progressbar.m + radiobuttons.m + scrollview.m + separator.m + slider.m + spinbox.m + stddialogs.m + tab.m + text.m + util.m + window.m +) +set_target_properties(libui-darwin PROPERTIES + COMPILE_FLAGS "${_LIBUI_CFLAGS}" +) + +macro(_add_static _name) + add_library(${_name} STATIC "${ARGN}") + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/sharedhidden) + add_custom_command( + TARGET ${_name} POST_BUILD + COMMAND + ${CMAKE_AR} x $ + COMMAND + nm -m *.o | sed -E -n "'s/^[0-9a-f]* \\([A-Z_]+,[a-z_]+\\) external //p'" > ${_name}.lst + COMMAND + ld -exported_symbols_list ${_name}.lst -r *.o -o ../_combined_${_name}.o + COMMAND + rm $ + COMMAND + ${CMAKE_AR} rcs $ ../_combined_${_name}.o + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/sharedhidden + COMMENT "Removing hidden symbols") +endmacro()