CMakeLists.txt 3.72 KB
Newer Older
Johan Pascal's avatar
Johan Pascal committed
1 2 3 4 5 6 7 8
############################################################################
# CMakeLists.txt
#
#    Released under the MIT License.  See LICENSE.txt for license information.
#
############################################################################

cmake_minimum_required(VERSION 3.0)
Michael Hamburg's avatar
Michael Hamburg committed
9
project(DECAF VERSION 1.0 LANGUAGES C CXX)
Johan Pascal's avatar
Johan Pascal committed
10 11 12

set(DECAF_SO_VERSION "0")

13 14
find_package( PythonInterp 2.7 REQUIRED )

Johan Pascal's avatar
Johan Pascal committed
15 16 17
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
18
option(ENABLE_TESTS  "Enable compilation of tests." OFF)
19 20 21 22 23 24 25
option(GENERATED_SOURCE_PATH "Where the generated source code is stored, default in the building tree" OFF)

if (GENERATED_SOURCE_PATH)
	set(GSOURCE_PATH ${GENERATED_SOURCE_PATH})
else()
	set(GSOURCE_PATH ${PROJECT_BINARY_DIR}/src/GENERATED)
endif()
26
message("Generated source code will be in ${GSOURCE_PATH}")
Johan Pascal's avatar
Johan Pascal committed
27 28 29 30 31 32 33 34 35 36

if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()

include(GNUInstallDirs)
include(CheckSymbolExists)
include(CMakePushCheckState)

37 38 39 40 41 42 43
include_directories(
	${GSOURCE_PATH}/include/
	src/include/
	src/
	${CMAKE_CURRENT_BINARY_DIR}
)

Johan Pascal's avatar
Johan Pascal committed
44 45 46 47 48 49 50 51
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_CXX )
if(MSVC)
	if(ENABLE_STRICT)
		set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} /WX")
	endif()
else()
52 53 54
	set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -std=c++11 -O2")
	set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wall -Wuninitialized -Wno-deprecated-declarations -Wno-missing-field-initializers ")
	set(STRICT_OPTIONS_C "${STRICT_OPTIONS_C} -std=c99 -O2 -Wstrict-prototypes -Wno-error=strict-prototypes -fvisibility=hidden ")
Johan Pascal's avatar
Johan Pascal committed
55 56 57 58 59 60 61 62 63 64 65 66
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
		set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Qunused-arguments -Wno-array-bounds ")
	endif()
	if(APPLE)
		set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare -Wno-unused-function -Wno-array-bounds ")
		set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -stdlib=libc++ ")
	endif()
	if(ENABLE_STRICT)
		set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing ")
	endif()
endif()

67 68
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C} ${STRICT_OPTIONS_CPP}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX} ${STRICT_OPTIONS_CPP}")
Johan Pascal's avatar
Johan Pascal committed
69 70 71 72

add_subdirectory(src)

if(ENABLE_TESTS)
73
	enable_testing()
Johan Pascal's avatar
Johan Pascal committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	add_subdirectory(test)
endif()

include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
)
configure_file(cmake/DecafConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
	@ONLY
)
set(ConfigPackageLocation share/decaf/cmake)
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE DecafTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
	DESTINATION ${ConfigPackageLocation}
)

Johan Pascal's avatar
Johan Pascal committed
95 96 97 98 99 100 101 102 103 104 105 106
# Doxygen
find_package(Doxygen)
if (DOXYGEN_FOUND)
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
	add_custom_target(doc
		${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		DEPENDS generatedCode
		COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif()

Johan Pascal's avatar
Johan Pascal committed
107 108 109 110 111 112 113 114 115 116 117
# CPack settings
set(CPACK_PACKAGE_NAME "decaf")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES
        "^${CMAKE_BINARY_DIR}"
        "/\\\\..+"
)

include(CPack)