Fixed static builds, added GTK+ builds, and cleaned out things in general for cmake.

This commit is contained in:
Pietro Gagliardi 2016-06-01 20:21:10 -04:00
parent 7bdeefedeb
commit e4a66b786e
4 changed files with 101 additions and 30 deletions

View File

@ -30,8 +30,10 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8")
project(libui)
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/out")
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/out")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out")
# now that we called project(), load our config variables
macro(cfgcopy _prefix)
@ -58,7 +60,8 @@ if(APPLE)
set(_VERSION "A")
set(_PLATFORM_LIBS
"-lobjc -framework Foundation -framework AppKit")
-lobjc "-framework Foundation" "-framework AppKit"
)
# always use our rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
@ -71,26 +74,22 @@ elseif(WIN32)
# note that usp10 comes before gdi32
# TODO prune this list
set(_PLATFORM_LIBS_BASE
user32 kernel32 usp10 gdi32 comctl32 uxtheme msimg32 comdlg32 d2d1 dwrite ole32 oleaut32 oleacc uuid)
if(MSVC)
string(REPLACE ";" ".lib " _PLATFORM_LIBS "${_PLATFORM_LIBS_BASE}")
set(_PLATFORM_LIBS "${_PLATFORM_LIBS}.lib")
else()
string(REPLACE ";" " -l" _PLATFORM_LIBS "${_PLATFORM_LIBS_BASE}")
set(_PLATFORM_LIBS "-l${_PLATFORM_LIBS}")
endif()
set(_PLATFORM_LIBS
user32 kernel32 usp10 gdi32 comctl32 uxtheme msimg32 comdlg32 d2d1 dwrite ole32 oleaut32 oleacc uuid
)
else()
set(_OSDIR unix)
set(_SETVERSION TRUE)
set(_VERSION "0")
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED gtk+-3.0)
set(_LIBUI_CFLAGS "${GTK_CFLAGS}")
string(REPLACE ";" " " _LIBUI_CFLAGS "${GTK_CFLAGS}")
set(_PLATFORM_LIBS "${GTK_LDFLAGS} -lm -ldl")
# always use our rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
endif()
if(MSVC)
@ -120,11 +119,6 @@ else()
# don't amend CMAKE_STATIC_LINKER_FLAGS; that's for ar
endif()
# and add the platform libraries to the three places that need it: shared library links and the two static executable links
append(CMAKE_SHARED_LINKER_FLAGS " ${_PLATFORM_LIBS}")
append2(CMAKE_EXE_LINKER_FLAGS_STATIC CMAKE_EXE_LINKER_FLAGS_RUNTIMESTATIC
" ${_PLATFORM_LIBS}")
add_subdirectory("common")
add_subdirectory("${_OSDIR}")
if(_SHARED)
@ -136,6 +130,7 @@ if(_SHARED)
set_target_properties(libui PROPERTIES
SOVERSION "${_VERSION}")
endif()
target_link_libraries(libui PRIVATE ${_PLATFORM_LIBS})
else()
_add_static(libui
$<TARGET_OBJECTS:libui-common>
@ -150,6 +145,9 @@ macro(_add_exec _name)
WIN32 EXCLUDE_FROM_ALL
${ARGN})
target_link_libraries(${_name} libui)
if(NOT _SHARED)
target_link_libraries(${_name} ${_PLATFORM_LIBS})
endif()
endmacro()
add_subdirectory("test")

View File

@ -42,21 +42,26 @@ set_target_properties(libui-darwin PROPERTIES
COMPILE_FLAGS "${_LIBUI_CFLAGS}"
)
# thanks to Mr-Hide in irc.freenode.net/#cmake
macro(_add_static _name)
add_library(${_name} STATIC "${ARGN}")
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/sharedhidden)
add_library(${_name}-temporary STATIC "${ARGN}")
set_target_properties(${_name}-temporary PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(_aname $<TARGET_FILE:${_name}-temporary>)
set(_lname ${_name}-combined.list)
set(_oname ${_name}-combined.o)
add_custom_command(
TARGET ${_name} POST_BUILD
OUTPUT ${_oname}
COMMAND
${CMAKE_AR} x $<TARGET_FILE:${_name}>
nm -m ${_aname} | sed -E -n "'s/^[0-9a-f]* \\([A-Z_]+,[a-z_]+\\) external //p'" > ${_lname}
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 $<TARGET_FILE:${_name}>
COMMAND
${CMAKE_AR} rcs $<TARGET_FILE:${_name}> ../_combined_${_name}.o
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/sharedhidden
ld -exported_symbols_list ${_lname} -r -all_load ${_aname} -o ${_oname}
COMMENT "Removing hidden symbols")
add_library(${_name} STATIC ${_oname})
# otherwise cmake won't know which linker to use
set_target_properties(${_name} PROPERTIES
LINKER_LANGUAGE C)
set(_aname)
set(_lname)
set(_oname)
endmacro()

View File

@ -5,12 +5,15 @@ include_directories(..)
_add_exec(controlgallery
controlgallery/main.c
)
_add_exec(histogram
histogram/main.c
)
_add_exec(cpp-multithread
cpp-multithread/main.cpp
)
target_link_libraries(cpp-multithread pthread)
add_custom_target(examples
DEPENDS

65
unix/CMakeLists.txt Normal file
View File

@ -0,0 +1,65 @@
# 1 june 2016
include_directories(.. . ../common)
add_library(libui-unix OBJECT
alloc.c
area.c
box.c
button.c
checkbox.c
child.c
colorbutton.c
combobox.c
control.c
datetimepicker.c
debug.c
draw.c
drawmatrix.c
drawpath.c
drawtext.c
editablecombo.c
entry.c
fontbutton.c
graphemes.c
group.c
label.c
main.c
menu.c
multilineentry.c
progressbar.c
radiobuttons.c
separator.c
slider.c
spinbox.c
stddialogs.c
tab.c
text.c
util.c
window.c
)
set_target_properties(libui-unix PROPERTIES
COMPILE_FLAGS "${_LIBUI_CFLAGS}"
)
# thanks to Mr-Hide in irc.freenode.net/#cmake
macro(_add_static _name)
add_library(${_name}-temporary STATIC "${ARGN}")
set_target_properties(${_name}-temporary PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(_aname $<TARGET_FILE:${_name}-temporary>)
set(_oname ${_name}-combined.o)
add_custom_command(
OUTPUT ${_oname}
COMMAND
ld -r --whole-archive ${_aname} -o ${_oname}
COMMAND
objcopy --localize-hidden ${_oname}
COMMENT "Removing hidden symbols")
add_library(${_name} STATIC ${_oname})
# otherwise cmake won't know which linker to use
set_target_properties(${_name} PROPERTIES
LINKER_LANGUAGE C)
set(_aname)
set(_oname)
endmacro()