Skip to content

Commit

Permalink
give up using CMAKE_CXX_FLAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
KowerKoint committed Jan 4, 2024
1 parent 6b51809 commit 62ac0ad
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 48 deletions.
59 changes: 26 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,6 @@ endif(NOT DEFINED QULACS_USE_EXE)
message(STATUS "QULACS_USE_PYTHON = ${QULACS_USE_PYTHON}")
message(STATUS "QULACS_USE_TEST = ${QULACS_USE_TEST}")

### Compile Warnings ###
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \
-Werror=missing-declarations -Werror=return-type -Wextra \
-Wfloat-equal -Wimplicit-fallthrough=5 -Wlogical-op \
-Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \
-Wshadow -Wstrict-aliasing=2 -Wsuggest-attribute=noreturn -Wwrite-strings \
-fdiagnostics-color=auto -fstrict-aliasing")
# -Werror=undef is eliminated due to conflict with boost
elseif ((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang"))
set(WARNING_CPP "-Wall -Wdate-time -Wendif-labels -Werror=format=2 \
-Werror=missing-declarations -Werror=return-type -Wextra \
-Wfloat-equal -Wimplicit-fallthrough \
-Wmissing-include-dirs -Wpointer-arith -Wredundant-decls \
-Wshadow -Wstrict-aliasing=2 -Wwrite-strings \
-fdiagnostics-color=auto -fstrict-aliasing")
endif()

### Compiler options ###
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang"))
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Enable pthread
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

# Enable openmp
if(QULACS_USE_OMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
add_compile_definitions(OPENMP)
endif()
endif()

### Kokkos options ###
set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "Enable Kokkos Serial backend")
if(QULACS_USE_OMP)
Expand Down Expand Up @@ -133,6 +100,32 @@ else()
message(STATUS "Skip downloding googletest")
endif(QULACS_USE_TEST)

add_library(qulacs)

### Compiler options ###
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang"))
# Standard
target_compile_features(qulacs PUBLIC cxx_std_20)

# Warning
target_compile_options(qulacs PUBLIC
-Wall -Wextra -Wunused-parameter -Wshadow -pedantic
-Wsign-compare -Wtype-limits -Wuninitialized)

# Enable pthread
target_compile_options(qulacs PUBLIC -pthread)

# Enable openmp
if(QULACS_USE_OMP)
target_compile_options(qulacs PUBLIC -fopenmp)
target_compile_definitions(qulacs PUBLIC OPENMP)
endif()

# Debug options
target_compile_options(qulacs PUBLIC $<$<CONFIG:Debug>:-O0 -g -fsanitize=address,undefined>)
target_link_options(qulacs PUBLIC $<$<CONFIG:Debug>:-fsanitize=address,undefined>)
endif()

### Add subdirectories ###
add_subdirectory(qulacs)
if(QULACS_USE_PYTHON)
Expand Down
2 changes: 1 addition & 1 deletion exe/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace qulacs;

void run() {
auto state = StateVector::Haar_random_state(3);
for (int i = 0; i < state.dim(); i++) {
for (UINT i = 0; i < state.dim(); i++) {
std::cout << state[i] << std::endl;
}
}
Expand Down
6 changes: 0 additions & 6 deletions qulacs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
cmake_minimum_required(VERSION 3.21)

add_library(qulacs)

target_compile_options(qulacs PRIVATE
-Wall -Wextra -Wunused-parameter -Wshadow -pedantic
-Wsign-compare -Wtype-limits -Wuninitialized)

target_sources(qulacs PRIVATE
gate/gate_one_control_one_target.cpp
gate/gate_one_qubit.cpp
Expand Down
8 changes: 4 additions & 4 deletions script/build_gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

set -eux

GCC_COMMAND=${C_COMPILER:-"gcc"}
GXX_COMMAND=${CXX_COMPILER:-"g++"}

QULACS_USE_OMP=${QULACS_USE_OMP:-"ON"}
QULACS_USE_CUDA=${QULACS_USE_CUDA:-"OFF"}
QULACS_USE_TEST=${QULACS_USE_TEST:-"ON"}
QULACS_USE_EXE=${QULACS_USE_EXE:-"ON"}

CMAKE_OPS="-D CMAKE_C_COMPILER=$GCC_COMMAND
-D CMAKE_CXX_COMPILER=$GXX_COMMAND \
-D CMAKE_BUILD_TYPE=Release \
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-"Release"}

CMAKE_OPS="-D CMAKE_CXX_COMPILER=${GXX_COMMAND} \
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-D QULACS_USE_OMP=${QULACS_USE_OMP} \
-D QULACS_USE_CUDA=${QULACS_USE_CUDA} \
-D QULACS_USE_TEST=${QULACS_USE_TEST}"
Expand Down
4 changes: 0 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ add_executable(qulacs_test EXCLUDE_FROM_ALL
state/state_vector_test.cpp
)

target_compile_options(qulacs_test PRIVATE
-Wall -Wextra -Wunused-parameter -Wshadow -pedantic
-Wsign-compare -Wtype-limits -Wuninitialized)

target_link_libraries(qulacs_test PRIVATE
qulacs
Kokkos::kokkos
Expand Down

0 comments on commit 62ac0ad

Please sign in to comment.