Commit 91b3ef19 authored by Nicolas Michon's avatar Nicolas Michon

Cmake changes for cross-compilation and better use of imported targets

parent 3641d9c1
############################################################################
# CMakeLists.txt
#
# Released under the MIT License. See LICENSE.txt for license information.
#
############################################################################
cmake_minimum_required(VERSION 3.0)
project(DECAF VERSION 1.0 LANGUAGES C CXX)
set(DECAF_SO_VERSION "0")
find_package( PythonInterp 2.7 REQUIRED )
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TESTS "Enable compilation of tests." OFF)
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()
message("Generated source code will be in ${GSOURCE_PATH}")
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)
include_directories(
${GSOURCE_PATH}/include/
src/include/
src/
${CMAKE_CURRENT_BINARY_DIR}
)
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()
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 ")
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()
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}")
add_subdirectory(src)
if(ENABLE_TESTS)
enable_testing()
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}
)
# 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()
# 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)
############################################################################
# CMakeLists.txt
#
# Released under the MIT License. See LICENSE.txt for license information.
#
############################################################################
cmake_minimum_required(VERSION 3.0)
project(DECAF VERSION 1.0 LANGUAGES C CXX)
set(DECAF_SO_VERSION "0")
find_package( PythonInterp 2.7 REQUIRED )
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TESTS "Enable compilation of tests." OFF)
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()
message("Generated source code in ${GSOURCE_PATH}")
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)
include_directories(
${GSOURCE_PATH}/include/
src/include/
src/
${CMAKE_CURRENT_BINARY_DIR}
)
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()
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")
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")
endif()
if(ENABLE_STRICT)
set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing")
endif()
endif()
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}")
add_subdirectory(src)
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
endif()
include(CMakePackageConfigHelpers)
set(ConfigPackageLocation share/decaf/cmake)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
)
configure_package_config_file(cmake/DecafConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
INSTALL_DESTINATION ${ConfigPackageLocation}
NO_SET_AND_CHECK_MACRO
)
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE DecafTargets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
DESTINATION ${ConfigPackageLocation}
)
# 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()
# 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)
>>>>>>> b819ca6... Cmake config and dependencies rework
......@@ -28,23 +28,25 @@
# DECAF_LIBRARIES - The libraries needed to use decaf
# DECAF_CPPFLAGS - The compilation flags needed to use decaf
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/DecafTargets.cmake")
if(@ENABLE_SHARED@)
set(DECAF_TARGETNAME decaf)
set(DECAF_LIBRARIES ${DECAF_TARGETNAME})
else()
set(DECAF_TARGETNAME decaf-static)
if(TARGET ${DECAF_TARGETNAME})
get_target_property(DECAF_LIBRARIES ${DECAF_TARGETNAME} LOCATION)
get_target_property(DECAF_LINK_LIBRARIES ${DECAF_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(DECAF_LINK_LIBRARIES)
list(APPEND DECAF_LIBRARIES ${DECAF_LINK_LIBRARIES})
endif()
endif()
endif()
get_target_property(DECAF_INCLUDE_DIRS ${DECAF_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
list(INSERT DECAF_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
list(REMOVE_DUPLICATES DECAF_INCLUDE_DIRS)
if(TARGET ${DECAF_TARGETNAME})
get_target_property(DECAF_LIBRARIES ${DECAF_TARGETNAME} LOCATION)
get_target_property(DECAF_LINK_LIBRARIES ${DECAF_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(DECAF_LINK_LIBRARIES)
list(APPEND DECAF_LIBRARIES ${DECAF_LINK_LIBRARIES})
endif()
endif()
set(DECAF_CPPFLAGS @DECAF_CPPFLAGS@)
set(DECAF_FOUND 1)
......@@ -83,14 +83,14 @@ if(ENABLE_STATIC)
add_library(decaf-static STATIC ${DECAF_HEADER_FILES} ${DECAF_SOURCE_FILES_C} ${DECAF_SOURCE_FILES_CXX} $<TARGET_OBJECTS:p25519> $<TARGET_OBJECTS:p448> $<TARGET_OBJECTS:CURVE25519> $<TARGET_OBJECTS:CURVE448>)
add_dependencies(decaf-static generatedCode)
set_target_properties(decaf-static PROPERTIES OUTPUT_NAME decaf)
target_include_directories(decaf-static PUBLIC)
target_include_directories(decaf-static INTERFACE $<INSTALL_INTERFACE:include/decaf>)
target_link_libraries(decaf-static INTERFACE)
endif()
if(ENABLE_SHARED)
add_library(decaf SHARED ${DECAF_HEADER_FILES} ${DECAF_SOURCE_FILES_C} ${DECAF_SOURCE_FILES_CXX} $<TARGET_OBJECTS:p25519> $<TARGET_OBJECTS:p448> $<TARGET_OBJECTS:CURVE25519> $<TARGET_OBJECTS:CURVE448>)
add_dependencies(decaf generatedCode)
set_target_properties(decaf PROPERTIES VERSION ${DECAF_SO_VERSION})
target_include_directories(decaf PUBLIC)
target_include_directories(decaf INTERFACE $<INSTALL_INTERFACE:include/decaf>)
target_link_libraries(decaf PRIVATE)
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment