-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake and CPack integration (removing Python dependency in the process) #462
base: master
Are you sure you want to change the base?
Changes from 5 commits
8d7b682
ec222c2
0761cfc
ac7e89a
2396b67
9b01b89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ docs/src | |
*.swo | ||
*.swp | ||
/private/ | ||
*build* | ||
.idea | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,105 @@ | ||||||
cmake_minimum_required(VERSION 3.15) | ||||||
|
||||||
project(Nuklear VERSION 0.0.1 LANGUAGES C) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be made the primary place for the version? |
||||||
|
||||||
#===============# | ||||||
# 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:-Wall;-Wextra;-pedantic;-Wno-misleading-indentation;-Wno-shift-negative-value;-O2>>" | ||||||
"$<${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") | ||||||
option(BUILD_DEMOS "Build demos" "ON") | ||||||
option(BUILD_EXAMPLES "Build examples" "ON") | ||||||
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could have the BUILD_DEMOS and BUILD_EXAMPLES options enabled only if the user is using CMake from root. That wasy it'll only build them if you're building locally rather than as a third-party dependdency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be accomplished with... # Options
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(NUKLEAR_IS_MAIN TRUE)
else()
set(NUKLEAR_IS_MAIN FALSE)
endif()
option(BUILD_DEMOS "Build demos" ${NUKLEAR_IS_MAIN})
option(BUILD_EXAMPLES "Examples" ${NUKLEAR_IS_MAIN}) |
||||||
|
||||||
add_subdirectory("src") | ||||||
if (BUILD_DEMOS) | ||||||
add_subdirectory("demo") | ||||||
endif (BUILD_DEMOS) | ||||||
if (BUILD_EXAMPLES) | ||||||
add_subdirectory("example") | ||||||
endif (BUILD_EXAMPLES) | ||||||
|
||||||
include(CTest) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to conditionally include |
||||||
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" | ||||||
SamuelMarks marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
@PACKAGE_INIT@ | ||
|
||
include ( "${CMAKE_CURRENT_LIST_DIR}/nuklearTargets.cmake" ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include("release/CPackConfig.cmake") | ||
|
||
set(CPACK_INSTALL_CMAKE_PROJECTS | ||
"debug;nuklear;ALL;/" | ||
"release;nuklear;ALL;/" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
RobLoach marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This installs nuklear. | ||
RobLoach marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# | ||
# - Find math | ||
# Find the native M includes and library | ||
# | ||
# M_INCLUDE_DIRS - where to find math.h, etc. | ||
# M_LIBRARIES - List of libraries when using math. | ||
# M_FOUND - True if math found. | ||
|
||
|
||
IF (M_INCLUDE_DIRS) | ||
# Already in cache, be silent | ||
SET(M_FIND_QUIETLY TRUE) | ||
ENDIF (M_INCLUDE_DIRS) | ||
|
||
# | ||
# On OS X, make sure we do *NOT* find math.h in the Kernel framework, | ||
# as that will convince CMake to cause the build to look there for | ||
# headers. | ||
# | ||
# For some unknown reason, on Yosemite, math.h is included in the Kernel | ||
# framework. That framework exists to supply headers for building | ||
# *kernel* modules; it includes versions of C headers that are similar | ||
# to the standard userland headers, but not similar enough to be usable | ||
# when building userland code. | ||
# | ||
# Unless told not to look first in the framework paths, CMake will, on | ||
# Yosemite, or when using the Yosemite SDK, find math.h in the Kernel | ||
# framework, and add the header directory for the Kernel framework to | ||
# the list of places to look for headers, causing it to pick up other | ||
# headers from there as well. This causes the build to fail. | ||
# | ||
SET(SAVED_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) | ||
SET(CMAKE_FIND_FRAMEWORK LAST) | ||
FIND_PATH(M_INCLUDE_DIR math.h) | ||
SET(CMAKE_FIND_FRAMEWORK ${SAVED_CMAKE_FIND_FRAMEWORK}) | ||
|
||
SET(M_NAMES m) | ||
FIND_LIBRARY(M_LIBRARY NAMES ${M_NAMES} ) | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set M_FOUND to TRUE if | ||
# all listed variables are TRUE | ||
INCLUDE(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(M DEFAULT_MSG M_LIBRARY M_INCLUDE_DIR) | ||
|
||
IF(M_FOUND) | ||
SET( M_LIBRARIES ${M_LIBRARY} ) | ||
SET( M_INCLUDE_DIRS ${M_INCLUDE_DIR} ) | ||
ELSE(M_FOUND) | ||
SET( M_LIBRARIES ) | ||
SET( M_INCLUDE_DIRS ) | ||
ENDIF(M_FOUND) | ||
|
||
MARK_AS_ADVANCED( M_LIBRARIES M_INCLUDE_DIRS ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
set(demos | ||
"allegro5" | ||
# "common" | ||
# "d3d11" | ||
# "d3d12" | ||
# "d3d9" | ||
# "gdi" | ||
Comment on lines
+2
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly have these as individual options defaulting to if the platform dependencies are found? |
||
# "gdip" | ||
# "glfw_opengl2" | ||
# "glfw_opengl3" | ||
# "glfw_opengl4" | ||
# "sdl2surface_rawfb" | ||
# "sdl_opengl2" | ||
# "sdl_opengl3" | ||
# "sdl_opengles2" | ||
# "sdl_renderer" | ||
# "sfml_opengl2" | ||
# "sfml_opengl3" | ||
# "wayland_rawfb" | ||
# "x11" | ||
# "x11_opengl2" | ||
# "x11_opengl3" | ||
# "x11_rawfb" | ||
# "x11_xft" | ||
) | ||
|
||
foreach (demo ${demos}) | ||
add_subdirectory("${demo}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CMakeLists.txt for all these demos are possibly going to be 90% the same, would it make sense to add a cmake function/macro like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contributions welcome There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you propose to do this, send a PR to your fork? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to bring the branch into the repository too, if that makes contributions easier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy either way |
||
endforeach (demo ${demos}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
################### | ||
# KeyboardHandler # | ||
################### | ||
#get_filename_component(LIBRARY_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) | ||
#set(LIBRARY_NAME "${PROJECT_NAME}_demo_${LIBRARY_NAME}") | ||
# | ||
#set(Header_Files "KeyboardHandleriOS.h") | ||
#source_group("Header Files" FILES "${Header_Files}") | ||
# | ||
#set(Source_Files "KeyboardHandleriOS.m") | ||
#source_group("Source Files" FILES "${Source_Files}") | ||
# | ||
#add_library("${LIBRARY_NAME}" "${Header_Files}" "${Source_Files}") | ||
#include(GNUInstallDirs) | ||
#target_include_directories( | ||
# "${LIBRARY_NAME}" | ||
# PUBLIC | ||
# "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" | ||
# "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" | ||
#) | ||
# | ||
#target_link_libraries( | ||
# "${LIBRARY_NAME}" | ||
# PRIVATE | ||
# "${PROJECT_NAME}_compiler_flags" | ||
#) | ||
# | ||
#set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) | ||
|
||
################# | ||
# allegro5 demo # | ||
################# | ||
|
||
get_filename_component(EXEC_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) | ||
set(EXEC_NAME "${PROJECT_NAME}_demo_${EXEC_NAME}") | ||
|
||
set(Header_Files "nuklear_allegro5.h") | ||
source_group("Header Files" FILES "${Header_Files}") | ||
|
||
set(Source_Files "main.c") | ||
source_group("Source Files" FILES "${Source_Files}") | ||
|
||
add_executable("${EXEC_NAME}" "${Header_Files}" "${Source_Files}") | ||
include(GNUInstallDirs) | ||
target_include_directories( | ||
"${EXEC_NAME}" | ||
PUBLIC | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" | ||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" | ||
) | ||
|
||
target_link_libraries( | ||
"${EXEC_NAME}" | ||
PRIVATE | ||
"${PROJECT_NAME}_compiler_flags" | ||
) | ||
|
||
find_package(unofficial-allegro5 CONFIG REQUIRED) | ||
target_link_libraries( | ||
"${EXEC_NAME}" | ||
PRIVATE | ||
"unofficial-allegro5::allegro" | ||
"unofficial-allegro5::allegro_ttf" | ||
"unofficial-allegro5::allegro_font" | ||
"unofficial-allegro5::allegro_main" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
set(_libs "file_browser" "extended" "canvas" "skinning") | ||
|
||
find_package(glfw3 CONFIG REQUIRED) | ||
find_package(GLEW REQUIRED) | ||
|
||
include(FindOpenGL) | ||
find_package(OpenGL REQUIRED) | ||
|
||
include("${CMAKE_SOURCE_DIR}/cmake/modules/CMakeFindM.cmake") | ||
|
||
set(deps "glfw" "GLEW::GLEW" "OpenGL::GL" "${M_LIBRARIES}") | ||
if (APPLE) | ||
#SET(GUI_TYPE MACOSX_BUNDLE) | ||
#INCLUDE_DIRECTORIES ( /Developer/Headers/FlatCarbon ) | ||
find_library(COCOA_LIBRARY Cocoa) | ||
find_library(COREVIDEO_LIBRARY CoreVideo) | ||
find_library(IOKIT_LIBRARY IOKit) | ||
mark_as_advanced(COCOA_LIBRARY COREVIDEO_LIBRARY IOKIT_LIBRARY) | ||
list(APPEND deps "${COCOA_LIBRARY}" "${COREVIDEO_LIBRARY}" "${IOKIT_LIBRARY}") | ||
# -L/usr/local/lib | ||
# -I/usr/local/include | ||
endif (APPLE) | ||
|
||
foreach (_lib ${_libs}) | ||
set(src "${_lib}.c") | ||
source_group("${_lib} Files" FILES "${src}") | ||
add_executable("${_lib}" "${src}") | ||
target_link_libraries("${_lib}" PRIVATE "${deps}") | ||
target_include_directories("${_lib}" PRIVATE "${M_INCLUDE_DIRS}") | ||
endforeach (_lib ${_libs}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ide specific folders should be in your global git config, not per project (that includes
.idea
,.vscode
, etc..)