aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2016-07-19 22:50:04 -0700
committerAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2016-11-30 08:25:19 -0800
commita8c9e5d64d9a5a0382fccaa98220d22cbaf9b55f (patch)
treecfded8a49cfc5b7e52ab2615d24a74c5fa7b479e /cmake
parent9cb3984eb0e0829d4f05b6116f6ae572bc44d21b (diff)
downloadpaludis-a8c9e5d64d9a5a0382fccaa98220d22cbaf9b55f.tar.gz
paludis-a8c9e5d64d9a5a0382fccaa98220d22cbaf9b55f.tar.xz
build: introduce cmake based build system
Diffstat (limited to 'cmake')
-rw-r--r--cmake/config.h.in22
-rw-r--r--cmake/modules/FindJansson.cmake57
-rw-r--r--cmake/modules/FindLibMagic.cmake40
-rw-r--r--cmake/modules/FindPCRECPP.cmake42
-rw-r--r--cmake/modules/FindSQLite3.cmake55
-rw-r--r--cmake/modules/FindSphinx.cmake24
-rw-r--r--cmake/modules/PaludisAddLibrary.cmake91
-rw-r--r--cmake/modules/PaludisAddTest.cmake103
-rw-r--r--cmake/modules/PaludisCheckFunctionExists.cmake17
-rw-r--r--cmake/modules/PaludisCompileFlags.cmake78
-rw-r--r--cmake/modules/PaludisGeneratorUtils.cmake140
-rw-r--r--cmake/modules/PaludisList.cmake24
-rw-r--r--cmake/modules/PaludisPackage.cmake34
13 files changed, 727 insertions, 0 deletions
diff --git a/cmake/config.h.in b/cmake/config.h.in
new file mode 100644
index 000000000..93e087841
--- /dev/null
+++ b/cmake/config.h.in
@@ -0,0 +1,22 @@
+
+#define HAVE_CXA_DEMANGLE @HAVE_CXA_DEMANGLE@
+
+#define REPOSITORY_GROUPS_DECLS @REPOSITORY_GROUPS_DECLS@
+#define REPOSITORY_GROUP_IF_accounts @REPOSITORY_GROUP_IF_accounts@
+#define REPOSITORY_GROUP_IF_e @REPOSITORY_GROUP_IF_e@
+#define REPOSITORY_GROUP_IF_fake @REPOSITORY_GROUP_IF_fake@
+#define REPOSITORY_GROUP_IF_gemcutter @REPOSITORY_GROUP_IF_gemcutter@
+#define REPOSITORY_GROUP_IF_repository @REPOSITORY_GROUP_IF_repository@
+#define REPOSITORY_GROUP_IF_unavailable @REPOSITORY_GROUP_IF_unavailable@
+#define REPOSITORY_GROUP_IF_unpackaged @REPOSITORY_GROUP_IF_unpackaged@
+#define REPOSITORY_GROUP_IF_unwritten @REPOSITORY_GROUP_IF_unwritten@
+#define REPOSITORY_GROUP_IF_dummy
+
+#define ENVIRONMENT_GROUPS_DECLS @ENVIRONMENT_GROUPS_DECLS@
+#define ENVIRONMENT_GROUP_IF_paludis @ENVIRONMENT_GROUP_IF_paludis@
+#define ENVIRONMENT_GROUP_IF_portage @ENVIRONMENT_GROUP_IF_portage@
+#define ENVIRONMENT_GROUP_IF_test @ENVIRONMENT_GROUP_IF_test@
+#define ENVIRONMENT_GROUP_IF_dummy
+
+#define DEFAULT_DISTRIBUTION "@PALUDIS_DEFAULT_DISTRIBUTION@"
+
diff --git a/cmake/modules/FindJansson.cmake b/cmake/modules/FindJansson.cmake
new file mode 100644
index 000000000..ea98f125a
--- /dev/null
+++ b/cmake/modules/FindJansson.cmake
@@ -0,0 +1,57 @@
+# .rst
+# FindJansson
+# -----------
+#
+# Find Jansson library and headers
+#
+# The module defines the following variables:
+#
+# ::
+#
+# Jansson_FOUND - true if Jansson was found
+# Jansson_INCLUDE_DIR - include search path
+# Jansson_LIBRARIES - libraries to link
+# Jansson_VERSION - libmagic 3-component version number
+
+if(Jansson_INCLUDE_DIRS AND Jansson_LIBRARIES)
+ set(Jansson_FOUND TRUE)
+else()
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PC_JANSSON QUIET jansson)
+
+ find_path(Jansson_INCLUDE_DIR
+ NAMES
+ jansson.h
+ HINTS
+ ${PC_JANSSON_INCLUDEDIR}
+ ${PC_JANSSON_INCLUDE_DIRS}
+ ${CMAKE_INSTALL_FULL_INCLUDEDIR})
+ find_library(Jansson_LIBRARIES
+ NAMES
+ jansson
+ libjansson
+ HINTS
+ ${PC_JANSSON_LIBDIR}
+ ${PC_JANSSON_LIBRARY_DIRS}
+ ${CMAKE_INSTALL_FULL_LIBDIR})
+
+ if(Jansson_INCLUDE_DIR AND EXISTS "${Jansson_INCLUDE_DIR}/jansson.h")
+ file(STRINGS "${Jansson_INCLUDE_DIR}/jansson.h"
+ REGEX "^#[ ]*define[ ]+JANSSON_VERSION[ ]+\".*\""
+ jansson_version_str)
+ string(REGEX
+ REPLACE "^[ ]*define[ ]+JANSSON_VERSION[ ]+\"([^\"]*)\".*" "\\1"
+ Jansson_VERSION_STRING "${jansson_version_str}")
+ unset(jansson_version_str)
+ endif()
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(Jansson
+ REQUIRED_VARS
+ Jansson_INCLUDE_DIRS
+ Jansson_LIBRARIES
+ VERSION_VAR
+ Jansson_VERSION_STRING)
+ mark_as_advanced(Jansson_INCLUDE_DIR Jansson_LIBRARIES)
+endif()
+
diff --git a/cmake/modules/FindLibMagic.cmake b/cmake/modules/FindLibMagic.cmake
new file mode 100644
index 000000000..9c56a07aa
--- /dev/null
+++ b/cmake/modules/FindLibMagic.cmake
@@ -0,0 +1,40 @@
+#.rst:
+# FindLibMagic
+# ------------
+#
+# Find libmagic library and headers
+#
+# The module defines the following variables:
+#
+# ::
+#
+# LibMagic_FOUND - true if libmagic was found
+# LibMagic_INCLUDE_DIR - include search path
+# LibMagic_LIBRARIES - libraries to link
+
+if(UNIX)
+ find_path(LibMagic_INCLUDE_DIR
+ NAMES
+ magic.h)
+
+ if(APPLE)
+ set(LibMagic_NAMES libmagic.a magic)
+ else()
+ set(LibMagic_NAMES magic)
+ endif()
+
+ find_library(LibMagic_LIBRARIES
+ NAMES
+ ${LibMagic_NAMES}
+ HINTS
+ ${LIBMAGIC_ROOT_DIR}
+ ${CMAKE_INSTALL_PREFIX})
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(LibMagic
+ REQUIRED_VARS
+ LibMagic_LIBRARIES
+ LibMagic_INCLUDE_DIR)
+ mark_as_advanced(LibMagic_LIBRARIES LibMagic_INCLUDE_DIR)
+endif()
+
diff --git a/cmake/modules/FindPCRECPP.cmake b/cmake/modules/FindPCRECPP.cmake
new file mode 100644
index 000000000..3075f59d8
--- /dev/null
+++ b/cmake/modules/FindPCRECPP.cmake
@@ -0,0 +1,42 @@
+#.rst:
+# FindPCRECPP
+# ------------
+#
+# Find libpcrecpp library and headers
+#
+# The module defines the following variables:
+#
+# ::
+#
+# PCRECPP_FOUND - true if libmagic was found
+# PCRECPP_INCLUDE_DIR - include search path
+# PCRECPP_LIBRARIES - libraries to link
+
+find_path(PCRECPP_INCLUDE_DIR
+ NAMES
+ pcrecpp.h)
+
+find_library(PCRECPP_LIBRARY
+ NAMES
+ pcrecpp
+ HINTS
+ ${PCRECPP_ROOT_DIR}
+ ${CMAKE_INSTALL_PREFIX})
+find_library(PCRE_LIBRARY
+ NAMES
+ pcre
+ HINTS
+ ${PCRECPP_ROOT_DIR}
+ ${CMAKE_INSTALL_PREFIX})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCRECPP
+ REQUIRED_VARS
+ PCRECPP_LIBRARY
+ PCRE_LIBRARY
+ PCRECPP_INCLUDE_DIR)
+if(PCRECPP_FOUND)
+ set(PCRECPP_LIBRARIES ${PCRECPP_LIBRARY} ${PCRE_LIBRARY})
+endif()
+mark_as_advanced(PCRECPP_INCLUDE_DIR PCRE_LIBRARY PCRECPP_LIBRARY PCRECPP_LIBRARIES)
+
diff --git a/cmake/modules/FindSQLite3.cmake b/cmake/modules/FindSQLite3.cmake
new file mode 100644
index 000000000..306fd9f22
--- /dev/null
+++ b/cmake/modules/FindSQLite3.cmake
@@ -0,0 +1,55 @@
+#.rst:
+# FindSQLite3
+# ------------
+#
+# Find SQLite3 library and headers
+#
+# The module defines the following variables:
+#
+# ::
+#
+# SQLite3_FOUND - true if SQLite3 was found
+# SQLite3_INCLUDE_DIR - include search path
+# SQLite3_LIBRARIES - libraries to link
+# SQLite3_VERSION - libmagic 3-component version number
+
+if(SQLite3_INCLUDE_DIRS AND SQLite3_LIBRARIES)
+ set(SQLite3_FOUND TRUE)
+else()
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PC_SQLITE3 QUIET sqlite3)
+
+ find_path(SQLite3_INCLUDE_DIR
+ NAMES
+ sqlite3.h
+ HINTS
+ ${PC_SQLITE3_INCLUDEDIR}
+ ${PC_SQLITE3_INCLUDE_DIRS}
+ ${CMAKE_INSTALL_FULL_INCLUDEDIR})
+ find_library(SQLite3_LIBRARIES
+ NAMES
+ sqlite3 libsqlite3
+ HINTS
+ ${PC_SQLITE3_LIBDIR}
+ ${PC_SQLITE3_LIBRARY_DIRS}
+ ${CMAKE_INSTALL_FULL_LIBDIR})
+
+ if(SQLite3_INCLUDE_DIR AND EXISTS "${SQLite3_INCLUDE_DIR}/sqlite3.h")
+ file(STRINGS "${SQLite3_INCLUDE_DIR}/sqlite3.h"
+ sqlite3_version_str
+ REGEX "^#define SQLITE_VERSION[ ]+\".*\"")
+ string(REGEX REPLACE "^#define SQLITE_VERSION[ ]+\"([^\"]*)\".*" "\\1"
+ SQLite3_VERSION_STRING "${sqlite3_version_str}")
+ unset(sqlite3_version_str)
+ endif()
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(SQLite3
+ REQUIRED_VARS
+ SQLite3_LIBRARIES
+ SQLite3_INCLUDE_DIR
+ VERSION_VAR
+ SQLite3_VERSION_STRING)
+ mark_as_advanced(SQLite3_INCLUDE_DIR SQLite3_LIBRARIES)
+endif()
+
diff --git a/cmake/modules/FindSphinx.cmake b/cmake/modules/FindSphinx.cmake
new file mode 100644
index 000000000..8e18e2cb2
--- /dev/null
+++ b/cmake/modules/FindSphinx.cmake
@@ -0,0 +1,24 @@
+#.rst:
+# FindSphinx
+# ------------
+#
+# Find sphinx documentation generator
+#
+# The module defines the following variables:
+#
+# ::
+#
+# SPHINX_FOUND - true if sphinx was found
+# SPHINX_EXECUTABLE - sphinx binary
+
+find_program(SPHINX_EXECUTABLE
+ NAMES
+ sphinx-build
+ HINTS
+ ${SPHINX_ROOT_DIR}
+ ${CMAKE_INSTALL_PREFIX})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE)
+mark_as_advanced(SPHINX_EXECUTABLE)
+
diff --git a/cmake/modules/PaludisAddLibrary.cmake b/cmake/modules/PaludisAddLibrary.cmake
new file mode 100644
index 000000000..d57666c26
--- /dev/null
+++ b/cmake/modules/PaludisAddLibrary.cmake
@@ -0,0 +1,91 @@
+
+include(CMakeParseArguments)
+include(PaludisGeneratorUtils)
+
+function(paludis_add_library library_name)
+ set(options SHARED_LIBRARY STATIC_LIBRARY OBJECT_LIBRARY UNVERSIONED)
+ set(single_value_args)
+ set(multiple_value_args NN_SOURCES SE_SOURCES INCORPORATE_OBJECT_LIBRARIES)
+
+ cmake_parse_arguments(PAL "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
+
+ if(PAL_STATIC_LIBRARY AND PAL_OBJECT_LIBRARY)
+ message(SEND_ERROR "paludis_add_library(${library_name}) called with STATIC_LIBRARY and OBJECT_LIBRARY")
+ endif()
+
+ if(PAL_STATIC_LIBRARY)
+ set(libkind STATIC)
+ elseif(PAL_OBJECT_LIBRARY)
+ set(libkind OBJECT)
+ elseif(PAL_SHARED_LIBRARY)
+ set(libkibd SHARED)
+ else()
+ set(libkind)
+ endif()
+
+ set(nnsources)
+ set(nndependencies)
+ foreach(nn_source ${PAL_NN_SOURCES})
+ get_filename_component(nnname ${nn_source} NAME_WE)
+ paludis_nnprocess(${nn_source}
+ HEADER_TARGET
+ ${nnname}_HEADER_TARGET
+ SOURCE_TARGET
+ ${nnname}_SOURCE_TARGET
+ SOURCE_FILE
+ ${nnname}_SOURCE_FILE)
+ list(APPEND nnsources ${${nnname}_SOURCE_FILE})
+ list(APPEND nndependencies ${${nnname}_HEADER_TARGET};${${nnname}_SOURCE_TARGET})
+ endforeach()
+ add_custom_target(${library_name}_NN
+ DEPENDS
+ ${nndependencies})
+
+ set(sedependencies)
+ foreach(se_source ${PAL_SE_SOURCES})
+ paludis_seprocess(${se_source}
+ HEADER_TARGET
+ ${se_source}_HEADER_TARGET
+ SOURCE_TARGET
+ ${se_source}_SOURCE_TARGET)
+ list(APPEND sedependencies ${${se_source}_HEADER_TARGET};${${se_source}_SOURCE_TARGET})
+ endforeach()
+ add_custom_target(${library_name}_SE
+ DEPENDS
+ ${sedependencies})
+
+ set(object_libraries_expressions)
+ foreach(library ${PAL_INCORPORATE_OBJECT_LIBRARIES})
+ list(APPEND object_libraries_expressions $<TARGET_OBJECTS:${library}>)
+ endforeach()
+
+ add_library(${library_name}
+ ${libkind}
+ ${PAL_UNPARSED_ARGUMENTS}
+ ${object_libraries_expressions}
+ ${nnsources})
+ if(nndependencies)
+ add_dependencies(${library_name} ${nndependencies})
+ endif()
+ if(sedependencies)
+ add_dependencies(${library_name} ${sedependencies})
+ endif()
+
+ if(NOT PAL_OBJECT_LIBRARY)
+ get_target_property(libkind ${library_name} TYPE)
+ string(REGEX REPLACE "^lib" "" output_name ${library_name})
+ set(output_name ${output_name}_${PALUDIS_PKG_CONFIG_SLOT})
+ set_target_properties(${library_name} PROPERTIES OUTPUT_NAME ${output_name})
+ endif()
+
+ if("${libkind}" STREQUAL "SHARED_LIBRARY" AND NOT PAL_UNVERSIONED)
+ math(EXPR version_major "${PROJECT_VERSION_MAJOR} * 100 + ${PROJECT_VERSION_MINOR}")
+ set_target_properties(${library_name}
+ PROPERTIES
+ VERSION
+ "${version_major}.${PROJECT_VERSION_PATCH}.0"
+ SOVERSION
+ "${version_major}")
+ endif()
+endfunction()
+
diff --git a/cmake/modules/PaludisAddTest.cmake b/cmake/modules/PaludisAddTest.cmake
new file mode 100644
index 000000000..cde8efbe1
--- /dev/null
+++ b/cmake/modules/PaludisAddTest.cmake
@@ -0,0 +1,103 @@
+
+include(CMakeParseArguments)
+
+function(paludis_add_test test_name)
+ set(options BASH GTEST PYTHON RUBY)
+ set(single_value_args EBUILD_MODULE_SUFFIXES TEST_RUNNER)
+ set(multiple_value_args LINK_LIBRARIES)
+
+ cmake_parse_arguments(PAT "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
+
+ string(REGEX MATCH "_TEST" has_TEST ${test_name})
+ if(NOT has_TEST)
+ set(test_name ${test_name}_TEST)
+ endif()
+
+ if(PAT_GTEST AND NOT ENABLE_GTEST)
+ return()
+ endif()
+
+ if(NOT PAT_BASH AND NOT PAT_PYTHON AND NOT PAT_RUBY)
+ add_executable(${test_name}
+ "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.cc")
+ endif()
+ if(PAT_GTEST)
+ target_include_directories(${test_name}
+ PRIVATE
+ ${GTEST_INCLUDE_DIRS})
+ target_link_libraries(${test_name}
+ PRIVATE
+ libpaludis
+ libpaludisutil
+ ${GTEST_BOTH_LIBRARIES}
+ ${PAT_LINK_LIBRARIES})
+ endif()
+
+ set(pat_test_runner "${PROJECT_SOURCE_DIR}/paludis/util/run_test.sh")
+ if(PAT_TEST_RUNNER)
+ set(pat_test_runner "${PAT_TEST_RUNNER}")
+ endif()
+
+ set(pat_environment_variables)
+ if(NOT "${PAT_EBUILD_MODULE_SUFFIXES}" STREQUAL "")
+ set(pat_environment_variables PALUDIS_EBUILD_MODULE_SUFFIXES=${PAT_EBUILD_MODULE_SUFFIXES})
+ endif()
+
+ string(REGEX REPLACE "_TEST" "" pat_display_name ${test_name})
+
+ set(pat_test_extension "")
+ if(PAT_PYTHON)
+ set(pat_test_extension ".py")
+ elseif(PAT_RUBY)
+ set(pat_test_extension ".rb")
+ endif()
+
+ if(PAT_BASH OR PAT_PYTHON OR PAT_RUBY)
+ set(pat_test_binary_parent_directory "${CMAKE_CURRENT_SOURCE_DIR}")
+ else()
+ set(pat_test_binary_parent_directory "${CMAKE_CURRENT_BINARY_DIR}")
+ endif()
+
+ set(pat_test_binary
+ "${pat_test_binary_parent_directory}/${test_name}${pat_test_extension}")
+
+ math(EXPR version_major "${PROJECT_VERSION_MAJOR} * 100 + ${PROJECT_VERSION_MINOR}")
+
+ # NOTE(compnerd) the trailing slash on the TEST_SCRIPT_DIR is important as
+ # the harness will not add that for us
+ add_test(NAME
+ ${pat_display_name}
+ COMMAND
+ env -i HOME=${CMAKE_CURRENT_BINARY_DIR}
+ LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/paludis
+ PALUDIS_BYPASS_USERPRIV_CHECKS=YES
+ PALUDIS_DEFAULT_OUTPUT_CONF=${PROJECT_SOURCE_DIR}/paludis/environments/paludis/tests_output.conf
+ PALUDIS_DISTRIBUTION=gentoo
+ PALUDIS_DISTRIBUTIONS_DIR=${PROJECT_SOURCE_DIR}/paludis/distributions
+ PALUDIS_EAPIS_DIR=${PROJECT_SOURCE_DIR}/paludis/repositories/e/eapis
+ PALUDIS_EBUILD_DIR=${PROJECT_SOURCE_DIR}/paludis/repositories/e/ebuild
+ PALUDIS_EBUILD_DIR_FALLBACK=${CMAKE_BINARY_DIR}/paludis/repositories/e/ebuild
+ PALUDIS_ECHO_FUNCTIONS_DIR=${CMAKE_BINARY_DIR}/paludis/util
+ PALUDIS_EXTRA_EBUILD_MODULES_DIRS=${CMAKE_BINARY_DIR}/paludis/util
+ PALUDIS_FETCHERS_DIR=${PROJECT_SOURCE_DIR}/paludis/fetchers
+ PALUDIS_HOOKER_DIR=${PROJECT_SOURCE_DIR}/paludis
+ PALUDIS_NO_CHOWN=YES
+ PALUDIS_NO_GLOBAL_HOOKS=YES
+ PALUDIS_NO_GLOBAL_SETS=YES
+ PALUDIS_NO_XTERM_TITLES=YES
+ PALUDIS_PC_SLOT=${PALUDIS_PKG_CONFIG_SLOT}
+ PALUDIS_PYTHON_DIR=${PROJECT_SOURCE_DIR}/python
+ PALUDIS_SUFFIXES_FILE=${PROJECT_SOURCE_DIR}/paludis/repositories/e/ebuild_entries_suffixes.conf
+ PALUDIS_TMPDIR=${CMAKE_CURRENT_BINARY_DIR}
+ PYTHON=${PYTHON_EXECUTABLE}
+ PYTHONPATH=${CMAKE_BINARY_DIR}/python
+ RUBY=${RUBY_EXECUTABLE}
+ RUBYLIB=${CMAKE_BINARY_DIR}/ruby
+ SO_SUFFIX=${version_major}
+ SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}
+ TEST_SCRIPT_DIR=${CMAKE_CURRENT_SOURCE_DIR}/
+ TOP_BUILDDIR=${CMAKE_BINARY_DIR}
+ ${pat_environment_variables}
+ "${BASH_EXECUTABLE}" ${pat_test_runner} "${pat_test_binary}")
+endfunction()
+
diff --git a/cmake/modules/PaludisCheckFunctionExists.cmake b/cmake/modules/PaludisCheckFunctionExists.cmake
new file mode 100644
index 000000000..4f036e06c
--- /dev/null
+++ b/cmake/modules/PaludisCheckFunctionExists.cmake
@@ -0,0 +1,17 @@
+
+include(CheckFunctionExists)
+include(CMakeParseArguments)
+
+macro(paludis_check_function_exists function variable)
+ set(pcfe_options REQUIRED)
+ set(pcfe_single_value_args)
+ set(pcfe_multiple_value_args)
+
+ cmake_parse_arguments(PCFE "${pcfe_options}" "${pcfe_single_value_args}" "${pcfe_multiple_value_args}" ${ARGN})
+
+ check_function_exists(${function} ${variable})
+ if(PCFE_REQUIRED AND NOT ${variable})
+ message(SEND_ERROR "required function `${function}` not found")
+ endif()
+endmacro()
+
diff --git a/cmake/modules/PaludisCompileFlags.cmake b/cmake/modules/PaludisCompileFlags.cmake
new file mode 100644
index 000000000..7db849f37
--- /dev/null
+++ b/cmake/modules/PaludisCompileFlags.cmake
@@ -0,0 +1,78 @@
+
+include(CheckCXXCompilerFlag)
+
+function(append_if condition value)
+ if (${condition})
+ foreach(variable ${ARGN})
+ set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
+ endforeach(variable)
+ endif()
+endfunction()
+
+if(NOT $ENV{LET_ME_RICE})
+ set(flags ${CMAKE_C_FLAGS};${CMAKE_CXX_FLAGS};${CMAKE_EXE_LINKER_FLAGS};${CMAKE_SHARED_LINKER_FLAGS})
+ foreach(flag enforce-eh;fast-math;rtti;visibility;znow;std=;align-functions=;prefetch-loop-arrays;Ofast)
+ list(FIND flags ${flag} have_flag)
+ if(have_flag)
+ message(SEND_ERROR "unsupported flag `${flag}` found")
+ endif()
+ endforeach()
+endif()
+
+check_cxx_compiler_flag("-Werror -Wall" CXX_SUPPORTS_WALL)
+append_if(CXX_SUPPORTS_WALL "-Wall" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wextra" CXX_SUPPORTS_WEXTRA)
+append_if(CXX_SUPPORTS_WEXTRA "-Wextra" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wold-style-cast" CXX_SUPPORTS_WOLD_STYLE_CAST)
+append_if(CXX_SUPPORTS_WOLD_STYLE_CAST "-Wold-style-cast" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wredundant-decls" CXX_SUPPORTS_WREDUNDANT_DECLS)
+append_if(CXX_SUPPORTS_WREDUNDANT_DECLS "-Wredundant-decls" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wstrict-null-sentinel" CXX_SUPPORTS_WSTRICT_NULL_SENTINEL)
+append_if(CXX_SUPPORTS_WSTRICT_NULL_SENTINEL "-Wstrict-null-sentinel" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wmissing-noreturn" CXX_SUPPORTS_WMISSING_NORETURN)
+append_if(CXX_SUPPORTS_WMISSING_NORETURN "-Wmissing-noreturn" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Woverloaded-virtual" CXX_SUPPORTS_WOVERLOADED_VIRTUAL)
+append_if(CXX_SUPPORTS_WOVERLOADED_VIRTUAL "-Woverloaded-virtual" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Winit-self" CXX_SUPPORTS_WINIT_SELF)
+append_if(CXX_SUPPORTS_WINIT_SELF "-Winit-self" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wunreachable-code" CXX_SUPPORTS_WUNREACHABLE_CODE)
+append_if(CXX_SUPPORTS_WUNREACHABLE_CODE "-Wunreachable-code" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wunused" CXX_SUPPORTS_WUNUSED)
+append_if(CXX_SUPPORTS_WUNUSED "-Wunused" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wshadow" CXX_SUPPORTS_WSHADOW)
+append_if(CXX_SUPPORTS_WSHADOW "-Wshadow" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wwrite-strings" CXX_SUPPORTS_WWRITE_STRINGS)
+append_if(CXX_SUPPORTS_WWRITE_STRINGS "-Wwrite-strings" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wsignature-shadow" CXX_SUPPORTS_WSIGNATURE_SHADOW)
+append_if(CXX_SUPPORTS_WSIGNATURE_SHADOW "-Wsignature-shadow" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wfloat-equal" CXX_SUPPORTS_WFLOAT_EQUAL)
+append_if(CXX_SUPPORTS_WFLOAT_EQUAL "-Wfloat-equal" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wno-ignored-qualifiers" CXX_SUPPORTS_WNO_IGNORED_QUALIFIERS)
+append_if(CXX_SUPPORTS_WNO_IGNORED_QUALIFIERS "-Wno-ignored-qualifiers" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -Wno-non-virtrual-dtor" CXX_SUPPORTS_WNO_NON_VIRTUAL_DTOR)
+append_if(CXX_SUPPORTS_WNO_NON_VIRTUAL_DTOR "-Wno-non-virtual-dtor" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -fvisibility=hidden" CXX_SUPPORTS_FVISIBILITY_HIDDEN)
+append_if(CXX_SUPPORTS_FVISIBILITY_HIDDEN "-fvisibility=hidden" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -fvisibility-inlines-hidden" CXX_SUPPORTS_FVISIBILITY_INLINES_HIDDEN)
+append_if(CXX_SUPPORTS_FVISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS)
+
+check_cxx_compiler_flag("-Werror -fno-strict-aliasing" CXX_SUPPORTS_FNO_STRICT_ALIASING)
+check_cxx_compiler_flag("-Werror -g0" CXX_SUPPORTS_G0)
+
diff --git a/cmake/modules/PaludisGeneratorUtils.cmake b/cmake/modules/PaludisGeneratorUtils.cmake
new file mode 100644
index 000000000..f9edcef4e
--- /dev/null
+++ b/cmake/modules/PaludisGeneratorUtils.cmake
@@ -0,0 +1,140 @@
+
+include(CMakeParseArguments)
+
+find_program(M4_EXECUTABLE NAMES m4 gm4 DOC "m4 macro processor")
+if(NOT M4_EXECUTABLE)
+ message(FATAL_ERROR "m4 not found")
+endif()
+
+function(paludis_m4process input_file target)
+ set(options)
+ set(single_value_args OUTPUT)
+ set(multiple_value_args)
+
+ cmake_parse_arguments(PM4P "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
+
+ get_filename_component(input_file_basename "${input_file}" NAME)
+ if(PM4P_OUTPUT)
+ set(output_file "${PM4P_OUTPUT}")
+ else()
+ set(output_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename}")
+ string(REGEX REPLACE "\\.[^.]*$" "" output_file "${output_file}")
+ endif()
+
+ string(MD5 md5 "paludis-m4process-${output_file}")
+ set(target_name paludis-m4process-${md5}-${input_file_basename})
+
+ add_custom_command(OUTPUT
+ ${output_file}
+ COMMAND
+ ${M4_EXECUTABLE} -I ${PROJECT_SOURCE_DIR} -E ${input_file} > ${output_file}
+ DEPENDS
+ ${input_file})
+ add_custom_target(${target_name} DEPENDS ${output_file} COMMENT ${output_file})
+
+ set(${target} ${target_name} PARENT_SCOPE)
+endfunction()
+
+# TODO(compnerd) convert misc/make_se.bash into a cmake script
+function(paludis_seprocess input_file)
+ set(single_value_args HEADER_TARGET SOURCE_TARGET)
+ set(multiple_value_args)
+
+ cmake_parse_arguments(PSEP "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
+
+ if(NOT PSEP_HEADER_TARGET)
+ message(SEND_ERROR "paludis_seprocess(${input_file}) invoked without HEADER_TARGET option")
+ endif()
+ if(NOT PSEP_SOURCE_TARGET)
+ message(SEND_ERROR "paludis_seprocess(${input_file}) invoked without SOURCE_TARGET option")
+ endif()
+
+ get_filename_component(input_file_basename "${input_file}" NAME)
+ get_filename_component(input_file_basename_we "${input_file}" NAME_WE)
+
+ set(output_header_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-se.hh")
+ string(MD5 md5 "paludis-seprocess-${output_header_file}")
+ set(header_target_name paludis-seprocess-${md5}-${input_file_basename_we}-se.hh)
+ set(${PSEP_HEADER_TARGET} ${header_target_name} PARENT_SCOPE)
+
+ add_custom_command(OUTPUT
+ ${output_header_file}
+ COMMAND
+ "${PROJECT_SOURCE_DIR}/misc/make_se.bash" --header ${input_file} > ${output_header_file}
+ DEPENDS
+ "${PROJECT_SOURCE_DIR}/misc/make_se.bash"
+ ${input_file})
+ add_custom_target(${header_target_name} DEPENDS ${output_header_file} COMMENT ${output_header_file})
+
+
+ set(output_source_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-se.cc")
+ string(MD5 md5 "paludis-seprocess-${output_source_file}")
+ set(source_target_name paludis-seprocess-${md5}-${input_file_basename_we}-se.cc)
+ set(${PSEP_SOURCE_TARGET} ${source_target_name} PARENT_SCOPE)
+
+ add_custom_command(OUTPUT
+ ${output_source_file}
+ COMMAND
+ "${PROJECT_SOURCE_DIR}/misc/make_se.bash" --source ${input_file} > ${output_source_file}
+ DEPENDS
+ "${PROJECT_SOURCE_DIR}/misc/make_se.bash"
+ ${input_file})
+ add_custom_target(${source_target_name} DEPENDS ${output_source_file} COMMENT ${output_source_file})
+endfunction()
+
+# TODO(compnerd) convert make_nn.bash into a cmake script
+function(paludis_nnprocess input_file)
+ set(options)
+ set(single_value_args HEADER_TARGET HEADER_FILE SOURCE_TARGET SOURCE_FILE)
+ set(multiple_value_args)
+
+ cmake_parse_arguments(PNNP "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
+
+ if(NOT PNNP_HEADER_TARGET)
+ message(SEND_ERROR "paludis_nnprocess(${input_file}) invoked without HEADER_TARGET option")
+ endif()
+ if(NOT PNNP_SOURCE_TARGET)
+ message(SEND_ERROR "paludis_nnprocess(${input_file}) invoked without SOURCE_TARGET option")
+ endif()
+
+ get_filename_component(input_file_basename "${input_file}" NAME)
+ get_filename_component(input_file_basename_we "${input_file}" NAME_WE)
+
+ set(output_header_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-nn.hh")
+ string(MD5 md5 "paludis-nnprocess-${output_header_file}")
+ set(header_target_name paludis-nnprocess-${md5}-${input_file_basename_we}-nn.hh)
+
+ add_custom_command(OUTPUT
+ ${output_header_file}
+ COMMAND
+ "${PROJECT_SOURCE_DIR}/misc/make_nn.bash" --header ${input_file} > ${output_header_file}
+ DEPENDS
+ "${PROJECT_SOURCE_DIR}/misc/make_nn.bash"
+ ${input_file})
+ add_custom_target(${header_target_name} DEPENDS ${output_header_file} COMMENT ${output_header_file})
+
+
+ set(output_source_file "${CMAKE_CURRENT_BINARY_DIR}/${input_file_basename_we}-nn.cc")
+ string(MD5 md5 "paludis-nnprocess-${output_source_file}")
+ set(source_target_name paludis-nnprocess-${md5}-${input_file_basename_we}-nn.cc)
+
+ add_custom_command(OUTPUT
+ ${output_source_file}
+ COMMAND
+ "${PROJECT_SOURCE_DIR}/misc/make_nn.bash" --source ${input_file} > ${output_source_file}
+ DEPENDS
+ "${PROJECT_SOURCE_DIR}/misc/make_nn.bash"
+ ${input_file})
+ add_custom_target(${source_target_name} DEPENDS ${output_source_file} COMMENT ${output_source_file})
+
+ set(${PNNP_HEADER_TARGET} ${header_target_name} PARENT_SCOPE)
+ if(PNNP_HEADER_FILE)
+ set(${PNNP_HEADER_FILE} ${output_header_file} PARENT_SCOPE)
+ endif()
+
+ set(${PNNP_SOURCE_TARGET} ${source_target_name} PARENT_SCOPE)
+ if(PNNP_SOURCE_FILE)
+ set(${PNNP_SOURCE_FILE} ${output_source_file} PARENT_SCOPE)
+ endif()
+endfunction()
+
diff --git a/cmake/modules/PaludisList.cmake b/cmake/modules/PaludisList.cmake
new file mode 100644
index 000000000..567ebebb2
--- /dev/null
+++ b/cmake/modules/PaludisList.cmake
@@ -0,0 +1,24 @@
+
+function(list_replace input_list old new)
+ set(replaced_list)
+ foreach(item ${${input_list}})
+ if(${item} STREQUAL ${old})
+ list(APPEND replaced_list ${new})
+ else()
+ list(APPEND replaced_list ${item})
+ endif()
+ endforeach()
+ set("${input_list}" "${replaced_list}" PARENT_SCOPE)
+endfunction()
+
+function(list_union lhs rhs result_var_name)
+ set(result)
+ foreach(item IN LISTS lhs rhs)
+ list(FIND result "${item}" index)
+ if(${index} EQUAL -1)
+ list(APPEND result "${item}")
+ endif()
+ endforeach()
+ set("${result_var_name}" "${result}" PARENT_SCOPE)
+endfunction()
+
diff --git a/cmake/modules/PaludisPackage.cmake b/cmake/modules/PaludisPackage.cmake
new file mode 100644
index 000000000..ecbd54e92
--- /dev/null
+++ b/cmake/modules/PaludisPackage.cmake
@@ -0,0 +1,34 @@
+
+set(CPACK_SET_DESTDIR TRUE)
+set(CPACK_SOURCE_GENERATOR "TBZ2")
+set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
+set(CPACK_PACKAGE_VERISON_MAJOR ${PROJECT_VERSION_MAJOR})
+set(CPACK_PACKAGE_VERISON_MINOR ${PROJECT_VERSION_MINOR})
+set(CPACK_PACKAGE_VERISON_PATCH ${PROJECT_VERSION_PATCH})
+set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}")
+set(CPACK_SOURCE_IGNORE_FILES
+ "/build/"
+ "/.git/"
+ "\\\\.sw[opn]$"
+ ".*~"
+ "cscope.*"
+ # TODO(compnerd) remove this set when the autotools build system is removed
+ "/.gitignore"
+ "/.gitreview"
+ "/aclocal.m4"
+ "/autogen.bash"
+ "/autom4te.cache/"
+ "/autotools_prepare.bash"
+ "/config.h.in"
+ "/configure.ac"
+ "Makefile.am"
+ "Makefile.am.m4"
+ "Makefile.in"
+ "/misc/common-makefile.am"
+ "files.m4"
+ "${CPACK_SOURCE_IGNORE_FILES}")
+
+include(CPack)
+
+add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
+