CMake and CPack integration (removing Python dependency in the process)

This commit is contained in:
Samuel Marks 2022-05-24 18:24:05 -04:00
parent 0a77211844
commit 8d7b6822c4
No known key found for this signature in database
GPG Key ID: 43FD8EDE42E1A799
12 changed files with 365 additions and 0 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ docs/src
*.swo
*.swp
/private/
*build*
.idea

97
CMakeLists.txt Normal file
View File

@ -0,0 +1,97 @@
cmake_minimum_required(VERSION 3.15)
project(Nuklear VERSION 0.0.1 LANGUAGES C)
#===============#
# Compiler args #
#===============#
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
set(CMAKE_C_STANDARD 90)
add_library("${PROJECT_NAME}_compiler_flags" INTERFACE)
target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}")
# add compiler warning flags just when building this project via
# the BUILD_INTERFACE genex
set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
target_compile_options(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"$<${gcc_like}:$<BUILD_INTERFACE:-Wno-shadow;-Wformat=2;-Wall;-Wno-gcc-compat;-Wno-c99-extensions>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
)
# Set the build directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
#===========#
# Configure #
#===========#
# configure a header file to pass the version number only
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_NAME}Config.h"
)
#=============#
# Sub-targets #
#=============#
option(BUILD_HEADER_ONLY "Header only variant" "ON")
add_subdirectory("src")
include(CTest)
if (BUILD_TESTING)
#add_subdirectory("tests")
endif (BUILD_TESTING)
#=========#
# Install #
#=========#
include(GNUInstallDirs)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nuklear")
include(InstallRequiredSystemLibraries)
set(CPACK_BUNDLE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "Micha Mettke")
set(CPACK_PACKAGE_DESCRIPTION "A single-header ANSI C immediate mode cross-platform GUI library")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
if (APPLE)
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist")
set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CustomVolumeIcon.icns")
endif (APPLE)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/src/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/cmake/README.txt")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Welcome.txt")
set(CPACK_PACKAGE_CONTACT "https://github.com/Immediate-Mode-UI/Nuklear")
include(CPack)
include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/nuklear"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/nuklear")

BIN
cmake/BundleIcon.icns Normal file

Binary file not shown.

7
cmake/CTestConfig.cmake Normal file
View File

@ -0,0 +1,7 @@
set(CTEST_PROJECT_NAME "nuklear")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=nuklear")
set(CTEST_DROP_SITE_CDASH TRUE)

4
cmake/Config.cmake.in Normal file
View File

@ -0,0 +1,4 @@
@PACKAGE_INIT@
include ( "${CMAKE_CURRENT_LIST_DIR}/nuklearTargets.cmake" )

BIN
cmake/CustomVolumeIcon.icns Normal file

Binary file not shown.

14
cmake/Info.plist Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>BundleGeneratorTest</string>
<key>CFBundleIconFile</key>
<string>BundleGeneratorTest.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>

View File

@ -0,0 +1,6 @@
include("release/CPackConfig.cmake")
set(CPACK_INSTALL_CMAKE_PROJECTS
"debug;nuklear;ALL;/"
"release;nuklear;ALL;/"
)

7
cmake/README.txt Normal file
View File

@ -0,0 +1,7 @@
nuklear
Minimal state immediate mode graphical user interface toolkit written in ANSI C and licensed under public domain.
------------------------------------------------------------------------
Licensed under (Unlicense OR MIT)

1
cmake/Welcome.txt Normal file
View File

@ -0,0 +1 @@
This installs nuklear.

9
cmake/config.h.in Normal file
View File

@ -0,0 +1,9 @@
#ifndef NUKLEAR_CONFIG_H
#define NUKLEAR_CONFIG_H
#define NUKLEAR_VERSION_MAJOR @Nuklear_VERSION_MAJOR@
#define NUKLEAR_VERSION_MINOR @Nuklear_VERSION_MINOR@
#define NUKLEAR_VERSION_PATCH @Nuklear_VERSION_PATCH@
#define NUKLEAR_VERSION "@Nuklear_VERSION@"
#endif /* !NUKLEAR_CONFIG_H */

