Skip to content
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

Add support for building with CMake #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) # Use <PackageName>_ROOT variables
endif()
project(UNIXem
DESCRIPTION "Small and simple library that provides emulation of several popular Unix API functions on the Windows platform. Its primary purpose is to assist Windows programmers who are porting to Unix or are writing multi-platform code."
LANGUAGES C CXX)

# Directory for CMake specific extensions and source files.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

# Set build type to Debug if this is a Git repository.
# Otherwise set to Release.
# Unless user overrides on the command line.
include(BuildType)

# Configure a project for testing with CTest/CDash
# and activate testing (set var BUILD_TESTING=On).
# Unless user overrides on the command line.
include(CTest)

# Handle version number
set(RX_WS "[ \t\r\n]")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/unixem/unixem.h" _header_file)
string(REGEX MATCH "#define${RX_WS}+UNIXEM_VER_MAJOR${RX_WS}+([0-9]+)" MAJOR_DUMMY ${_header_file})
set(_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#define${RX_WS}+UNIXEM_VER_MINOR${RX_WS}+([0-9]+)" MINOR_DUMMY ${_header_file})
set(_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#define${RX_WS}+UNIXEM_VER_REVISION${RX_WS}+([0-9]+)" PATCH_DUMMY ${_header_file})
set(_VERSION_PATCH ${CMAKE_MATCH_1})

# Set project version number here
set(PROJECT_VERSION_MAJOR ${_VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${_VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${_VERSION_PATCH})
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

# Adhere strictly to C and C++ standards plus extensions.
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # GNU extensions and POSIX standard
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# #########################################################
# Preparations for installing

# Provides install directory variables as defined by the GNU Coding Standards.
include(GNUInstallDirs)

# #########################################################
# Build

find_package(STLSoft 1.9 REQUIRED)

add_subdirectory(src)

# Tests
if(BUILD_TESTING)
find_package(xTests 0.18.4 QUIET)
if(xTests_FOUND)
add_subdirectory(test)
else(xTests_FOUND)
message(AUTHOR_WARNING "The xTests framework not found. Cannot build tests.")
endif()
endif()

# #########################################################
# Export and install the project

string(TOLOWER ${PROJECT_NAME} EXPORT_NAME)

# Prepare a config and config-version files
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXPORT_NAME}/cmake
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

export(EXPORT project-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
)

# Install to GNU type subdirs under CMAKE_INSTALL_PREFIX
install(EXPORT project-targets
NAMESPACE "${PROJECT_NAME}::"
FILE "${EXPORT_NAME}-targets.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)
install( FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)

# Store the current build directory in the CMake
# user package registry for package.
# This helps dependent projects use a package
# from the current project’s build tree,
# i.e. without installing it.
export(PACKAGE "${PROJECT_NAME}")

15 changes: 15 additions & 0 deletions cmake/BuildType.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Set a default build type if none was specified
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug")
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

3 changes: 3 additions & 0 deletions cmake/unixem-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include("${CMAKE_CURRENT_LIST_DIR}/b64Targets.cmake")
set(b64_INCLUDE_DIRS "@PACKAGE_INCLUDE_DIR@")

65 changes: 65 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
add_library(UNIXem.core
atomic.c
dirent.c
dlfcn.c
glob.c
hostname.c
mktemp.c
mmap.c
resource.c
setenv.c
time.c
uio.c
unistd.c
internal/util.c)

list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/arpa/inet.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/asm/atomic.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/netonet/in.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/sys/mman.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/sys/resource.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/sys/socket.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/sys/time.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/sys/uio.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/arpa/inet.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/asm/atomic.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/netonet/in.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/sys/mman.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/sys/resource.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/sys/socket.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/sys/time.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/sys/uio.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/arpa/inet.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/dirent.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/dlfcn.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/glob.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/setenv.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/time.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/unistd.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unixem/unixem.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/dirent.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/dlfcn.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/glob.h")
list(APPEND public_headers "${CMAKE_SOURCE_DIR}/include/unistd.h")

list(APPEND private_headers "${CMAKE_SOURCE_DIR}/include/unixem/internal/safestr.h")
list(APPEND private_headers "${CMAKE_SOURCE_DIR}/include/unixem/internal/util.h")
list(APPEND private_headers "${CMAKE_SOURCE_DIR}/include/unixem/internal/winsock.h")

set_target_properties(UNIXem.core PROPERTIES
OUTPUT_NAME "UNIXem"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PRIVATE_HEADER "${private_headers}"
PUBLIC_HEADER "${public_headers}")
target_include_directories(UNIXem.core PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

install(TARGETS UNIXem.core
EXPORT project-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unixem
)
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(component)
add_subdirectory(scratch)
add_subdirectory(unit)
4 changes: 4 additions & 0 deletions test/component/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(test.component.dirent)
add_subdirectory(test.component.glob)
add_subdirectory(test.component.unistd.mkdtemp)
add_subdirectory(test.component.unistd.mkstemp)
3 changes: 3 additions & 0 deletions test/component/test.component.dirent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.component.dirent test.component.dirent.c)
target_link_libraries(test.component.dirent UNIXem.core xTests::xTests.core)
add_test(NAME test.component.dirent COMMAND ./test.component.dirent)
5 changes: 5 additions & 0 deletions test/component/test.component.glob/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This test is deactivated temporarily
# due to missing STLSoft file 'platformstl/system/temporary_directory.hpp'.
# add_executable(test.component.glob test.component.glob.cpp)
# target_link_libraries(test.component.glob UNIXem.core STLSoft::STLSoft xTests::xTests.core)
# add_test(NAME test.component.glob COMMAND ./test.component.glob)
3 changes: 3 additions & 0 deletions test/component/test.component.unistd.mkdtemp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.component.unistd.mkdtemp test.component.unistd.mkdtemp.c)
target_link_libraries(test.component.unistd.mkdtemp UNIXem.core xTests::xTests.core)
add_test(NAME test.component.unistd.mkdtemp COMMAND ./test.component.unistd.mkdtemp)
3 changes: 3 additions & 0 deletions test/component/test.component.unistd.mkstemp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.component.unistd.mkstemp test.component.unistd.mkstemp.c)
target_link_libraries(test.component.unistd.mkstemp UNIXem.core xTests::xTests.core)
add_test(NAME test.component.unistd.mkstemp COMMAND ./test.component.unistd.mkstemp)
8 changes: 8 additions & 0 deletions test/scratch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_subdirectory(test.scratch.dlfcn)
add_subdirectory(test.scratch.fnmatch)
add_subdirectory(test.scratch.getrusage)
add_subdirectory(test.scratch.link)
add_subdirectory(test.scratch.mmap)
add_subdirectory(test.scratch.setenv)
add_subdirectory(test.scratch.syslog)
add_subdirectory(test.scratch.uio)
3 changes: 3 additions & 0 deletions test/scratch/test.scratch.dlfcn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.scratch.dlfcn test.scratch.dlfcn.c)
target_link_libraries(test.scratch.dlfcn UNIXem.core xTests::xTests.core)
add_test(NAME test.scratch.dlfcn COMMAND ./test.scratch.dlfcn)
6 changes: 6 additions & 0 deletions test/scratch/test.scratch.fnmatch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This test is temporarily deactivated du to compile error
# C:\Users\test\scratch\test.scratch.fnmatch\test.scratch.fnmatch.c(45): fatal error C1083: Cannot open include file: 'fnmatch.h': No such file or directory

# add_executable(test.scratch.fnmatch test.scratch.fnmatch.c)
# target_link_libraries(test.scratch.fnmatch UNIXem.core xTests::xTests.core)
# add_test(NAME test.scratch.fnmatch COMMAND ./test.scratch.fnmatch)
3 changes: 3 additions & 0 deletions test/scratch/test.scratch.getrusage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.scratch.getrusage test.scratch.getrusage.c)
target_link_libraries(test.scratch.getrusage UNIXem.core xTests::xTests.core)
add_test(NAME test.scratch.getrusage COMMAND ./test.scratch.getrusage)
3 changes: 3 additions & 0 deletions test/scratch/test.scratch.link/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.scratch.link test.scratch.link.c)
target_link_libraries(test.scratch.link UNIXem.core xTests::xTests.core)
add_test(NAME test.scratch.link COMMAND ./test.scratch.link)
17 changes: 17 additions & 0 deletions test/scratch/test.scratch.mmap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This test is deactivated temporarily
# due to compile errors.

