From a16fd798383763b7bb5802b8c4d89ac5d45987e9 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 2 Sep 2015 08:49:23 -1000 Subject: [PATCH] OS X support for atdna macro; dependency resolution fix --- CMakeLists.txt | 12 +++++---- atdna/CMakeLists.txt | 50 +++++++++++++++++++++++++++++++++++++- atdna/atdnaConfig.cmake.in | 9 +++++-- atdna/main.cpp | 8 ++++++ extern/lzo/CMakeLists.txt | 3 +++ extern/zlib/CMakeLists.txt | 4 +++ 6 files changed, 78 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77399b2..b870760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) cmake_minimum_required(VERSION 3.0) project(Athena) +endif() ################## # Athena Version # @@ -73,7 +75,7 @@ add_library(AthenaCore include/utf8proc.h ) -add_library(AthenaSakura +add_library(AthenaSakura EXCLUDE_FROM_ALL src/Athena/Sprite.cpp src/Athena/SpriteFile.cpp src/Athena/SpriteFileReader.cpp @@ -89,7 +91,7 @@ add_library(AthenaSakura include/Athena/SpritePart.hpp ) -add_library(AthenaWiiSave +add_library(AthenaWiiSave EXCLUDE_FROM_ALL src/Athena/WiiBanner.cpp src/Athena/WiiFile.cpp src/Athena/WiiImage.cpp @@ -118,7 +120,7 @@ if(NOT MSVC) set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes) endif() -add_library(AthenaZelda +add_library(AthenaZelda EXCLUDE_FROM_ALL src/Athena/ALTTPFile.cpp src/Athena/ALTTPFileReader.cpp src/Athena/ALTTPFileWriter.cpp @@ -174,7 +176,7 @@ endforeach() # Define installs install(DIRECTORY include/ DESTINATION ${INSTALL_INCLUDE_DIR}/Athena COMPONENT Athena) -install(TARGETS AthenaCore AthenaSakura AthenaWiiSave AthenaZelda +install(TARGETS AthenaCore DESTINATION ${INSTALL_LIB_DIR} EXPORT AthenaTargets COMPONENT Athena) if(WIN32 AND NOT CYGWIN) install(FILES Athena.ico DESTINATION ${INSTALL_LIB_DIR} COMPONENT Athena) @@ -190,7 +192,7 @@ endif() ################## # Add all targets to the build-tree export set -export(TARGETS AthenaCore AthenaSakura AthenaWiiSave AthenaZelda +export(TARGETS AthenaCore FILE "${PROJECT_BINARY_DIR}/AthenaTargets.cmake") # Export the package for use from the build-tree diff --git a/atdna/CMakeLists.txt b/atdna/CMakeLists.txt index 169eace..844b2bd 100644 --- a/atdna/CMakeLists.txt +++ b/atdna/CMakeLists.txt @@ -30,7 +30,8 @@ list(APPEND LLVM_LIBS LLVMBitReader LLVMMC LLVMSupport) -set(CLANG_INCLUDE_DIR ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_STRING}/include) +set(CLANG_INCLUDE_DIR ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_STRING}/include + CACHE PATH "Clang include dir" FORCE) if(UNIX) list(APPEND PLAT_LIBS z pthread curses dl) @@ -123,3 +124,50 @@ add_test(NAME test-dna COMMAND $ -o test.cpp endif() +####################### +# In-tree atdna macro # +####################### + +# Super handy macro for adding atdna target +macro(atdna out) + # Make input files source-relative + set(ins "") + foreach(arg ${ARGN}) + list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg}) + endforeach() + + # Get local include directories for atdna + get_property(incdirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) + set(inccli "") + foreach(dir ${incdirs}) + list(APPEND inccli "-I${dir}") + endforeach() + + # Get local defines for atdna + get_property(cdefs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) + set(cdefcli "") + foreach(def ${cdefs}) + list(APPEND cdefcli "-D${def}") + endforeach() + + # MS extra + unset(extraargs) + if(MSVC) + list(APPEND extraargs -fms-compatibility -fexceptions) + if(MSVC_VERSION EQUAL 1800) + list(APPEND extraargs -fms-compatibility-version=18.00) + elseif(MSVC_VERSION EQUAL 1900) + list(APPEND extraargs -fms-compatibility-version=19.00) + endif() + + # OSX Extra + elseif(APPLE) + list(APPEND extraargs -isysroot ${CMAKE_OSX_SYSROOT} -isysroot /) + endif() + + # Make target + add_custom_command(OUTPUT ${out} COMMAND $ + ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}" + -isystem "${CLANG_INCLUDE_DIR}" ${ins} + DEPENDS ${ins} COMMENT "Generating DNA ${out}") +endmacro() diff --git a/atdna/atdnaConfig.cmake.in b/atdna/atdnaConfig.cmake.in index a8f3219..0acd5fb 100644 --- a/atdna/atdnaConfig.cmake.in +++ b/atdna/atdnaConfig.cmake.in @@ -42,11 +42,16 @@ macro(atdna out) elseif(MSVC_VERSION EQUAL 1900) list(APPEND extraargs -fms-compatibility-version=19.00) endif() + + # OSX Extra + elseif(APPLE) + list(APPEND extraargs -isysroot ${CMAKE_OSX_SYSROOT} -isysroot /) endif() - + # Make target add_custom_command(OUTPUT ${out} COMMAND $ - ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}" -isystem "@CONF_CLANG_INCLUDE_DIR@" ${ins} + ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}" + -isystem "@CONF_CLANG_INCLUDE_DIR@" ${ins} DEPENDS ${ins} COMMENT "Generating DNA ${out}") endmacro() diff --git a/atdna/main.cpp b/atdna/main.cpp index 4f401a6..5674d1d 100644 --- a/atdna/main.cpp +++ b/atdna/main.cpp @@ -29,6 +29,8 @@ static unsigned AthenaError = 0; static llvm::cl::opt Help("h", llvm::cl::desc("Alias for -help"), llvm::cl::Hidden); +static llvm::cl::opt Verbose("v", llvm::cl::desc("verbose mode")); + static llvm::cl::OptionCategory ATDNAFormatCategory("atdna options"); static llvm::cl::opt OutputFilename("o", @@ -54,6 +56,12 @@ static llvm::cl::list IncludeSearchPaths("I", static llvm::cl::list SystemIncludeSearchPaths("isystem", llvm::cl::desc("System Header search path")); +static llvm::cl::opt StandardCXXLib("stdlib", + llvm::cl::desc("Standard C++ library")); + +static llvm::cl::list SystemIncRoot("isysroot", + llvm::cl::desc("System include root")); + static llvm::cl::list PreprocessorDefines("D", llvm::cl::desc("Preprocessor define"), llvm::cl::Prefix); diff --git a/extern/lzo/CMakeLists.txt b/extern/lzo/CMakeLists.txt index 4772cc1..7ee3897 100644 --- a/extern/lzo/CMakeLists.txt +++ b/extern/lzo/CMakeLists.txt @@ -81,5 +81,8 @@ if(WIN32 AND NOT UNIX) install(DIRECTORY include/lzo DESTINATION include COMPONENT lzo2) install(TARGETS lzo2 DESTINATION lib COMPONENT lzo2) endif() +set(LZO_LIB lzo2 CACHE PATH "LZO library" FORCE) set(LZO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "LZO include path" FORCE) +else() +find_path(LZO_INCLUDE_DIR lzo/lzo1x.h) endif() diff --git a/extern/zlib/CMakeLists.txt b/extern/zlib/CMakeLists.txt index 7183588..8ef90d4 100644 --- a/extern/zlib/CMakeLists.txt +++ b/extern/zlib/CMakeLists.txt @@ -30,5 +30,9 @@ if(WIN32 AND NOT UNIX) install(FILES zconf.h zlib.h DESTINATION include COMPONENT zlib) install(TARGETS z DESTINATION lib COMPONENT zlib) endif() +set(ZLIB_LIBRARIES z CACHE PATH "Zlib libraries" FORCE) set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Zlib include path" FORCE) +else() +set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} CACHE PATH "Zlib libraries" FORCE) +find_path(ZLIB_INCLUDE_DIR zlib.h) endif()