218
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,218 @@
set(LIBRARY_NAME "nuklear")
include(GNUInstallDirs)
if (NOT BUILD_HEADER_ONLY)
set(Header_Files
"nuklear.h"
"nuklear_internal.h"
"stb_rect_pack.h"
"stb_truetype.h"
)
source_group("Header Files" FILES "${Header_Files}")
set(Source_Files
"nuklear_9slice.c"
"nuklear_buffer.c"
"nuklear_button.c"
"nuklear_chart.c"
"nuklear_color.c"
"nuklear_color_picker.c"
"nuklear_combo.c"
"nuklear_context.c"
"nuklear_contextual.c"
"nuklear_draw.c"
"nuklear_edit.c"
"nuklear_font.c"
"nuklear_group.c"
"nuklear_image.c"
"nuklear_input.c"
"nuklear_layout.c"
"nuklear_list_view.c"
"nuklear_math.c"
"nuklear_menu.c"
"nuklear_page_element.c"
"nuklear_panel.c"
"nuklear_pool.c"
"nuklear_popup.c"
"nuklear_progress.c"
"nuklear_property.c"
"nuklear_scrollbar.c"
"nuklear_selectable.c"
"nuklear_slider.c"
"nuklear_string.c"
"nuklear_style.c"
"nuklear_table.c"
"nuklear_text.c"
"nuklear_text_editor.c"
"nuklear_toggle.c"
"nuklear_tooltip.c"
"nuklear_tree.c"
"nuklear_utf8.c"
"nuklear_util.c"
"nuklear_vertex.c"
"nuklear_widget.c"
"nuklear_window.c"
)
source_group("Source Files" FILES "${Source_Files}")
add_library("${LIBRARY_NAME}" "${Header_Files}" "${Source_Files}")
target_link_libraries("${LIBRARY_NAME}" PRIVATE "${PROJECT_NAME}_compiler_flags")
#include(GenerateExportHeader)
#set(_export_file "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h")
#generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}")
target_include_directories(
"${LIBRARY_NAME}"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
endif (NOT BUILD_HEADER_ONLY)
#=========#
# Install #
#=========#
if (NOT BUILD_HEADER_ONLY)
# setup the version numbering
set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}")
set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}")
install(FILES ${Header_Files} #"${_export_file}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/nuklear")
endif (NOT BUILD_HEADER_ONLY)
#============================#
# Amalgamation (header-only) #
#============================#
function (omit_includes new_file_contents file_contents blacklist)
set(_new_file_contents "${file_contents}")
foreach (omit ${blacklist})
string(REPLACE "#include \"${omit}\"" "" _new_file_contents "${_new_file_contents}")
string(REPLACE "#include <${omit}>" "" _new_file_contents "${_new_file_contents}")
endforeach (omit ${blacklist})
set(${new_file_contents} "${_new_file_contents}" PARENT_SCOPE)
endfunction (omit_includes new_file_contents file_contents blacklist)
if (BUILD_HEADER_ONLY)
set(macro "NK")
set(intro "HEADER")
set(pub "nuklear.h")
set(priv1
"nuklear_internal.h" "nuklear_math.c" "nuklear_util.c"
"nuklear_color.c" "nuklear_utf8.c" "nuklear_buffer.c"
"nuklear_string.c" "nuklear_draw.c" "nuklear_vertex.c")
set(extern "stb_rect_pack.h" "stb_truetype.h")
set(priv2
"nuklear_font.c" "nuklear_input.c" "nuklear_style.c"
"nuklear_context.c" "nuklear_pool.c" "nuklear_page_element.c"
"nuklear_table.c" "nuklear_panel.c" "nuklear_window.c"
"nuklear_popup.c" "nuklear_contextual.c" "nuklear_menu.c"
"nuklear_layout.c" "nuklear_tree.c" "nuklear_group.c"
"nuklear_list_view.c" "nuklear_widget.c" "nuklear_text.c"
"nuklear_image.c" "nuklear_9slice.c" "nuklear_button.c"
"nuklear_toggle.c" "nuklear_selectable.c" "nuklear_slider.c"
"nuklear_progress.c" "nuklear_scrollbar.c" "nuklear_text_editor.c"
"nuklear_edit.c" "nuklear_property.c" "nuklear_chart.c"
"nuklear_color_picker.c" "nuklear_combo.c" "nuklear_tooltip.c")
set(outro "LICENSE" "CHANGELOG" "CREDITS")
set(intro_contents "")
foreach (filename ${intro})
file(READ "${filename}" file_contents)
set(intro_contents "${file_contents}")
endforeach (filename ${intro})
set(pub_contents "")
foreach (filename ${pub})
file(READ "${filename}" file_contents)
set(pub_contents "${file_contents}")
endforeach (filename ${pub})
set(priv_blacklist ${pub} ${priv1} ${priv2} ${extern})
set(amalgam_contents "")
foreach (filename ${priv1})
file(READ "${filename}" file_contents)
omit_includes(new_file_contents
"${file_contents}"
"${priv_blacklist}"
)
string(APPEND amalgam_contents "${new_file_contents}")
endforeach (filename ${priv1})
foreach (filename ${extern})
# TODO: Replace C++ with C style comments
file(READ "${filename}" file_contents)
string(APPEND amalgam_contents "${file_contents}")
endforeach (filename ${extern})
foreach (filename ${priv2})
file(READ "${filename}" file_contents)
omit_includes(new_file_contents
"${file_contents}"
"${priv_blacklist}"
)
string(APPEND amalgam_contents "${new_file_contents}")
endforeach (filename ${priv1})
set(outro_contents "")
foreach (filename ${outro})
file(READ "${filename}" file_contents)
set(APPEND outro_contents "${file_contents}")
endforeach (filename ${outro})
set(macro "NK")
set(Header_Files "${CMAKE_SOURCE_DIR}/nuklear.h")
file(WRITE
"${Header_Files}"
"/*\n"
"${intro_contents}\n"
"*/\n"
"#ifndef ${macro}_SINGLE_HEADER\n"
"#define ${macro}_SINGLE_HEADER\n"
"${pub_contents}\n"
"#endif /* ${macro}_SINGLE_HEADER */\n\n"
"#ifdef ${macro}_IMPLEMENTATION\n"
"${amalgam_contents}"
"#endif /* ${macro}_IMPLEMENTATION */\n"
"/*\n"
"${outro_contents}\n"
"*/\n")
source_group("Header Files" FILES "${Header_Files}")
add_library("${LIBRARY_NAME}" INTERFACE "${Header_Files}")
target_link_libraries("${LIBRARY_NAME}" INTERFACE "${PROJECT_NAME}_compiler_flags")
install(FILES ${Header_Files}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBRARY_NAME}")
endif (BUILD_HEADER_ONLY)
#====================#
# Package to install #
#====================#
set(installable_libs "${LIBRARY_NAME}" "${PROJECT_NAME}_compiler_flags")
if (TARGET "${DEPENDANT_LIBRARY}")
list(APPEND installable_libs "${DEPENDANT_LIBRARY}")
endif ()
install(TARGETS ${installable_libs}
EXPORT "${LIBRARY_NAME}Targets"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}")