# add_executable(test.scratch.mmap.readonly test.scratch.mmap.c)
# target_link_libraries(test.scratch.mmap.readonly UNIXem.core xTests::xTests.core)
# target_compile_definitions(test.scratch.mmap.readonly PRIVATE TEST_READONLY)
# add_test(NAME test.scratch.mmap.readonly COMMAND ./test.scratch.mmap.readonly)

# add_executable(test.scratch.mmap.readwrite test.scratch.mmap.c)
# target_link_libraries(test.scratch.mmap.readwrite UNIXem.core xTests::xTests.core)
# target_compile_definitions(test.scratch.mmap.readwrite PRIVATE TEST_READWRITE)
# add_test(NAME test.scratch.mmap.readwrite COMMAND ./test.scratch.mmap.readwrite)

# add_executable(test.scratch.mmap.paging test.scratch.mmap.c)
# target_link_libraries(test.scratch.mmap.paging UNIXem.core xTests::xTests.core)
# target_compile_definitions(test.scratch.mmap.paging PRIVATE TEST_PAGING)
# add_test(NAME test.scratch.mmap.paging COMMAND ./test.scratch.mmap.paging)
3 changes: 3 additions & 0 deletions test/scratch/test.scratch.setenv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.scratch.setenv test.scratch.setenv.c)
target_link_libraries(test.scratch.setenv UNIXem.core xTests::xTests.core)
add_test(NAME test.scratch.setenv COMMAND ./test.scratch.setenv)
3 changes: 3 additions & 0 deletions test/scratch/test.scratch.syslog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.scratch.syslog test.scratch.syslog.c)
target_link_libraries(test.scratch.syslog UNIXem.core xTests::xTests.core)
add_test(NAME test.scratch.syslog COMMAND ./test.scratch.syslog)
3 changes: 3 additions & 0 deletions test/scratch/test.scratch.uio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.scratch.uio test.scratch.uio.c)
target_link_libraries(test.scratch.uio UNIXem.core xTests::xTests.core)
add_test(NAME test.scratch.uio COMMAND ./test.scratch.uio)
1 change: 1 addition & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(test.unit.unistd.gethostname)
4 changes: 4 additions & 0 deletions test/unit/test.unit.unistd.gethostname/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(test.unit.unistd.gethostname test.unit.unistd.gethostname.c)
target_link_libraries(test.unit.unistd.gethostname UNIXem.core xTests::xTests.core)
add_test(NAME test.unit.unistd.gethostname COMMAND ./test.unit.unistd.gethostname)

4 changes: 4 additions & 0 deletions test/unit/test.unit.unistd.getpid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(test.unit.unistd.getpid test.unit.unistd.getpid.c)
target_link_librariestest.unit.unistd.getpid UNIXem.core xTests::xTests.core)
add_test(NAME test.unit.unistd.getpid COMMAND ./test.unit.unistd.getpid)

3 changes: 3 additions & 0 deletions test/unit/test.unit.unistd.pathconf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_executable(test.unit.unistd.pathconf test.unit.unistd.pathconf.c)
target_link_librariestest.unit.unistd.pathconf UNIXem.core xTests::xTests.core)
add_test(NAME test.unit.unistd.pathconf COMMAND ./test.unit.unistd.pathconf)