Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package recipes using modern CMake (required 3.8) #743

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/_*.json
**/_*.txt
*.pyc
*.swp
\#*\#
tests/bindings/python/ice40_test.json
GPATH
Expand Down
185 changes: 159 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,173 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.8)

project(coreir)
option(STATIC "Statically link everything" OFF)


if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# require at least gcc 4.8
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9!")
endif()
if(${CMAKE_VERSION} VERSION_LESS 3.13)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
message(WARNING "You are using an untested compiler")
cmake_policy(VERSION 3.13)
endif()

if (STATIC)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(STATIC_FLAGS "-static-libgcc -static-libstdc++")
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()

# ---------------------------------------------------------------------------- #
# PROJECT
# name version language
# ---------------------------------------------------------------------------- #
project(coreir VERSION 0.0.30
LANGUAGES CXX
)


# ---------------------------------------------------------------------------- #
# OPTION
# build configuration
# ---------------------------------------------------------------------------- #
option(BUILD_SHARED_LIBS "To build shared librareis" ON)


# ---------------------------------------------------------------------------- #
# VARARIABLE
# alias and configurations
# ---------------------------------------------------------------------------- #
set(COREIR_TARGET_NAME ${PROJECT_NAME})
set(COREIR_CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
set(COREIR_INCLUDE_INSTALL_DIR "include")
set(COREIR_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include")
set(COREIR_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(COREIR_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(COREIR_CMAKE_CONFIG_TEMPLATE "tools/cmake/config.cmake.in")
set(COREIR_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(COREIR_CMAKE_PROJECT_TARGETS_FILE "${PROJECT_NAME}Targets.cmake")

set(COREIR_CMAKE_VERSION_CONFIG_FILE
"${COREIR_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")

set(COREIR_CMAKE_PROJECT_CONFIG_FILE
"${COREIR_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")


# ---------------------------------------------------------------------------- #
# External dependencies
# ---------------------------------------------------------------------------- #
##
## Make sure that custom modules can be found.
##
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/tools/cmake" ${CMAKE_MODULE_PATH})


# ---------------------------------------------------------------------------- #
# Misc
# ---------------------------------------------------------------------------- #
##
## Compiler options
##
if(${CMAKE_COMPILER_IS_GNUCXX})

# require at least gcc 4.8
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9!")
endif()

else()

message(WARNING "You are using an untested compiler")

endif()

set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -fPIC -Werror ${STATIC_FLAGS}")
macro(coreir_set_compile_option IARG_TARGET_NAME)

if(${CMAKE_COMPILER_IS_GUNCXX})
target_compile_options(${IARG_TARGET_NAME} PRIVATE "-Wall")
target_compile_options(${IARG_TARGET_NAME} PRIVATE "-Werror")
endif()

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(INCLUDE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include)
set_property(
TARGET ${IARG_TARGET_NAME}
PROPERTY POSITION_INDEPENDENT_CODE ON
)

add_subdirectory(${CMAKE_SOURCE_DIR}/src)
endmacro()


##
## RPATH for shared target
##
set(CMAKE_INSTALL_RPATH ${COREIR_INSTALL_RPATH})
set(CMAKE_MACOSX_RPATH TRUE)


# ---------------------------------------------------------------------------- #
# TARGET
# library target
# ---------------------------------------------------------------------------- #
set(COREIR_LIB_NAME ${COREIR_TARGET_NAME})
set(COREIR_EXE_NAME ${COREIR_TARGET_NAME}-bin)
set(COREIR_ITP_NAME ${COREIR_TARGET_NAME}-interpreter)
set(COREIR_SIM_NAME ${COREIR_TARGET_NAME}-simulator)
add_subdirectory(src)


# ---------------------------------------------------------------------------- #
# INSTALL
# project related
# ---------------------------------------------------------------------------- #
##
## forward version for find_package
##
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${COREIR_CMAKE_VERSION_CONFIG_FILE}
COMPATIBILITY SameMajorVersion # AnyNewVersion
)

##
## cmake config
##
configure_file(
${COREIR_CMAKE_CONFIG_TEMPLATE}
${COREIR_CMAKE_PROJECT_CONFIG_FILE}
@ONLY
)

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h"
FILES ${COREIR_CMAKE_PROJECT_CONFIG_FILE} ${COREIR_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${COREIR_CONFIG_INSTALL_DIR}
)

add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/tools/cmake/uninstall.cmake"
##
## project export
##
install(
EXPORT ${COREIR_TARGETS_EXPORT_NAME}
DESTINATION ${COREIR_CONFIG_INSTALL_DIR}
NAMESPACE ${PROJECT_NAME}::
FILE ${COREIR_CMAKE_PROJECT_TARGETS_FILE}
)

export(
TARGETS ${COREIR_LIB_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${COREIR_CMAKE_PROJECT_TARGETS_FILE}
)

if(${COREIR_EXPORT_PACKAGE})
export(PACKAGE ${PROJECT_NAME})
endif()


# ---------------------------------------------------------------------------- #
# UNINSTALL
# uninstall files listed in install_manifest.txt
# ---------------------------------------------------------------------------- #
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/tools/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)

add_custom_target(uninstall
COMMAND
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/tools/cmake/cmake_uninstall.cmake
)

endif()

20 changes: 19 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,26 @@ Option 2:
Add `export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:<path_to_coreir_release>/lib` to your `~/.bashrc` or `~/.profile`
If this does not work, you may have System Integrity Protection enabled on your Mac.

### If you are using linux:
#### If you are using linux:
Add `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path_to_coreir_release>/lib` to your `~/.bashrc` or `~/.profile`

#### If you are using CMake:
Add the below lines in your `CMakeLists.txt`. (No `PATH` variable needs to be set.)

``` cmake
# CMakeLists.txt

find_package(coreir REQUIRED)

target_link_libraries(MyTarget coreir::coreir)
```

For non-standard install path (`/usr` or `/usr/local`), set `CMAKE_PREFIX_PATH` to the customed install path.

``` bash
# bash
cmake .. -DCMAKE_PREFIX_PATH=<coreir/install/path>
```


# How to Install from source (OSX or Linux)
Expand Down
Loading