Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslg committed Feb 20, 2024
0 parents commit 0d9f803
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 0 deletions.
54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.20)

include(CMakePrintHelpers)

#
# Change default CMake options for convenience
#

# Change default build type
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type")

# Build .so by default
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libs")

# Build tests by default
set(BUILD_TESTING ON CACHE BOOL "Build tests")

# Build -fPIC by default (even static) by default
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Position independent code")

# Silent some install messages by default
set(CMAKE_INSTALL_MESSAGE "LAZY" CACHE STRING "")

# Add rpaths of external dependencies by default
if (NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) # not CACHE, only for our project
endif()

#
# Read the version from version.txt
#

file(READ "version.txt" version_txt)
string(REGEX REPLACE "^[ \t\n]+|[ \t\n]+$" "" version_txt "${version_txt}") # Strip

#
#
#

project(MachineTypes
LANGUAGES C
VERSION "${version_txt}"
DESCRIPTION "Simple C numeric types definitions")

cmake_print_variables(MachineTypes_VERSION)

# (after project() is important here:)
include(GNUInstallDirs)

# Global PRIVATE compilation flags
add_compile_options(-Wall -Wextra)

add_subdirectory(machinetypes)
add_subdirectory(cmake)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simple C numeric types definitions
20 changes: 20 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

include(CMakePackageConfigHelpers)

configure_package_config_file(MachineTypesConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/MachineTypesConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/MachineTypes/cmake)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/MachineTypesConfigVersion.cmake
COMPATIBILITY SameMinorVersion # AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion
VERSION "${MachineTypes_VERSION}")

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/MachineTypesConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/MachineTypesConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/MachineTypes/cmake)

install(EXPORT MachineTypesTargets
NAMESPACE MachineTypes::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/MachineTypes/cmake)
43 changes: 43 additions & 0 deletions cmake/MachineTypesConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

set(MachineTypes_VERSION "@MachineTypes_VERSION@")

@PACKAGE_INIT@

#
# Expose cmake options used at install
#

set(MachineTypes_DUMMY_OPTION "@MachineTypes_DUMMY_OPTION@")

#
# Dependencies
#

#include(CMakeFindDependencyMacro)
#find_dependency(Threads)
#find_dependency(SomeConfigDep PATHS "@SomeConfigDep_DIR@")

#
# MachineTypes Exported Targets
#

include("${CMAKE_CURRENT_LIST_DIR}/MachineTypesTargets.cmake")

#
# Message and detect multiple, different, find_package
#

set(_details "${MachineTypes_DIR}")
if(NOT DEFINED _MachineTypes_FOUND_MESSAGE_DETAILS)
set(_MachineTypes_FOUND_MESSAGE_DETAILS "${_details}" CACHE INTERNAL "")
message(STATUS "Found MachineTypes: ${MachineTypes_DIR} (${MachineTypes_VERSION})")
elseif(NOT _MachineTypes_FOUND_MESSAGE_DETAILS STREQUAL _details)
message(WARNING "Different MachineTypes were find_package:
- ${_MachineTypes_FOUND_MESSAGE_DETAILS}
- ${_details}")
endif()

#
# Final check
#
check_required_components(MachineTypes)
31 changes: 31 additions & 0 deletions machinetypes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set(INC_FILES inc/machine_types.h)

add_library(MachineTypes INTERFACE)
add_library(MachineTypes::MachineTypes ALIAS MachineTypes)

target_include_directories(MachineTypes INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/inc>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# target_link_libraries(mytestlib
# PUBLIC Some_Lib_Used_in_Public_Headers
# PRIVATE Some_Lib_Used_Internaly
# )

#install(DIRECTORY
# ${CMAKE_CURRENT_SOURCE_DIR}/inc/
# ${CMAKE_CURRENT_BINARY_DIR}/inc/
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
# FILES_MATCHING PATTERN "*.h"
# )
install(FILES
${INC_FILES}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)


install(TARGETS MachineTypes
EXPORT MachineTypesTargets
)
12 changes: 12 additions & 0 deletions machinetypes/inc/machine_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef MACHINE_TYPES_H
#define MACHINE_TYPES_H

// This header was manufactured specifically for smooth3d/magix3d

// it can be called from C code so we do not use cstdint
#include <stdint.h>

typedef int64_t int_type;
typedef double float_type;

#endif // MACHINE_TYPES_H
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0

0 comments on commit 0d9f803

Please sign in to comment.