use cmake to generate the config.h file!

This commit is contained in:
Kelvin Sherlock 2016-08-09 10:30:29 -04:00
parent e0b6ba2c31
commit 70c74d4bc9
8 changed files with 65 additions and 34 deletions

View File

@ -4,6 +4,8 @@ set (PROJECT_TYPE "CXX")
set (PROJECT_NAME "mpw")
# these are only effective as of CMake 3.1, apparently.
# Use c++14 for all C++ files, c99 for C files.
#
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)
@ -16,7 +18,7 @@ if (APPLE)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_FLAGS "-stdlib=libc++ -Wall -g")
set(CMAKE_C_FLAGS "-Wall -g")
set(CMAKE_C_FLAGS "-Wall -g")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS")
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
@ -31,6 +33,28 @@ elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
endif()
#
# create the config.h file.
#
INCLUDE (CheckIncludeFiles)
INCLUDE (CheckTypeSize)
CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
SET(CMAKE_EXTRA_INCLUDE_FILES dirent.h)
CHECK_TYPE_SIZE("((struct dirent *)0)->d_namlen" DIRENT_D_NAMLEN)
SET(CMAKE_EXTRA_INCLUDE_FILES)
SET(CMAKE_EXTRA_INCLUDE_FILES sys/stat.h)
CHECK_TYPE_SIZE("((struct stat *)0)->st_birthtime" STAT_ST_BIRTHTIME)
SET(CMAKE_EXTRA_INCLUDE_FILES)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
add_subdirectory(bin)
add_subdirectory(cpu)

View File

@ -1,30 +0,0 @@
#ifndef __mpw_config_h__
#define __mpw_config_h__
#ifdef __APPLE__
#include <machine/endian.h>
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
#define HAVE_STAT_ST_BIRTHTIME
#endif
#define HAVE_DIRENT_D_NAMLEN
#endif
#ifdef __sun__
#include <endian.h>
#endif
#ifdef __linux__
#include <endian.h>
#endif
#ifdef _WIN32
#endif
#endif

11
config.h.in Normal file
View File

@ -0,0 +1,11 @@
#ifndef __mpw_config_h__
#define __mpw_config_h__
#cmakedefine HAVE_STAT_ST_BIRTHTIME
#cmakedefine HAVE_DIRENT_D_NAMLEN
#cmakedefine HAVE_ENDIAN_H
#cmakedefine HAVE_MACHINE_ENDIAN_H
#cmakedefine HAVE_SYS_ENDIAN_H
#endif

17
include/endian.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef __mpw_endian_h__
#define __mpw_endian_h__
#include "config.h"
#if defined(HAVE_ENDIAN_H)
#include <endian.h>
#elif defined(HAVE_SYS_ENDIAN_H)
#include <sys/endian.h>
#elif defined(HAVE_MACHINE_ENDIAN_H)
#include <machine/endian.h>
#else
#error missing endian.h
#endif
#endif

View File

@ -1,5 +1,6 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
add_definitions(-I ${CMAKE_BINARY_DIR}/)
set(NATIVE_SRC native.cpp ${CMAKE_SYSTEM_NAME}.cpp)

View File

@ -32,12 +32,17 @@
#include <unistd.h>
#include <fcntl.h>
#include "config.h"
//using MacOS::macos_error_from_errno;
//using MacOS::macos_error;
using namespace MacOS;
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
// pre 10.5 I guess...
#ifndef HAVE_STAT_ST_BIRTHTIME
#undef st_birthtime
#define st_birthtime st_ctime
#endif

View File

@ -33,9 +33,11 @@
#include <unistd.h>
#include <fcntl.h>
#include "config.h"
#define XATTR_FINDERINFO_NAME "com.apple.FinderInfo"
#define XATTR_RESOURCEFORK_NAME "com.apple.ResourceFork"
#define XATTR_FINDERINFO_NAME "com.apple.FinderInfo"
#define XATTR_RESOURCEFORK_NAME "com.apple.ResourceFork"
#define XATTR_FILETYPE_NAME "prodos.FileType"
#define XATTR_AUXTYPE_NAME "prodos.AuxType"

View File

@ -1,6 +1,7 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
add_definitions(-I ${CMAKE_BINARY_DIR}/)
set(TOOLBOX_SRC
toolbox.cpp