diff --git a/.gitignore b/.gitignore index 6e8f906d9..f085469e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ **/_*.json **/_*.txt *.pyc +*.swp \#*\# tests/bindings/python/ice40_test.json GPATH diff --git a/CMakeLists.txt b/CMakeLists.txt index 63bed1a8c..2c7879a91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() + diff --git a/INSTALL.md b/INSTALL.md index dec126962..93dd31ab2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -14,8 +14,26 @@ Option 2: Add `export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/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:/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= +``` # How to Install from source (OSX or Linux) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7fd967342..b10f65dd0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,95 +1,207 @@ message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}) + +# ---------------------------------------------------------------------------- # +# TARGET +# archive library +# ---------------------------------------------------------------------------- # +## +## source files +## file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ir/[^_]*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/passes/analysis/[^_]*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/passes/transform/[^_]*.cpp ) -#Create libcoreir -set(CMAKE_MACOSX_RPATH 1) -set(CMAKE_INSTALL_RPATH "${LIBRARY_OUTPUT_PATH}") +## +## create lib +## +add_library(${COREIR_LIB_NAME} ${SRC_FILES}) +add_library(${PROJECT_NAME}::${COREIR_LIB_NAME} ALIAS ${COREIR_LIB_NAME}) + +## +## compile features/options +## +target_compile_features(${COREIR_LIB_NAME} PUBLIC cxx_std_11) +coreir_set_compile_option(${COREIR_LIB_NAME}) + +## +## include paths +## +target_include_directories(${COREIR_LIB_NAME} + PUBLIC + $ + $ +) + -if (STATIC) - add_library(coreir STATIC ${SRC_FILES}) -else() - add_library(coreir SHARED ${SRC_FILES}) -endif() +# ---------------------------------------------------------------------------- # +# LINK LIBRARIES +# external dependencies +# ---------------------------------------------------------------------------- # +target_link_libraries(${COREIR_LIB_NAME} PUBLIC ${CMAKE_DL_LIBS}) -target_include_directories(coreir PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include) -target_link_libraries(coreir dl) -#Install libcoreir +# ---------------------------------------------------------------------------- # +# INSTALL +# install and export lib target +# ---------------------------------------------------------------------------- # install( - TARGETS coreir - DESTINATION lib + TARGETS ${COREIR_LIB_NAME} + EXPORT ${COREIR_TARGETS_EXPORT_NAME} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION ${COREIR_INCLUDE_INSTALL_DIR} ) +## +## copy to source dir for tests (legacy) +## add_custom_command( - TARGET coreir + TARGET ${COREIR_LIB_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/lib/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/lib" COMMENT "Copying to lib/" ) -#Create coreir executable -add_executable(coreir-bin ${CMAKE_CURRENT_SOURCE_DIR}/binary/coreir.cpp) -target_link_libraries(coreir-bin PUBLIC coreir) -target_include_directories(coreir-bin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include) -set_target_properties(coreir-bin - PROPERTIES OUTPUT_NAME coreir +## +## include directory +## +install( + DIRECTORY ${COREIR_INCLUDE_BUILD_DIR} + #DESTINATION ${COREIR_INCLUDE_INSTALL_DIR} + DESTINATION "." # XXX wrap the header in "coreir" to make this cleaner + FILES_MATCHING PATTERN "*.h" ) -add_custom_command( - TARGET coreir-bin - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/bin/" - COMMENT "Copying to bin/" + + +# ---------------------------------------------------------------------------- # +# TARGET +# coreir executable +# ---------------------------------------------------------------------------- # +add_executable( + ${COREIR_EXE_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/binary/coreir.cpp ) +target_link_libraries(${COREIR_EXE_NAME} PUBLIC ${COREIR_LIB_NAME}) +set_target_properties(${COREIR_EXE_NAME} PROPERTIES RUNTIME_OUTPUT_NAME coreir) +coreir_set_compile_option(${COREIR_EXE_NAME}) + +# ---------------------------------------------------------------------------- # +# INSTALL +# install coreir executable +# ---------------------------------------------------------------------------- # install( - TARGETS coreir-bin - DESTINATION bin + TARGETS ${COREIR_EXE_NAME} + RUNTIME DESTINATION bin ) +## +## copy to source dir for tests (legacy) +## +add_custom_command( + TARGET ${COREIR_EXE_NAME} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/bin" + COMMENT "Copying to bin/" +) + + #Create the coreir libraries -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs) +set(COREIR_SUBLIB_PREFIX ${COREIR_LIB_NAME}) +add_subdirectory(libs) #create simulator library -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/simulator) +set(COREIR_SIMLIB coreirsim) +add_subdirectory(simulator) #create coreir-c libraries -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/coreir-c) - +set(COREIR_LIB_C "${COREIR_LIB_NAME}-c") +set(COREIR_SIMLIB_C "${COREIR_SIMLIB}-c") +add_subdirectory(coreir-c) + + +# ---------------------------------------------------------------------------- # +# TARGET +# interpreter executable +# ---------------------------------------------------------------------------- # +add_executable( + ${COREIR_ITP_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/binary/interpreter.cpp +) +target_link_libraries(${COREIR_ITP_NAME} PUBLIC ${COREIR_LIB_NAME}) +target_link_libraries(${COREIR_ITP_NAME} PUBLIC ${COREIR_SIMLIB}) +target_link_libraries(${COREIR_ITP_NAME} PUBLIC "${COREIR_SUBLIB_PREFIX}-commonlib") -#create interpreter executable -add_executable(coreir-interpreter ${CMAKE_CURRENT_SOURCE_DIR}/binary/interpreter.cpp) -target_link_libraries(coreir-interpreter PUBLIC coreir) -target_link_libraries(coreir-interpreter PUBLIC coreirsim) -target_link_libraries(coreir-interpreter PUBLIC coreir-commonlib) -target_include_directories(coreir-interpreter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include) +coreir_set_compile_option(${COREIR_ITP_NAME}) -#create simulator executable -add_executable(coreir-simulator ${CMAKE_CURRENT_SOURCE_DIR}/binary/simulator.cpp) -target_link_libraries(coreir-simulator PUBLIC coreir) -target_link_libraries(coreir-simulator PUBLIC coreirsim) -target_link_libraries(coreir-simulator PUBLIC coreir-commonlib) -target_include_directories(coreir-simulator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include) +# ---------------------------------------------------------------------------- # +# INSTALL +# install interpreter executable +# ---------------------------------------------------------------------------- # install( - TARGETS coreir-interpreter coreir-simulator - DESTINATION bin + TARGETS ${COREIR_ITP_NAME} + RUNTIME DESTINATION bin ) +## +## copy to source dir for tests (legacy) +## add_custom_command( - TARGET coreir-interpreter + TARGET ${COREIR_ITP_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/bin/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/bin" COMMENT "Copying to bin/" ) + +# ---------------------------------------------------------------------------- # +# TARGET +# simulator executable +# ---------------------------------------------------------------------------- # +add_executable( + ${COREIR_SIM_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/binary/simulator.cpp +) +target_link_libraries(${COREIR_SIM_NAME} PUBLIC ${COREIR_LIB_NAME}) +target_link_libraries(${COREIR_SIM_NAME} PUBLIC ${COREIR_SIMLIB}) +target_link_libraries(${COREIR_SIM_NAME} PUBLIC "${COREIR_SUBLIB_PREFIX}-commonlib") + +coreir_set_compile_option(${COREIR_SIM_NAME}) + + +# ---------------------------------------------------------------------------- # +# INSTALL +# install simulator executable +# ---------------------------------------------------------------------------- # +install( + TARGETS ${COREIR_SIM_NAME} + RUNTIME DESTINATION bin +) + +## +## copy to source dir for tests (legacy) +## add_custom_command( - TARGET coreir-simulator + TARGET ${COREIR_SIM_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/bin/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/bin" COMMENT "Copying to bin/" ) + diff --git a/src/coreir-c/CMakeLists.txt b/src/coreir-c/CMakeLists.txt index 3c9947b02..e6a0d41f5 100644 --- a/src/coreir-c/CMakeLists.txt +++ b/src/coreir-c/CMakeLists.txt @@ -1,42 +1,58 @@ -set(CMAKE_MACOSX_RPATH 1) -set(CMAKE_INSTALL_RPATH "${LIBRARY_OUTPUT_PATH}") - - -#Create libcoreir-c -project(coreir-c) +## +## libcoreir-c +## +project(${COREIR_LIB_C} LANGUAGES CXX) set(CSRC coreir-c.cpp types-c.cpp values-c.cpp) -add_library(coreir-c SHARED ${CSRC}) -target_include_directories(coreir-c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) -target_link_libraries(coreir-c PUBLIC coreir) +add_library(${COREIR_LIB_C} ${CSRC}) -#Create libcoreirsim-c -project(coreirsim-c) -set(CSIMSRC simulator-c.cpp) +target_link_libraries(${COREIR_LIB_C} PUBLIC ${COREIR_LIB_NAME}) -add_library(coreirsim-c SHARED ${CSIMSRC}) -target_include_directories(coreirsim-c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) -target_link_libraries(coreirsim-c PUBLIC coreir) -target_link_libraries(coreirsim-c PUBLIC coreirsim) +coreir_set_compile_option(${COREIR_LIB_C}) -#Install libcoreir install( - TARGETS coreir-c coreirsim-c - DESTINATION lib + TARGETS ${COREIR_LIB_C} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib ) + add_custom_command( - TARGET coreir-c + TARGET ${COREIR_LIB_C} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/lib/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/lib" COMMENT "Copying to lib/" ) +## +## libcoreirsim-c +## +project(${COREIR_SIMLIB_C} LANGUAGES CXX) +set(CSIMSRC simulator-c.cpp) + +add_library(${COREIR_SIMLIB_C} ${CSIMSRC}) + +target_link_libraries(${COREIR_SIMLIB_C} PUBLIC ${COREIR_LIB_NAME}) +target_link_libraries(${COREIR_SIMLIB_C} PUBLIC ${COREIR_SIMLIB}) + +coreir_set_compile_option(${COREIR_SIMLIB_C}) + +install( + TARGETS ${COREIR_SIMLIB_C} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + + add_custom_command( - TARGET coreirsim-c + TARGET ${COREIR_SIMLIB_C} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/lib/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/lib" COMMENT "Copying to lib/" ) - - diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt index 02988a565..df0941b7c 100644 --- a/src/libs/CMakeLists.txt +++ b/src/libs/CMakeLists.txt @@ -1,39 +1,43 @@ +## +## Macro for creating sub-units +## +macro(add_coreir_sub_lib CLIB) + set(COREIR_SUB_LIB "${COREIR_SUBLIB_PREFIX}-${CLIB}") + project(${COREIR_SUB_LIB} LANGUAGES CXX) + set(SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${CLIB}.cpp") -#Common things for creating the libraries -#find_library(COREIR_LIB coreir) -#message(STATUS ${COREIR_LIB}) -set(CMAKE_MACOSX_RPATH 1) -set(CMAKE_INSTALL_RPATH "${LIBRARY_OUTPUT_PATH}") - -set(COREIRLIBS - "commonlib" - "rtlil" - "aetherlinglib" - "ice40" - "float" -) -foreach(CLIB ${COREIRLIBS}) - #message(STATUS ${COREIRLIB}) - set(COREIRLIB "coreir-${CLIB}") - project(${COREIRLIB}) - - set(SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${CLIB}.cpp") - - add_library(${COREIRLIB} SHARED ${SRC_FILES}) - target_include_directories(${COREIRLIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) - target_link_libraries(${COREIRLIB} PUBLIC coreir) - install( - TARGETS ${COREIRLIB} - DESTINATION lib - ) + # create lib + add_library(${COREIR_SUB_LIB} ${SRC_FILES}) + + target_link_libraries(${COREIR_SUB_LIB} PUBLIC ${COREIR_LIB_NAME}) + + # compile features/options + coreir_set_compile_option(${COREIR_SUB_LIB}) + + # install lib + install( + TARGETS ${COREIR_SUB_LIB} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + + # copy to source dir for tests (legacy) add_custom_command( - TARGET ${COREIRLIB} + TARGET ${COREIR_SUB_LIB} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/lib/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/lib" COMMENT "Copying to lib/" ) -endforeach() +endmacro() +add_coreir_sub_lib("commonlib") +add_coreir_sub_lib("rtlil") +add_coreir_sub_lib("aetherlinglib") +add_coreir_sub_lib("ice40") +add_coreir_sub_lib("float") diff --git a/src/simulator/CMakeLists.txt b/src/simulator/CMakeLists.txt index 11fbfa082..7eac677c3 100644 --- a/src/simulator/CMakeLists.txt +++ b/src/simulator/CMakeLists.txt @@ -1,29 +1,31 @@ -project(coreirsim) +## +## libcoreirsim +## +project(${COREIR_SIMLIB} LANGUAGES CXX) file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/[^_]*.cpp ) -#Create libcoreir -set(CMAKE_MACOSX_RPATH 1) -set(CMAKE_INSTALL_RPATH "${LIBRARY_OUTPUT_PATH}") +add_library(${COREIR_SIMLIB} ${SRC_FILES}) -add_library(coreirsim SHARED ${SRC_FILES}) -target_include_directories(coreirsim PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) -target_link_libraries(coreirsim PUBLIC coreir) +target_link_libraries(${COREIR_SIMLIB} PUBLIC ${COREIR_LIB_NAME}) + +coreir_set_compile_option(${COREIR_SIMLIB}) install( - TARGETS coreirsim - DESTINATION lib + TARGETS ${COREIR_SIMLIB} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib ) add_custom_command( - TARGET coreirsim + TARGET ${COREIR_SIMLIB} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy "$" "${CMAKE_SOURCE_DIR}/lib/" + COMMAND + ${CMAKE_COMMAND} -E copy + "$" + "${CMAKE_SOURCE_DIR}/lib" COMMENT "Copying to lib/" ) - - - diff --git a/tools/cmake/ConfigSafeGuards.cmake b/tools/cmake/ConfigSafeGuards.cmake new file mode 100644 index 000000000..dc735f1a6 --- /dev/null +++ b/tools/cmake/ConfigSafeGuards.cmake @@ -0,0 +1,11 @@ + +# guard against in-source builds +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.") +endif() + +# guard against bad build-type strings +if(NOT ${CMAKE_BUILD_TYPE}) + set(CMAKE_BUILD_TYPE "Debug") +endif() + diff --git a/tools/cmake/cmake_uninstall.cmake.in b/tools/cmake/cmake_uninstall.cmake.in new file mode 100644 index 000000000..a44ad4488 --- /dev/null +++ b/tools/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,23 @@ +# uninstall targets +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) + diff --git a/tools/cmake/config.cmake.in b/tools/cmake/config.cmake.in new file mode 100644 index 000000000..fb415952c --- /dev/null +++ b/tools/cmake/config.cmake.in @@ -0,0 +1,31 @@ +# ---------------------------------------------------------------------------- # +# define dependencies +# ---------------------------------------------------------------------------- # +include(CMakeFindDependencyMacro) + +# ---------------------------------------------------------------------------- # +# define exports +# ---------------------------------------------------------------------------- # +include(FindPackageHandleStandardArgs) + +set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE}) + +find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE) + +if(NOT TARGET @PROJECT_NAME@::@COREIR_TARGET_NAME@) + include("${CMAKE_CURRENT_LIST_DIR}/@COREIR_TARGETS_EXPORT_NAME@.cmake") + + if((NOT TARGET @COREIR_TARGET_NAME@) AND + (NOT @PROJECT_NAME@_FIND_VERSION OR + @PROJECT_NAME@_FIND_VERSION VERSION_LESS 1.0.0)) + + add_library(@COREIR_TARGET_NAME@ INTERFACE IMPORTED) + + set_target_properties(@COREIR_TARGET_NAME@ PROPERTIES + INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@COREIR_TARGET_NAME@ + ) + + endif() + +endif() + diff --git a/tools/cmake/uninstall.cmake b/tools/cmake/uninstall.cmake deleted file mode 100644 index fe36912c0..000000000 --- a/tools/cmake/uninstall.cmake +++ /dev/null @@ -1,27 +0,0 @@ -set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") - -if(NOT EXISTS ${MANIFEST}) - message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'") -endif() - -file(STRINGS ${MANIFEST} files) -foreach(file ${files}) - if(EXISTS ${file}) - message(STATUS "Removing file: '${file}'") - - exec_program( - ${CMAKE_COMMAND} ARGS "-E remove ${file}" - OUTPUT_VARIABLE stdout - RETURN_VALUE result - ) - - if(NOT "${result}" STREQUAL 0) - message(FATAL_ERROR "Failed to remove file: '${file}'.") - endif() - else() - MESSAGE(STATUS "File '${file}' does not exist.") - endif() -endforeach(file) - - -